//===== rAthena Script =======================================
//= The Last Room
//===== Description: =========================================
//= [Walkthrough Conversion]
//= The Last Room Instance
//===== Changelogs: ==========================================
//= 1.0 First version. [Capuche]
//============================================================

un_myst,163,38,5	script	Mark	4_M_BLUEMAN,{
	mes "[Mark]";
	cutin "bu_mark1.bmp",0;

	if (BaseLevel < 150) {
		mes "It's dangerous here.";
		mes "It would be better to come back next time when we are stronger.";
		close3;
	}
	if (getcharid(1) < 1) {
		mes "...It doesn't feel right here.";
		mes "It may be dangerous alone so it might be better to form a party.";
		close3;
	}
	mes "Unlike the other doors we saw this door has traces of it being blocked from this side.";
	next;
	mes "[Mark]";
	mes "Is there something inside?";
	next;
	switch( checkquest(11379,PLAYTIME) ) {
	case -1:
		.@party_id = getcharid(1);
		if (getpartyleader(.@party_id,2) == getcharid(0))
			.@string$ = "Open door.";
		.@s = select( .@string$, "Go in.", "Quit." );
		if (.@s == 1) {
			mes "[Mark]";
			mes "I'm opening the door.";
			mes "Go in when the door is completely open.";
			instance_create("Last room");
		}
		else if (.@s == 2) {
			mes "[Mark]";
			switch( instance_enter("Last room") ) {
			case IE_NOMEMBER:
			case IE_NOINSTANCE:
			case IE_OTHER:
				mes "The door won't open right.";
				break;
			case IE_OK:
				mapannounce "un_myst", strcharinfo(0) + " of the party, " + getpartyname(.@party_id) + ", is entering Last room.",bc_map,"0x00FF99";
				setquest 11379;// Final Room
				if (isbegin_quest(11380) == 0)
					setquest 11380;// Final Room
				break;
			}
		}
		close3;
	case 0:
	case 1:
		mes "[Mark]";
		cutin "bu_mark1.bmp",0;
		mes "...You look tired.";
		mes "Since you went there you should take a day to rest.";
		close3;
	case 2:
		mes "[Mark]";
		cutin "bu_mark1.bmp",0;
		mes "I can't believe you want to enter a place like this again...";
		erasequest 11379;// Final Room
		close3;
	}
}

// 1st step
1@uns,139,41,3	script	Mark#room1	4_M_BLUEMAN,{
	mes "[Mark]";
	mes "Something doesn't feel right. It is better that we move carefully.";
	cutin "bu_mark4.bmp",0;
	close3;
}

1@uns,145,32,5	script	Alp#room1	4_M_BLACKMAN,{
	mes "[Alp]";
	mes "There are suspicious traces everywhere.";
	mes "Some kind of heavy machine seems to have passed...";
	cutin "bu_alp1.bmp",2;
	close3;
}

1@uns,145,37,3	script	Tamarin#room1	4_M_TAMARIN,{
	mes "[Tamarin]";
	mes "Verity, are you alright?";
	mes "You do not look good...";
	cutin "ep143_taang.bmp",2;
	close3;
}

1@uns,143,38,5	script	Du#room1	4_M_REDMAN,{
	mes "[Du]";
	mes "I have a bad feeling about this...";
	cutin "bu_du1.bmp",2;
	close3;
}

1@uns,143,39,5	script	Maggi#room1	4_F_PINKWOMAN,{
	mes "[Maggi]";
	mes "Aahh....";
	cutin "bu_maggi4.bmp",2;
	close3;
}

