//===== rAthena Script =======================================
//= Instance: Thor Gunsu Base.
//===== Description: =========================================
//- [Walkthrough conversion]
//- Part of the Episode 18 main quest.
//===== Changelogs: ==========================================
//= 1.0 First version. [Capuche]
//============================================================

// Main Quest: Step 47.
que_thr,133,53,5	script	Maram#Armybase1	4_EP18_MARAM,{
	if (ep18_main < 45 || ep18_main > 46)
		end;
	if (ep18_main == 45) {
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "You've arrived, adventurer!";
		mes "Thank you for coming all the way here.";
		next;
		cutin "ep18_maram_03.png",2;
		mes "[Maram]";
		mes "It seems like this is the real deal after all. The security here is different from what it has been so far....";
		mes "Let's be careful not to be caught by the guards and explore the inside.";
		next;
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "Try to move away from the security guard's line of sight as much as possible.";
		mes "If you get caught, you might be attacked, so if you can't break through, we'll meet again here.";
		erasequest 16577;
		setquest 16578;
		ep18_main = 46;
		next;
	}
	else if (ep18_main == 46) {
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "Let's try to go in while avoiding the guard tower as much as possible.";
		next;
	}

	.@md_name$ = "Thor Military Base";
	cutin "",255;
	mes "^FF0000Caution : If you perform arbitrary processing within the dungeon, such as monster taming, it will not be considered normal progress.^000000";
	next;
	// player has party
	if (is_party_leader())
		// player is leader of the party
		.@create$ = "Apply for entry to " + .@md_name$ + "";

	switch( select( .@create$, "Enter " + .@md_name$ + "" ) ) {
	case 1:
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "When the application is complete, talk to me again and select ^0000CD" + .@md_name$ + " entry^000000";
		if (instance_create(.@md_name$) < 0) {
			mes "Party: " + getpartyname(getcharid(1)) + "";
			mes "Leader: " + strcharinfo(0) + "";
			mes "^0000ff" + .@md_name$ + " ^000000- Unknown error";
			close3;
		}
		close3;
	case 2:
		// Note: instance not forced solo
		switch( instance_enter(.@md_name$) ) {
		case IE_OTHER:
			mes "[Maram]";
			mes "^ff0000An unknown error occurred.^000000";
			close;
		case IE_NOINSTANCE:
			cutin "ep18_maram_01.png",2;
			mes "[Maram]";
			mes "It seems like you haven't created the dungeon yet. Please check again in a moment.";
			close3;
		case IE_NOMEMBER:
			mes "[Maram]";
			mes "^ff0000Only a member of the party can enter the Memorial Dungeon.^000000";
			close;
		case IE_OK:
			mapannounce "que_thr", "" + strcharinfo(0) + " of the party, " + getpartyname( getcharid(1) ) + ", is entering " + .@md_name$ + ".", bc_map, 0xFF99;
			// warp 1@tcamp,103,237;
			end;
		}
	}
	end;

OnInit:
	questinfo( QTYPE_QUEST2, QMARK_YELLOW, "isbegin_quest(16577) == 1" );
	end;
}

1@tcamp,106,237,3	script	Maram#Base1	4_EP18_MARAM,{
	mes "[Maram]";
	mes "Be careful and explore inside.";
	mes "From what I heard from Dandelion earlier, there aren't many people, but there are watchtowers here and there that monitor a fairly wide area.";
	next;
	mes "[Maram]";
	mes "If you get caught by the watchtower, soldiers will appear, so be careful not to get caught.";
	mes "Well, if you find anything, please contact me!";
	close;

OnInstanceInit:
	'step = 0;
	'map_tcamp$ = instance_mapname("1@tcamp");

	setcell 'map_tcamp$,137,216,142,216,cell_walkable,0;
	setcell 'map_tcamp$,135,145,144,145,cell_walkable,0;
	setcell 'map_tcamp$,223,105,223,110,cell_walkable,0;
	setcell 'map_tcamp$,80,94,80,100,cell_walkable,0;

	// some monsters spawn randomly
	monster 'map_tcamp$,0,0,"Base Soldier",21310,18;	// EP18_MD_GUARD_A
	monster 'map_tcamp$,0,0,"Base Soldier",21309,18;	// EP18_MD_THOR_GUARD
	end;
}

