//===== rAthena Script =======================================
//= Instance: Thor Gunsu Base.
//===== Description: =========================================
//- [Walkthrough conversion]
//- Part of the episode 18.1 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_1_main != 45 && ep18_1_main != 46)
		end;
	if (ep18_1_main == 45) {
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "You have arrived, adventurer!";
		mes "You did a great job getting here.";
		next;
		cutin "ep18_maram_03.png",2;
		mes "[Maram]";
		mes "After all, it looks like this next one is real. The guards are different from before...";
		mes "Let's look inside, being careful not to be caught by the guards.";
		next;
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "Make sure to move out of sight of the guards as much as possible.";
		mes "If you make a mistake, you will be attacked, so if you don't break through, we'll meet again here.";
		changequest 16577,16578;
		ep18_1_main = 46;
		next;
	}
	else if (ep18_1_main == 46) {
		mes "[Maram]";
		mes "Let's try to get in as far as possible from the guard tower.";
		next;
	}

	.@md_name$ = "Thor Gunsu Base";
	cutin "",255;
	mes "^FF0000 Any arbitrary processing such as taming monsters in the dungeon is not considered normal. Please note.^000000";
	next;
	// player has party
	if (is_party_leader()) {
		// player is leader of the party
		.@create$ = "Open " + .@md_name$;
	}
	switch( select( .@create$, .@md_name$ + " entry" ) ) {
	case 1:
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "When the application is complete, talk to me again and select ^0000CD Thor military base 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 "I don't think the dungeon has been created yet? Please check later.";
			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,"0x00ff99",FW_NORMAL,12;
			// warp 1@tcamp,103,237;
			end;
		}
	}
	end;

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

1@tcamp,106,237,3	script	Maram#base1	4_EP18_MARAM,{
	cutin "ep18_maram_01.png",2;
	mes "[Maram]";
	mes "Be careful and explore the inside.";
	mes "I heard from Mr. Dandelion earlier, there aren't many people, but there are Watch Towers here and there that monitor a fairly wide area.";
	next;
	mes "[Maram]";
	mes "If you get caught by the Watch Tower, soldiers will appear, so be careful not to get caught.";
	mes "Well, if you find something, please contact me!";
	close3;

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

	disablenpc instance_npcname("Document Pile#Site1");
	disablenpc instance_npcname("Document Pile#Site2");
	disablenpc instance_npcname("Document Pile#Site3");
	disablenpc instance_npcname("Document Pile#Site4");
	disablenpc instance_npcname("Document Pile#Site5");
	disablenpc instance_npcname("Maram#Lock1");
	disablenpc instance_npcname("Maram#Lock2");
	disablenpc instance_npcname("Maram#Lock3");
	disablenpc instance_npcname("Maram#Lock4");

	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	Watch Tower#Watch1	4_SYSTEM_BOX,7,7,{
	end;
OnTouch:	// note: hidden player trigger the event
	npctalk "Detect intruders. Exclude them.";
	mapannounce 'map_tcamp$, "Intruder detected, intruder detected. We rule 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(Watch Tower#Watch1)	Watch Tower#Watch2	4_SYSTEM_BOX,7,7