1@uns,144,37,3	script	Verity#room1	4_F_BERRYTEA,{
	if ('protocole < 2) {
		mes "[Verity]";
		mes "Umph...I suddenly have a feeling that's not good.";
		cutin "EP15_2_brt_6.bmp",2;
		if (getpartyleader(getcharid(1),2) != getcharid(0)) {
			mes "I wish to talk with the leader.";
			close3;
		}
		npctalk "Verity: Umph...I suddenly have a feeling that's not good.";
		next;
		mes "[Verity]";
		mes "Something is splitting my head....Ugh....";
		npctalk "Verity: Something is splitting my head....Ugh....";
		next;
		mes "[Verity]";
		mes "....Ugh....";
		npctalk "Verity: ....Ugh....";
		next;
		mes "[Du]";
		mes "Sister! Are you alright?!";
		cutin "bu_du5.bmp",2;
		npctalk "Du: Sister! Are you alright?!", instance_npcname("Du#room1");
		next;
		mes "[Verity]";
		mes "....Have to go back....";
		cutin "EP15_2_brt_7.bmp",2;
		npctalk "Verity: ....Have to go back....";
		next;
		mes "[Tamarin]";
		mes "Verity, are you alright?";
		mes "Can you walk?";
		cutin "ep143_tahuk.bmp",2;
		npctalk "Tamarin: Verity, are you alright? Can you walk?", instance_npcname("Tamarin#room1");
		next;
		mes "[Verity]";
		mes "Ugh...";
		cutin "EP15_2_brt_6.bmp",2;
		npctalk "Verity: Ugh...";
		next;
		mes "[Du]";
		mes "" + strcharinfo(0) + "! I think it is better that you go back.";
		cutin "bu_du5.bmp",2;
		npctalk "Du: " + strcharinfo(0) + "! I think it is better that you go back.", instance_npcname("Du#room1");
		next;
		mes "[Verity]";
		mes "N...no. I will catch up soon so go on ahead.";
		cutin "EP15_2_brt_4.bmp",2;
		npctalk "Verity: N...no. I will catch up soon so go on ahead.";
		next;
		mes "[Tamarin]";
		mes "Then I will stay with Verity until she recovers so you can go on ahead.";
		cutin "ep143_tahuk.bmp",2;
		npctalk "Tamarin: Then I will stay with Verity until she recovers so you can go on ahead.";
		close2;
		'protocole = 1;
		cutin "",255;
	}
	end;
}

1@uns,140,45,0	script	#lrdoor2	HIDDEN_WARP_NPC,6,6,{
	end;
OnTouch:
	if ('protocole == 0)
		warp 'map_name$,142,30;
	else if ('protocole == 1) {
		'protocole = 2;
		disablenpc instance_npcname("#lrdoor2");
		disablenpc instance_npcname("Mark#room1");
		disablenpc instance_npcname("Du#room1");
		disablenpc instance_npcname("Tamarin#room1");
		disablenpc instance_npcname("Verity#room1");
		disablenpc instance_npcname("Maggi#room1");
		disablenpc instance_npcname("Alp#room1");
		mapannounce 'map_name$, "-----------------Creak---------------------",bc_map,"0xFF0000";
		sleep 2000;
		mapannounce 'map_name$, "-----Creak---Wrr--------------------------",bc_map,"0xFF0000";
		sleep 2000;
		mapannounce 'map_name$, "--------------Wirrrrrrr-----------------",bc_map,"0xFF0000";
		sleep 2000;
		mapannounce 'map_name$, "-----Zizip--------Zizizip------------------",bc_map,"0xFF0000";
		sleep 2000;
		mapannounce 'map_name$, "System message : Intruder detected.",bc_map,"0xFF0000";
		sleep 2000;
		mapannounce 'map_name$, "System message : Sealing off entrance and eliminating intruder according to designated protocols.",bc_map,"0xFF0000";
		donpcevent instance_npcname("protocole1") + "::OnStart";
	}
	end;
}