// unknown npc effect
// 1@tcamp,244,152,3	duplicate(dummy_npc)	#Remote 1	CLEAR_NPC


//-------------------------------------------------------------------
// Traps
//-------------------------------------------------------------------
1@tcamp,120,228,3	script	Watchtower#Watch1	4_SYSTEM_BOX,7,7,{
	end;
OnTouch:	// note: hidden player trigger the event
	npctalk "Intruder detected !!";
	mapannounce 'map_tcamp$, "Intruder found, intruder found. Ruled out immediately.", bc_map, 0xFF0000;
	getmapxy .@map$,.@x,.@y, BL_NPC;

	areamonster 'map_tcamp$,.@x-2,.@y-2,.@x+2,.@y+2,"Base Soldier",21309,3;	// EP18_MD_THOR_GUARD
	areamonster 'map_tcamp$,.@x-2,.@y-2,.@x+2,.@y+2,"Base Soldier",21310,3;	// EP18_MD_GUARD_A
	end;
OnTimer2000:
	specialeffect EF_WARP;
	initnpctimer;
	end;
OnInstanceInit:
	initnpctimer;
	end;
}

1@tcamp,135,228,3	duplicate(Watchtower#Watch1)	Watchtower#Watch2	4_SYSTEM_BOX,7,7
1@tcamp,152,133,3	duplicate(Watchtower#Watch1)	Watchtower#Watch3	4_SYSTEM_BOX,7,7
1@tcamp,167,133,3	duplicate(Watchtower#Watch1)	Watchtower#Watch4	4_SYSTEM_BOX,7,7
1@tcamp,182,133,3	duplicate(Watchtower#Watch1)	Watchtower#Watch5	4_SYSTEM_BOX,7,7
1@tcamp,161,96,3	duplicate(Watchtower#Watch1)	Watchtower#Watch6	4_SYSTEM_BOX,7,7
1@tcamp,146,96,3	duplicate(Watchtower#Watch1)	Watchtower#Watch7	4_SYSTEM_BOX,7,7
1@tcamp,116,102,3	duplicate(Watchtower#Watch1)	Watchtower#Watch8	4_SYSTEM_BOX,7,7
1@tcamp,88,92,3	duplicate(Watchtower#Watch1)	Watchtower#Watch9	4_SYSTEM_BOX,7,7
1@tcamp,240,148,3	duplicate(Watchtower#Watch1)	Watchtower#Watch10	4_SYSTEM_BOX,7,7
1@tcamp,156,71,3	duplicate(Watchtower#Watch1)	Watchtower#Watch11	4_SYSTEM_BOX,7,7
1@tcamp,176,194,3	duplicate(Watchtower#Watch1)	Watchtower#Watch12	4_SYSTEM_BOX,7,7
1@tcamp,192,194,3	duplicate(Watchtower#Watch1)	Watchtower#Watch13	4_SYSTEM_BOX,7,7
1@tcamp,142,153,3	duplicate(Watchtower#Watch1)	Watchtower#Watch14	4_SYSTEM_BOX,7,7
1@tcamp,142,168,3	duplicate(Watchtower#Watch1)	Watchtower#Watch15	4_SYSTEM_BOX,7,7
1@tcamp,192,179,3	duplicate(Watchtower#Watch1)	Watchtower#Watch16	4_SYSTEM_BOX,7,7
1@tcamp,237,90,3	duplicate(Watchtower#Watch1)	Watchtower#Watch17	4_SYSTEM_BOX,7,7


//-------------------------------------------------------------------
// Walls
//-------------------------------------------------------------------
1@tcamp,138,216,3	script	Lock Device#1-1	4_ROPEPILE,{
	.@maram$ = instance_npcname("Maram#Lock Device1");
	enablenpc .@maram$;
	npctalk "Maram: Please wait a moment. I know how to open it.", .@maram$;
	progressbar_npc "3131FF",10;
	npctalk "Maram: Well, we can pass now!", .@maram$;
	disablenpc instance_npcname("Lock Device#1-1");
	disablenpc instance_npcname("Lock Device#1-2");
	disablenpc .@maram$;
	setcell 'map_tcamp$,137,216,142,216,cell_walkable,1;
	end;
}
1@tcamp,141,216,3	duplicate(Lock Device#1-1)	Lock Device#1-2	4_ROPEPILE
1@tcamp,140,218,3	duplicate(dummy_disabled_npc)	Maram#Lock Device1	4_EP18_MARAM

1@tcamp,136,145,3	script	Lock Device#2-1	4_ROPEPILE,{
	.@maram$ = instance_npcname("Maram#Lock Device2");
	enablenpc .@maram$;
	progressbar_npc "3131FF",10;
	npctalk "It would be better to proceed with caution.", .@maram$;
	disablenpc instance_npcname("Lock Device#2-1");
	disablenpc instance_npcname("Lock Device#2-2");
	disablenpc instance_npcname("Lock Device#2-3");
	disablenpc instance_npcname("Lock Device#2-4");
	disablenpc .@maram$;
	setcell 'map_tcamp$,135,145,144,145,cell_walkable,1;
	end;
}
1@tcamp,138,145,3	duplicate(Lock Device#2-1)	Lock Device#2-2	4_ROPEPILE
1@tcamp,141,145,3	duplicate(Lock Device#2-1)	Lock Device#2-3	4_ROPEPILE
1@tcamp,143,145,3	duplicate(Lock Device#2-1)	Lock Device#2-4	4_ROPEPILE
1@tcamp,142,147,3	duplicate(dummy_disabled_npc)	Maram#Lock Device2	4_EP18_MARAM

1@tcamp,223,109,3	script	Lock Device#3-1	4_ROPEPILE,{
	.@maram$ = instance_npcname("Maram#Lock Device3");
	enablenpc .@maram$;
	npctalk "Maram: This building looks quite suspicious, right? There must be a surveillance system in here too.", .@maram$;
	progressbar_npc "3131FF",10;
	npctalk "Maram: Let's explore carefully this time, being careful not to get caught.", .@maram$;
	disablenpc instance_npcname("Lock Device#3-1");
	disablenpc instance_npcname("Lock Device#3-2");
	disablenpc .@maram$;
	setcell 'map_tcamp$,223,105,223,110,cell_walkable,1;
	end;
}
1@tcamp,223,106,3	duplicate(Lock Device#3-1)	Lock Device#3-2	4_ROPEPILE
1@tcamp,226,114,3	duplicate(dummy_disabled_npc)	Maram#Lock Device3	4_EP18_MARAM

1@tcamp,80,99,3	script	Lock Device#4-1	4_ROPEPILE,{
	.@maram$ = instance_npcname("Maram#Lock Device4");
	enablenpc .@maram$;
	npctalk "Maram: Looks like we're in pretty deep. We should be able to safely find what we need.", .@maram$;
	progressbar_npc "3131FF",10;
	npctalk "Maram: Shall we wish you good luck?", .@maram$;
	disablenpc instance_npcname("Lock Device#4-1");
	disablenpc instance_npcname("Lock Device#4-2");
	disablenpc instance_npcname("Lock Device#4-3");
	disablenpc .@maram$;
	setcell 'map_tcamp$,80,94,80,100,cell_walkable,1;

	enablenpc instance_npcname("Pile of documents#Base1");
	enablenpc instance_npcname("Pile of documents#Base2");
	enablenpc instance_npcname("Pile of documents#Base3");
	enablenpc instance_npcname("Pile of documents#Base4");
	enablenpc instance_npcname("Pile of documents#Base5");
	enablenpc instance_npcname("Miriam#Base1");
	enablenpc instance_npcname("Maram#Base5");
	if ('step == 0)
		'step = 1;
	end;
}
1@tcamp,80,97,3	duplicate(Lock Device#4-1)	Lock Device#4-2	4_ROPEPILE
1@tcamp,80,95,3	duplicate(Lock Device#4-1)	Lock Device#4-3	4_ROPEPILE
1@tcamp,82,100,3	duplicate(dummy_disabled_npc)	Maram#Lock Device4	4_EP18_MARAM


//-------------------------------------------------------------------
// Final
//-------------------------------------------------------------------
1@tcamp,32,100,3	script(DISABLED)	Pile of documents#Base1	4_EP18_PAPERS,{
	if ('step != 1)
		end;
	mes "[Pile of documents]";
	mes "All kinds of documents are all mixed up.";
	mes "I took out a few pages from the middle and found that they were weapons expiration dates and sales records.";
	next;
	mes "[Pile of documents]";
	mes "Even the date is very recent. There is also a record of handing over a large amount of weapons to Mr. Dandelion.";
	mes "It looks like I found what I was looking for. I put the documents in my arms.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself();
	end;
}

1@tcamp,49,123,3	script(DISABLED)	Pile of documents#Base2	4_EP18_PAPERS,{
	if ('step != 1)
		end;
	mes "[Pile of documents]";
	mes "All kinds of documents are all mixed up.";
	mes "On the top page... is it a battle to decide the menu for lunch?";
	next;
	mes "[Pile of documents]";
	mes "It looks like the menu has been set on fried fish covered in sauce....";
	mes "It looks like he left behind only unimportant documents. Let's take care of them for now.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself();
	end;
}

1@tcamp,29,86,3	script(DISABLED)	Pile of documents#Base3	4_EP18_PAPERS,{
	if ('step != 1)
		end;
	mes "[Pile of documents]";
	mes "All kinds of documents are all mixed up.";
	mes "I took one out from the middle and saw... a map of the security guards at the military base?";
	next;
	mes "[Pile of documents]";
	mes "Looking at the date, it's a long time ago document.";
	mes "It looks like he left behind only unimportant documents. Let's take care of them for now.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself();
	end;
}

1@tcamp,60,122,3	script(DISABLED)	Pile of documents#Base4	4_EP18_PAPERS,{
	if ('step != 1)
		end;
	mes "[Pile of documents]";
	mes "All kinds of documents are all mixed up.";
	mes "The top chapter is... If you feed a magmaring a potato and then hunt it after a while, should it drop a baked potato?'";
	next;
	mes "[Pile of documents]";
	mes "...Why is this here? But I'm curious about the results!";
	mes "It looks like he left behind only unimportant documents. Let's take care of them for now.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself();
	end;
}

1@tcamp,31,84,3	script(DISABLED)	Pile of documents#Base5	4_EP18_PAPERS,{
	if ('step != 1)
		end;
	mes "[Pile of documents]";
	mes "All kinds of documents are all mixed up.";
	mes "When I pulled one out from the middle... I found an illustration of the Pope drawn with Pope cookie icing using a pen.";
	next;
	mes "[Pile of documents]";
	mes "What kind of picture is this? And it's really well drawn....";
	mes "It looks like he left behind only unimportant documents. Let's take care of them for now.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself();
	end;
}


1@tcamp,34,100,3	script(DISABLED)	Miriam#Base1	4_EP18_MIRIAM,3,3,{
	if ('step == 1) {
		if (countitem(1000409) < 5) {	// Ep18_Docu_File
			cutin "ep18_miriam_02.png",2;
			mes "[Miriam]";
			mes "As expected, you are talented, adventurer. I used all my connections to find out the location.";
			mes "It looks like you found the adventurer and Maram right away.";
			next;
			mes "[Miriam]";
			mes "Please read these documents. They contain what we are looking for.";
			mes "Rather than having me explain everything to you, I think it would be better for you to see it for yourself.";
			close3;
		}
		if (getequipid(EQI_HEAD_TOP) != 400127) {	// Ep18_Mini_Elly
			mes "[Mini Elly]";
			mes "Get it out of the bag. Put it on your head.";
			close;
		}
		mes "[Miriam]";
		mes ".......";
		next;
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "No, Miriam! How are you here?";
		mes "They said they would conduct a separate investigation!";
		next;
		cutin "ep18_miriam_01.png",2;
		mes "[Miriam]";
		mes "How did you and the adventurer dig this far?";
		mes "As expected, your skills are good. I used all my connections to find out the location, but you found it right away.";
		next;
		cutin "ep18_maram_02.png",2;
		mes "[Maram]";
		mes "Let's do something about it, right, adventurer?";
		mes "Anyway, what information did you get?";
		next;
		cutin "ep18_miriam_02.png",2;
		mes "[Miriam]";
		mes "Look at this document here.";
		next;
		cutin "",255;
		mes "[Mini Elly]";
		mes "This document is a weapon sales record. Please show it to me.";
		mes "All of the weapons and firearms that these people disposed of have less than a year left before their expiration date.";
		next;
		cutin "ep18_miriam_03.png",2;
		mes "[Miriam]";
		mes "You sell weapons like this so recklessly.";
		mes "If a weapon is not properly maintained, it may not function properly.";
		next;
		cutin "ep18_maram_03.png",2;
		mes "[Maram]";
		mes "The quality of all weapons coming out of the back hole is the same.";
		mes "...But I guess it's at this point in time.";
		next;
		mes "[Maram]";
		mes "One year is not a long expiration date, but it is not too tight.";
		mes "Why did it pour out at this moment when we were preparing for the protest?";
		next;
		mes "[Maram]";
		mes "There wouldn't have been a need to dispose of it right away.";
		next;
		cutin "ep18_miriam_02.png",2;
		mes "[Miriam]";
		mes "This is one of the military bases managed by my adoptive father.";
		mes "I was wondering if it would really pop out at a time like this.";
		next;
		cutin "",255;
		select( "If it's your adoptive father, is it Priest Amal?", "That adoptive father who is a hardliner and pro-war?" );
		cutin "ep18_miriam_02.png",2;
		mes "[Miriam]";
		mes "That's right, adventurer. When I looked at the ledger, it doesn't seem like my adoptive father was involved.";
		mes "I think it's an isolated corruption at the lowest level, the weapons leak incident.";
		next;
		mes "[Miriam]";
		mes "I'll have to dig a little deeper, but that's my guess for now.";
		mes "Oh, please give me the documents. I'll take them as evidence.";
		delitem 1000409,5;	// Ep18_Docu_File
		if ('step == 1)
			'step = 2;
		if (isbegin_quest(16578) == 1) {
			erasequest 16578;
			setquest 16579;
		}
		close2;
		cutin "",255;
		npctalk "Maram: Ha, this is really fun.", instance_npcname("Maram#Base5");
		end;
	}
	if ('step == 2) {
		cutin "ep18_miriam_02.png",2;
		mes "[Miriam]";
		mes "...Just a moment, I'm reading the document.";
		close;
	}
	end;

OnTouch:
	if (countitem(1000409) < 5)
		npctalk "Miriam: Oh, adventurer? Maram, you too!?";
	end;

OnInstanceInit:
	questinfo( QTYPE_QUEST2, QMARK_YELLOW, "isbegin_quest(16578) == 1 && countitem(1000409) > 4" );	// Ep18_Docu_File
	end;
}

1@tcamp,32,102,3	script(DISABLED)	Maram#Base5	4_EP18_MARAM,{
	if ('step == 1) {
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "I didn't know Miriam would be here. Right, adventurer?";
		close3;
	}
	if ('step == 2) {
		mes "[Maram]";
		mes "They moved separately, but ended up in the same place.";
		mes "Still, what I gained from the process was different, so I guess it has some meaning.";
		next;
		cutin "ep18_miriam_02.png",2;
		mes "[Miriam]";
		mes "Then I guess I'll have to leave for a while.";
		mes "I'll have to relay what I found out to my adoptive father.";
		next;
		mes "[Miriam]";
		mes "If it's an isolated corruption, there's a chance that even my adoptive father doesn't know about it yet.";
		next;
		cutin "ep18_maram_03.png",2;
		mes "[Maram]";
		mes "Is this really an isolated case of corruption? That is something that bothers me.";
		mes "I also have something to deliver to Rachel, so Miriam, let's go together.";
		next;
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "I will tell you a shortcut to get out, so would you, adventurer, tell Suad what you found out here?";
		mes "We will follow shortly, so please go and tell us first.";
		if (ep18_main == 46) {
			ep18_main = 47;
			erasequest 16579;
			setquest 16580;
			getitem 1000405,50;	// Ep18_Amethyst_Fragment
		}
		close2;
		warp "wolfvill",162,154;
		end;
	}
	// debug
	warp "wolfvill",162,154;
	end;

OnInstanceInit:
	questinfo( QTYPE_QUEST2, QMARK_YELLOW, "isbegin_quest(16579) == 1" );
	end;
}