1@tcamp,152,133,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch3	4_SYSTEM_BOX,7,7
1@tcamp,167,133,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch4	4_SYSTEM_BOX,7,7
1@tcamp,182,133,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch5	4_SYSTEM_BOX,7,7
1@tcamp,161,96,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch6	4_SYSTEM_BOX,7,7
1@tcamp,146,96,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch7	4_SYSTEM_BOX,7,7
1@tcamp,116,102,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch8	4_SYSTEM_BOX,7,7
1@tcamp,88,92,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch9	4_SYSTEM_BOX,7,7
1@tcamp,240,148,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch10	4_SYSTEM_BOX,7,7
1@tcamp,156,71,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch11	4_SYSTEM_BOX,7,7
1@tcamp,176,194,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch12	4_SYSTEM_BOX,7,7
1@tcamp,192,194,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch13	4_SYSTEM_BOX,7,7
1@tcamp,142,153,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch14	4_SYSTEM_BOX,7,7
1@tcamp,142,168,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch15	4_SYSTEM_BOX,7,7
1@tcamp,192,179,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch16	4_SYSTEM_BOX,7,7
1@tcamp,237,90,3	duplicate(Watch Tower#Watch1)	Watch Tower#Watch17	4_SYSTEM_BOX,7,7


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

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

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

1@tcamp,80,99,3	script	Lock#4-1	4_ROPEPILE,{
	.@maram$ = instance_npcname("Maram#Lock4");
	enablenpc .@maram$;
	npctalk "Maram: I think you've gotten pretty deep. You should be able to find what you need safely.", .@maram$;
	progressbar_npc "3131FF",10;
	npctalk "Maram: Shall we wish you luck?", .@maram$;
	disablenpc instance_npcname("Lock#4-1");
	disablenpc instance_npcname("Lock#4-2");
	disablenpc instance_npcname("Lock#4-3");
	disablenpc .@maram$;
	setcell 'map_tcamp$,80,94,80,100,cell_walkable,1;

	enablenpc instance_npcname("Document Pile#Site1");
	enablenpc instance_npcname("Document Pile#Site2");
	enablenpc instance_npcname("Document Pile#Site3");
	enablenpc instance_npcname("Document Pile#Site4");
	enablenpc instance_npcname("Document Pile#Site5");
	enablenpc instance_npcname("Miriam#base1");
	enablenpc instance_npcname("Maram#base5");
	end;
}
1@tcamp,80,97,3	duplicate(Lock#4-1)	Lock#4-2	4_ROPEPILE
1@tcamp,80,95,3	duplicate(Lock#4-1)	Lock#4-3	4_ROPEPILE
1@tcamp,82,100,3	duplicate(dummy_npc)	Maram#Lock4	4_EP18_MARAM


//-------------------------------------------------------------------
// Final
//-------------------------------------------------------------------
1@tcamp,32,100,3	script	Document Pile#Site1	4_EP18_PAPERS,{
	mes "[Pile of Papers]";
	mes "All the papers are jumbled up.";
	mes "I took out a few sheets from the middle These are the expiry date of the weapon and the sales statement.";
	next;
	mes "[Pile of Papers]";
	mes "Even the date is very recent. There is a record of handing over a large number of weapons to Mr. Dandelion.";
	mes "I think I found what I was looking for. I put the documents in my pocket.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself( instance_npcname("Document Pile#Site1") );
	end;
}

1@tcamp,49,123,3	script	Document Pile#Site2	4_EP18_PAPERS,{
	mes "[Pile of Papers]";
	mes "All the papers are jumbled up.";
	mes "At the top of the page the final menu for luncheon dinner?";
	next;
	mes "[Pile of Papers]";
	mes "It seems that the menu is fried fish with sauce.";
	mes "You seem to have left unimportant documents. Let's take care of them first.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself( instance_npcname("Document Pile#Site2") );
	end;
}

1@tcamp,29,86,3	script	Document Pile#Site3	4_EP18_PAPERS,{
	mes "[Pile of Papers]";
	mes "All the papers are jumbled up.";
	mes "I took one out of the middle The layout of the military base guards?";
	next;
	mes "[Pile of Papers]";
	mes "Looking at the date, it was a long time ago.";
	mes "You seem to have left unimportant documents. Let's take care of them first.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself( instance_npcname("Document Pile#Site3") );
	end;
}

1@tcamp,60,122,3	script	Document Pile#Site4	4_EP18_PAPERS,{
	mes "[Pile of Papers]";
	mes "All the papers are jumbled up.";
	mes "The top one... 'If you feed the magmaring potatoes and hunt them after a while, will they drop the baked potatoes?'";
	next;
	mes "[Pile of Papers]";
	mes "why is this here. But I'm curious about the result!";
	mes "You seem to have left unimportant documents. Let's take care of them first.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself( instance_npcname("Document Pile#Site4") );
	end;
}

1@tcamp,31,84,3	script	Document Pile#Site5	4_EP18_PAPERS,{
	mes "[Pile of Papers]";
	mes "All the papers are jumbled up.";
	mes "Picking one out of the middle I found an illustration of the Pope drawn by icing the Pope's cookie icing with a pen.";
	next;
	mes "[Pile of Papers]";
	mes "What kind of picture is it? Besides, you drew it very well.";
	mes "You seem to have left unimportant documents. Let's take care of them first.";
	close2;
	getitem 1000409,1;	// Ep18_Docu_File
	cloakonnpcself( instance_npcname("Document Pile#Site5") );
	end;
}