1@uns,1,1,0	script	protocole1	-1,{
	end;
OnStart:
	enablenpc instance_npcname("protocole1");
	monster 'map_name$,47,49,"System message",3253,1, instance_npcname("protocole1") + "::OnMyMobDead2";
	callsub S_Spawn;
OnTimer300000:
	mapannounce 'map_name$, "System message : Eliminating intruder.",bc_map,"0xFF0000";
	callsub S_Spawn;
S_Spawn:
	initnpctimer;
	.@npc_name$ = instance_npcname("protocole1");
	// don't kill System message
	killmonster 'map_name$, .@npc_name$ + "::OnMyMobDead";
	areamonster 'map_name$,118,56,131,67, "Machine Component",3251,6, .@npc_name$ + "::OnMyMobDead";
	areamonster 'map_name$, 62,82, 61,67, "Machine Component",3251,6, .@npc_name$ + "::OnMyMobDead";
	areamonster 'map_name$, 46,89, 64,96, "Machine Component",3251,6, .@npc_name$ + "::OnMyMobDead";
	areamonster 'map_name$,118,56,131,67, "Machine Component",3252,6, .@npc_name$ + "::OnMyMobDead";
	areamonster 'map_name$, 62,82, 61,67, "Machine Component",3252,6, .@npc_name$ + "::OnMyMobDead";
	areamonster 'map_name$, 46,89, 64,96, "Machine Component",3252,6, .@npc_name$ + "::OnMyMobDead";
	end;
OnMyMobDead:
OnMyMobDead2:
	.@count = mobcount( 'map_name$, instance_npcname("protocole1") + "::OnMyMobDead" ) + mobcount( 'map_name$, instance_npcname("protocole1") + "::OnMyMobDead2" );
	if (.@count < 1) {
		mapannounce 'map_name$, "System message : First protocol failed. Commencing next protocol.",bc_map,"0xFF0000";
		stopnpctimer;
		enablenpc instance_npcname("Tamarin#room2");
		disablenpc instance_npcname("protocole1");
	}
	end;
}

1@uns,67,97,3	script	Tamarin#room2	4_M_TAMARIN,{
	mes "[Tamarin]";
	mes "Huff huff... Verity suddenly huff huff couldn't even stand straight before huff huff...";
	cutin "ep143_tahuk.bmp",2;
	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
		next;
		mes "[Tamarin]";
		mes "I don't think this is a problem we can solve by talking amongst ourselves.";
		mes "Let's ask the leader's opinion first.";
		close3;
	}
	npctalk "Tamarin: Huff huff... Verity suddenly huff huff couldn't even stand straight before huff huff...";
	next;
	mes "[Tamarin]";
	mes "Ran off so fast huff...huff... to even catch up. Huff huff";
	npctalk "Tamarin: Ran off so fast huff...huff... to even catch up. Huff huff";
	next;
	mapannounce 'map_name$, "System message : An unidentified object is moving fast from Zone 1 to Zone 2.",bc_map,"0xFF0000";
	mes "[Tamarin]";
	mes "Uh... Could Verity have gone that far?";
	npctalk "Tamarin: Uh... Could Verity have gone that far?";
	next;
	mapannounce 'map_name$, "System message : Commencing emergency protocol.",bc_map,"0xFF0000";
	mes "[Tamarin]";
	mes "We need to find Verity quickly";
	npctalk "Tamarin: We need to find Verity quickly";
	next;
	mes "[Tamarin]";
	mes "There is only the route going up so go ahead.";
	npctalk "Tamarin: There is only the route going up so go ahead.";
	close2;
	if ('protocole == 2) {
		'protocole = 3;
		enablenpc instance_npcname("#lrdoor4");
		for ( .@i = 1; .@i < 16; ++.@i )
			enablenpc instance_npcname( "#lrboom" + .@i );
		enablenpc instance_npcname("Verity#room2");
		enablenpc instance_npcname("Verity#room3");
	}
	cutin "",255;
	end;
}

// 2nd step
1@uns,100,121,0	warp2	#lrdoor4	3,3,1@uns,145,107

1@uns,157,94,0	script	#lrboom1	4_CRACK,2,2,{
	end;
OnTouch:
	.@npc_name$ = instance_npcname( strnpcinfo(0) );
	areamonster 'map_name$,176,26,196,52, "Machine Component", (3251 + rand(2)), 3, .@npc_name$ + "::OnMyMobDead";
	mapannounce 'map_name$, "System message : Intruder detected in Zone 2.",bc_map,"0xFF0000";
	disablenpc .@npc_name$;
	end;