1@tcamp,34,100,3	script	Miriam#base1	4_EP18_MIRIAM,3,3,{
	disable_items;
	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 sorts of connections to find the position.";
		mes "It seems that Adventurer and Maram found it at once.";
		next;
		mes "[Miriam]";
		mes "Read some of the documents here. We have what we were looking for.";
		mes "I think it would be better to come and see it firsthand than to explain everything.";
		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;
	}
	cutin "ep18_miriam_02.png",2;
	mes "[Miriam]";
	mes ".";
	next;
	cutin "ep18_maram_01.png",2;
	mes "[Maram]";
	mes "No, Miriam! How are you here?";
	mes "They said they would investigate separately!";
	next;
	cutin "ep18_miriam_01.png",2;
	mes "[Miriam]";
	mes "How did you and the adventurer dig this far?";
	mes "You have good skills, too. It was a location that I found using all kinds of connections, but you found it at once.";
	next;
	cutin "ep18_maram_02.png",2;
	mes "[Maram]";
	mes "Let's do some, 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 is a sales statement for arms. Show it to me as well.";
	mes "The weapons and firearms these men have disposed of are all less than a year old.";
	next;
	cutin "ep18_miriam_03.png",2;
	mes "[Miriam]";
	mes "How dare you sell such weapons.";
	mes "A weapon that is not properly maintained may not function properly.";
	next;
	cutin "ep18_maram_03.png",2;
	mes "[Maram]";
	mes "The weapons that come out of the back hole are all the same.";
	mes "but, at least it's at this point.";
	next;
	mes "[Maram]";
	mes "A year is not a long term, but it is not tight.";
	mes "Why did we pour out at this moment in preparation for the protest?";
	next;
	mes "[Maram]";
	mes "You wouldn't have to dispose of it right away.";
	next;
	npctalk "Maram: haha, this is so funny", instance_npcname("Maram#base5");
	sleep2 300;
	cutin "ep18_miriam_02.png",2;
	mes "[Miriam]";
	mes "This is one of the military bases managed by my stepfather.";
	mes "Just by chance, it really came out at a time like this.";
	next;
	cutin "",255;
	select( "If your stepfather is a priest, Youth Amal?", "The hard-line and pro-war stepfather?" );
	cutin "ep18_miriam_02.png",2;
	mes "[Miriam]";
	mes "That's right, adventurer. Looking at the ledger, it doesn't seem like the stepfather was involved.";
	mes "I think it was a single corruption at the end, the weapon leak case.";
	next;
	mes "[Miriam]";
	mes "I'll have to dig a little deeper, but that's my guess for now.";
	mes "Oh, give me the documents. I'll take it as evidence.";
	delitem 1000409,5;	// Ep18_Docu_File
	if (isbegin_quest(16578) == 1) {
		erasequest 16578;
		setquest 16579;
	}
	close2;
	cutin "",255;
	npctalk "Maram: haha, this is so funny", instance_npcname("Maram#base5");
	end;

OnTouch:
	npctalk "Miriam: Oh, adventurer? Maram you too!?";
	end;

OnInstanceInit:
	questinfo( QTYPE_QUEST, QMARK_YELLOW, "isbegin_quest(16578) == 1 && countitem(1000409) > 4" );	// Ep18_Docu_File
	disablenpc instance_npcname("Miriam#base1");
	end;
}

1@tcamp,32,102,3	script	Maram#base5	4_EP18_MARAM,{
	if (isbegin_quest(16579) == 0) {
		cutin "ep18_maram_01.png",2;
		mes "[Maram]";
		mes "I didn't know Miriam was here, right, adventurer?";
		close3;
	}
	cutin "ep18_maram_02.png",2;
	mes "[Maram]";
	mes "We moved separately, but in the end we are in the same position.";
	mes "Still, what I got in the process was different, so I guess it has its own meaning.";
	next;
	cutin "ep18_miriam_02.png",2;
	mes "[Miriam]";
	mes "Then I must be away for a while.";
	mes "I'm going to pass on my findings to my stepfather.";
	next;
	mes "[Miriam]";
	mes "Because there is a possibility that the adoptive father may not know yet if it is a single corruption.";
	next;
	cutin "ep18_maram_03.png",2;
	mes "[Maram]";
	mes "Is it really an independent corruption? That's probably what bothers me.";
	mes "I have something to give to Rachel, Miriam, let's go together.";
	next;
	cutin "ep18_maram_01.png",2;
	mes "[Maram]";
	mes "I'll give you a shortcut, so can you please tell Suad what you found out here?";
	mes "We will follow soon, so please go ahead and tell me.";
	if (ep18_1_main == 46) {
		ep18_1_main = 47;
		erasequest 16579;
		setquest 16580;
		getitem "Ep18_Amethyst_Fragment",50;
	}
	close2;
	warp "wolfvill",162,154;
	end;

OnInstanceInit:
	questinfo( QTYPE_QUEST, QMARK_YELLOW, "isbegin_quest(16579) == 1" );
	disablenpc instance_npcname("Maram#base5");
	end;
}