OnMyMobDead:
	end;
}
1@uns,164,97,0	duplicate(#lrboom1)	#lrboom2	4_CRACK,2,2
1@uns,166,92,0	duplicate(#lrboom1)	#lrboom3	4_CRACK,2,2
1@uns,170,96,0	duplicate(#lrboom1)	#lrboom4	4_CRACK,2,2
1@uns,175,93,0	duplicate(#lrboom1)	#lrboom5	4_CRACK,2,2
1@uns,190,97,0	duplicate(#lrboom1)	#lrboom6	4_CRACK,2,2
1@uns,194,94,0	duplicate(#lrboom1)	#lrboom7	4_CRACK,2,2
1@uns,199,96,0	duplicate(#lrboom1)	#lrboom8	4_CRACK,2,2
1@uns,206,93,0	duplicate(#lrboom1)	#lrboom9	4_CRACK,2,2
1@uns,217,91,0	duplicate(#lrboom1)	#lrboom10	4_CRACK,2,2
1@uns,224,79,0	duplicate(#lrboom1)	#lrboom11	4_CRACK,2,2
1@uns,227,73,0	duplicate(#lrboom1)	#lrboom12	4_CRACK,2,2
1@uns,227,69,0	duplicate(#lrboom1)	#lrboom13	4_CRACK,2,2
1@uns,220,63,0	duplicate(#lrboom1)	#lrboom14	4_CRACK,2,2
1@uns,201,60,0	duplicate(#lrboom1)	#lrboom15	4_CRACK,2,2

1@uns,224,29,3	script	Verity#room2	4_F_BERRYTEA,{
	mes "[Verity]";
	mes "Ah...Where am I..";
	mes "What happened?";
	cutin "EP15_2_brt_6.bmp",2;
	next;
	mes "[Verity]";
	mes "My head...is splitting.";
	mes "A sound coming from this...door...";
	next;
	if (select( "Quit.", "Go inside." ) == 1) {
		mes "[Verity]";
		mes "Go back...we have to go back...";
		cutin "EP15_2_brt_7.bmp",2;
		close3;
	}
	mes "[Verity]";
	mes "Quickly...we have to go back...";
	cutin "EP15_2_brt_7.bmp",2;
	close2;
	warp 'map_name$,240,255;
	cutin "",255;
	end;
}

// Last step
1@uns,242,253,3	script	Verity#room3	4_F_BERRYTEA,{
	mes "[Verity]";
	mes "Finally.. We came back...";
	mes "Finally.....";
	cutin "EP15_2_brt_7.bmp",2;
	close2;
	cutin "",255;
	if ('protocole == 3) {
		'protocole = 4;
		disablenpc instance_npcname("Verity#room3");
		donpcevent instance_npcname("protocole3") + "::OnStart";
	}
	end;
}

1@uns,1,1,0	script	protocole3	-1,{
	end;
OnStart:
	enablenpc instance_npcname("protocole3");
	initnpctimer;
	mapannounce 'map_name$, "System message : Intruder detected in Mother Room.",bc_map,"0xFF0000";
	monster 'map_name$,247,270,"T_W_O",3254,1, instance_npcname("protocole3") + "::OnMyMobDead";
	end;
OnTimer2000:
	mapannounce 'map_name$, "System message : Commencing final protocol.",bc_map,"0xFF0000";
	end;
OnTimer4000:
	mapannounce 'map_name$, "System message : Changing all systems from maintenance mode to combat mode.",bc_map,"0xFF0000";
	end;
OnTimer6000:
	mapannounce 'map_name$, "System message : This is the final protocol to protect... all unrelated personnel please evacuate.",bc_map,"0xFF0000";
	end;
OnTimer9000:
	mapannounce 'map_name$, "T_W_O : Have to go back..... This place isn't it....",bc_map,"0xFF0000";
	end;
OnTimer28000:
	mapannounce 'map_name$, "System message : System damage occurred.",bc_map,"0xFF0000";
	areamonster 'map_name$,222,250,267,281, "System message",3253,3, instance_npcname("protocole3") + "::OnMyMobDead2";
	end;
OnTimer30000:
	mapannounce 'map_name$, "T_W_O : Who am I? Why am I here?.",bc_map,"0xFF0000";
	end;
OnTimer58000:
	mapannounce 'map_name$, "System message : There may be critical damage within the Zone during system damage so please be careful.",bc_map,"0xFF0000";
	end;
OnTimer88000:
	mapannounce 'map_name$, "System message : System damage occurred.",bc_map,"0xFF0000";
	areamonster 'map_name$,222,250,267,281, "System message",3253,3, instance_npcname("protocole3") + "::OnMyMobDead2";
	end;
OnTimer98000:
	mapannounce 'map_name$, "T_W_O : There is nothing left....",bc_map,"0xFF0000";
	end;
OnTimer108000:
	mapannounce 'map_name$, "T_W_O : I... Nor them....",bc_map,"0xFF0000";
	end;
OnTimer148000:
	mapannounce 'map_name$, "System message : System damage occurred.",bc_map,"0xFF0000";
	areamonster 'map_name$,222,250,267,281, "System message",3253,3, instance_npcname("protocole3") + "::OnMyMobDead2";
	end;
OnTimer208000:
	mapannounce 'map_name$, "System message : System damage occurred.",bc_map,"0xFF0000";
	areamonster 'map_name$,222,250,267,281, "System message",3253,3, instance_npcname("protocole3") + "::OnMyMobDead2";
	stopnpctimer;
	end;
OnMyMobDead:
	stopnpctimer;
	killmonster 'map_name$, instance_npcname("protocole3") + "::OnMyMobDead2";
	mapannounce 'map_name$, "System message : All protocols failed. Locking down area excluding threat element.",bc_map,"0xFF0000";
	enablenpc instance_npcname("Alp#room4");
	enablenpc instance_npcname("Tamarin#room4");
	enablenpc instance_npcname("Maggi#room4");
	enablenpc instance_npcname("Du#room4");
	enablenpc instance_npcname("Mark#room4");
	enablenpc instance_npcname("Verity#room4");
	disablenpc instance_npcname("protocole3");
	end;
OnMyMobDead2:
	end;
}
	
1@uns,236,258,1	script	Alp#room4	4_M_BLACKMAN,{
	mes "[Alp]";
	mes "It's too early to relax...";
	cutin "bu_alp1.bmp",2;
	close3;
}

1@uns,244,257,3	script	Tamarin#room4	4_M_TAMARIN,{
	mes "[Tamarin]";
	mes "Verity!!!";
	mes "Pull yourself together!";
	cutin "ep143_tahuk.bmp",2;
	close3;
}

1@uns,245,254,3	script	Maggi#room4	4_F_PINKWOMAN,{
	mes "[Maggi]";
	mes "Verity, are you alright?";
	cutin "bu_maggi4.bmp",2;
	close3;
}

1@uns,244,254,3	script	Du#room4	4_M_REDMAN,{
	mes "[Du]";
	mes "Sister!";
	mes "What happened?!";
	mes "Are you alright?";
	cutin "bu_du5.bmp",2;
	close3;
}

1@uns,242,255,5	script	Mark#room4	4_M_BLUEMAN,{
	mes "[Mark]";
	mes "Everybody out of the way!";
	mes "I will cast Heal!!!";
	cutin "bu_mark4.bmp",0;
	close3;
}

1@uns,242,253,3	script	Verity#room4	4_F_BERRYTEA,{
	mes "[Du]";
	mes "Sister!";
	mes "What happened?!";
	mes "Are you alright?";
	cutin "bu_du5.bmp",2;
	npctalk "Du: Sister! What happened?! Are you alright?", instance_npcname("Du#room4");
	next;
	mes "[Tamarin]";
	mes "Verity!!!";
	mes "Pull yourself together!";
	cutin "ep143_tahuk.bmp",2;
	npctalk "Tamarin: Verity!!! Pull yourself together!", instance_npcname("Tamarin#room4");
	next;
	mes "[Mark]";
	mes "Everybody out of the way!";
	mes "I will cast Heal!!!";
	cutin "bu_mark4.bmp",0;
	npctalk "Mark: Everybody out of the way! I will cast Heal!!!", instance_npcname("Mark#room4");
	next;
	mes "[Verity]";
	mes "Uh..uhm...";
	cutin "EP15_2_brt_4.bmp",2;
	npctalk "Verity: Uh..uhm...";
	next;
	mes "[Verity]";
	mes "Oh...";
	mes "What is going on.";
	mes "With serious faces.";
	cutin "EP15_2_brt_5.bmp",2;
	npctalk "Verity Oh... What is going on. With serious faces.";
	next;
	mes "[Du]";
	mes "What do you think!";
	mes "You don't remember?";
	cutin "bu_du4.bmp",2;
	npctalk "Du: What do you think! You don't remember?", instance_npcname("Du#room4");
	next;
	mes "[Verity]";
	mes "Remember?";
	cutin "EP15_2_brt_5.bmp",2;
	npctalk "Verity: Remember?";
	next;
	mes "[Verity]";
	mes "... Come to think of it where am I?";
	cutin "EP15_2_brt_3.bmp",2;
	npctalk "Verity: ... Come to think of it where am I?";
	next;
	mes "[Tamarin]";
	mes "Verity you really don't remember anything?";
	mes "Before...";
	cutin "ep143_tahuk.bmp",2;
	npctalk "Tamarin: Verity you really don't remember anything? Before...", instance_npcname("Tamarin#room4");
	next;
	mes "[Verity]";
	mes "Uhm...";
	mes "I think my head was splitting since I went underground...";
	npctalk "Verity: I think my head was splitting since I went underground...";
	cutin "EP15_2_brt_3.bmp",2;
	next;
	mes "[Verity]";
	mes "I don't remember anything after that.";
	npctalk "Verity: I don't remember anything after that.";
	cutin "EP15_2_brt_5.bmp",2;
	next;
	mes "[Du]";
	mes "Just now something tremendous...";
	cutin "bu_du4.bmp",2;
	npctalk "Du: Just now something tremendous...", instance_npcname("Du#room4");
	next;
	mes "[Alp]";
	mes "Hey... I don't think this is a situation where we should be chatting right now.";
	cutin "bu_alp3.bmp",2;
	npctalk "Alp: Hey... I don't think this is a situation where we should be chatting right now.", instance_npcname("Alp#room4");
	next;
	mes "[Du]";
	mes "You call this chatting?";
	mes "It was tremendous before okay?";
	cutin "bu_du4.bmp",2;
	npctalk "Du: You call this chatting? It was tremendous before okay?", instance_npcname("Du#room4");
	next;
	mes "[Alp]";
	mes "Do you hear this?";
	mes "Something is coming...";
	cutin "bu_alp1.bmp",2;
	npctalk "Alp: Do you hear this? Something is coming...", instance_npcname("Alp#room4");
	next;
	mes "[Tamarin]";
	mes "Now...now that I look the ground is..., shaking a little, right?";
	cutin "ep143_tahuk.bmp",2;
	npctalk "Tamarin: Now...now that I look the ground is..., shaking a little, right?", instance_npcname("Tamarin#room4");
	next;
	mes "[Du]";
	mes "What...what's this?";
	cutin "bu_du4.bmp",2;
	npctalk "Du: What...what's this?", instance_npcname("Du#room4");
	next;
	mes "[Alp]";
	mes "This is...dangerous.";
	mes "This is not a level we can handle...";
	cutin "bu_alp2.bmp",2;
	npctalk "Alp: This is...dangerous. This is not a level we can handle...", instance_npcname("Alp#room4");
	next;
	mes "[Mark]";
	mes "Qui...quickly outside!!!!!";
	cutin "bu_mark4.bmp",0;
	npctalk "Mark: Qui...quickly outside!!!!!", instance_npcname("Mark#room4");
	close2;
	warp "un_bunker",299,162;
	cutin "",255;
	end;

OnInstanceInit:
	'map_name$ = instance_mapname("1@uns");
	'protocole = 0;

	// 1st step
	disablenpc instance_npcname("protocole1");
	disablenpc instance_npcname("Tamarin#room2");
	disablenpc instance_npcname("#lrdoor4");

	// 2nd step
	disablenpc instance_npcname("Verity#room2");
	for ( .@i = 1; .@i < 16; ++.@i )
		disablenpc instance_npcname( "#lrboom" + .@i );

	// Last step
	disablenpc instance_npcname("Verity#room3");
	disablenpc instance_npcname("protocole3");
	disablenpc instance_npcname("Alp#room4");
	disablenpc instance_npcname("Tamarin#room4");
	disablenpc instance_npcname("Maggi#room4");
	disablenpc instance_npcname("Du#room4");
	disablenpc instance_npcname("Mark#room4");
	disablenpc instance_npcname("Verity#room4");
	end;
}
