//================= Hercules Script =======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2013-2015  Hercules Dev Team
//= Copyright (C)  Euphy
//=
//= Hercules is free software: you can redistribute it and/or modify
//= it under the terms of the GNU General Public License as published by
//= the Free Software Foundation, either version 3 of the License, or
//= (at your option) any later version.
//=
//= This program is distributed in the hope that it will be useful,
//= but WITHOUT ANY WARRANTY; without even the implied warranty of
//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//= GNU General Public License for more details.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http://www.gnu.org/licenses/>.
//=========================================================================
//= Buwaya Cave
//================= Description ===========================================
//= Defeat Buwaya in his cave.
//= Part of the "Secret in the Woods" quest.
//================= Current Version =======================================
//= 1.0
//=========================================================================

ma_fild02,312,317,5	script	Guard#buwaya_cave	4_MAL_SOLDIER,{
	if (BaseLevel < 130) {
		mes("[Guard]");
		mes("People under ^ff0000level 130^000000");
		mes("cannot enter this place.");
		mes("This place is dangerous. Please go back.");
		close();
	}

	.@party_id = getcharid(CHAR_ID_PARTY);
	.@md_name$ = _("Buwaya Cave");

	if (!.@party_id) {
		mes("[Guard]");
		mes("Buwaya is dangerous.");
		mes("Please come back after you form a");
		mes("team with other people.");
		close();
	}
	if (getcharid(CHAR_ID_CHAR) == getpartyleader(.@party_id, 2)) {
		mes("[Guard]");
		mes("This place is dangerous. Please go back.");
		mes("If you dont have any business here, please go back.");
		next();
		while (true) {
			switch (select("Why is it so dangerous?", "I'm here to hunt down Buwaya.", "End conversation.")) {
			case 1:
				mes("[Guard]");
				mes("Recently, there has been a case");
				mes("where villagers have disappeared.");
				mes("After investigating the tracks, ");
				mes("we found out the giant monster Buwaya");
				mes("was responsible.");
				next();
				mes("[Guard]");
				mes("Soldiers and mercenaries have been dispatched to ");
				mes("hunt down Buwaya, but were never");
				mes("completely successful.");
				next();
				mes("[Guard]");
				mes("Buwaya is still kidnapping");
				mes("the villagers to this day.");
				mes("Please gather some people to get rid of Buwaya.");
				next();
				break;
			case 2:
				.@playtime = questprogress(4229, PLAYTIME);
				if (!.@playtime) {
					// fall through
				} else if (.@playtime == 1) {
					mes("[Guard]");
					mes("Buwaya is still hiding.");
					mes("Even if you enter now, Buwaya will not come out. ");
					mes("Please come back later.");
					close();
				} else {
					erasequest(4229);
					// fall through
				}
				.@instance = instance_create(.@md_name$, .@party_id);
				if (.@instance >= 0) {
					if (instance_attachmap("1@ma_c", .@instance) == "") {
						mes("[Guard]");
						mesf("Party name is... %s.", getpartyname(.@party_id));
						mesf("Party leader is... %s", strcharinfo(PC_NAME));
						mesf("^0000ff%s^000000 cannot be opened now.", .@md_name$);
						mes("Please try a moment later.");
						instance_destroy(.@instance);
						close();
					}
					instance_set_timeout(3600, 300, .@instance);
					instance_init(.@instance);
				}
				mes("[Guard]");
				mesf("I will open up the tunnel to ^0000ff%s^000000.", .@md_name$);
				mes("I wish you good luck.");
				close();
			case 3:
				mes("[Guard]");
				mes("This place is dangerous. You cannot enter.");
				close();
			}
		}
	} else {
		mes("[Guard]");
		mes("Let me talk with the party leader.");
		mes("Please call forth the leader.");
		close();
	}
}

ma_fild02,315,323,0	script	Cave Entrance#buwaya	WARPNPC,2,2,{
	end;
OnTouch:
	if (BaseLevel < 130) {
		mes("[Guard]");
		mes("People under ^ff0000level 130^000000");
		mes("cannot enter this place.");
		mes("This place is dangerous. Please go back.");
		close();
	}
	.@playtime = questprogress(4229, PLAYTIME);
	if (!.@playtime) {
		// fall through
	} else if (.@playtime == 1) {
		mes("[Guard]");
		mes("Buwaya is still hiding.");
		mes("Even if you enter now, Buwaya will not come out.");
		mes("Please come back later.");
		close();
	} else {
		erasequest(4229);
		// fall through
	}
	switch (select("Enter.", "Turn back.")) {
	case 1:
		if (has_instance("1@ma_c") == "") {
			mes("The memorial dungeon Buwaya Cave does not exist.");
			mes("The party leader did not generate the dungeon yet.");
			close();
		} else {
			mapannounce("ma_fild02", sprintf(_$("%s party's %s member began hunting Buwaya in Buwaya Cave."), getpartyname(getcharid(CHAR_ID_PARTY)), strcharinfo(PC_NAME)), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
			setquest(4229);
			warp("1@ma_c", 35, 57);
			end;
		}
	case 2:
		mes("[Guard]");
		mes("You must value your life.");
		mes("It is better to think carefully before you act.");
		close();
	}
}

1@ma_c,33,112,0	script	#damage	HIDDEN_WARP_NPC,7,7,{
	end;
OnInstanceInit:
	initnpctimer();
	disablenpc(instance_npcname("#damage"));
	end;
OnTimer1000:
	enablenpc(instance_npcname("#damage"));
	specialeffect(EF_POISONHIT);
	end;
OnTimer2000:
	stopnpctimer();
	initnpctimer();
	disablenpc(instance_npcname("#damage"));
	end;
OnTouch:
	percentheal(-10, -10);
	sc_start(SC_BLOODING, 60000, 0);
	sc_start(SC_POISON, 60000, 0);
	end;
}

1@ma_c,29,110,5	script	Kidnapped People#1	4_F_BARYO_OLD,{
	mes("[Kidnapped Residents]");
	mes("Buwaya was running around,");
	mes("and new people got caught.");
	mes("We will be stuck in here for the rest of our lives.");
	next();
	switch (select("Get me outta here!!", "Ca...can't escape?")) {
	case 1:
		mes("[Kidnapped Residents]");
		mes("We don't have enough power to destroy it but Buwaya has a weakness.");
		mes("Look at the wall over there.");
		mes("If you knock there, Buywaya will feel pain and spit you out.");
		donpcevent(instance_npcname("#box_mob_call")+"::OnEnable");
		close2();
		disablenpc(instance_npcname("Kidnapped People#1"));
		end;
	case 2:
		mes("[Kidnapped People]");
		mes("Somthing is wrong here...");
		mes("Have you experienced this before?");
		close();
	}
	end;
OnInstanceInit:
	disablenpc(instance_npcname("Kidnapped People#1"));
	end;
OnEnable:
	enablenpc(instance_npcname("Kidnapped People#1"));
	donpcevent(instance_npcname("#box_mob_call")+"::OnDisable");
	end;
}

1@ma_c,36,110,5	script	Kidnapped People#2	4_M_BARYO_OLD,{
	mes("[Kidnapped Residents]");
	mes("Ahaa! I wish I had a little more power...");
	mes("I know its weakness...");
	next();
	switch (select("Tell me.", "Do you really know?")) {
	case 1:
		mes("[Kidnapped Residents]");
		mes("Are you sure you can do it...?");
		mes("Ok, listen carefully,");
		mes("its weakness is...");
		next();
		mes("[Kidnapped Residents]");
		mes("...behind us on the walls.");
		sc_start(SC_ATKPOTION, 60000, 45);
		sc_start(SC_MATKPOTION, 60000, 45);
		disablenpc(instance_npcname("Kidnapped People#2"));
		close();
	case 2:
		mes("[Kidnapped Residents]");
		mes("WHAT?!");
		mes("Are you ignoring me");
		mes("because I'm captured in here?");
		close();
	}
	end;
OnInstanceInit:
	disablenpc(instance_npcname("Kidnapped People#2"));
	end;
OnEnable:
	enablenpc(instance_npcname("Kidnapped People#2"));
	end;
}

1@ma_c,3,3,0	script	#box_mob_call	HIDDEN_WARP_NPC,1,1,{
	end;
OnInstanceInit:
	setcell(instance_mapname("1@ma_c"), 30, 118, 35, 118, cell_shootable, 1); //custom
	disablenpc(instance_npcname("#box_mob_call"));
	end;
OnEnable:
	enablenpc(instance_npcname("#box_mob_call"));
	.@label$ = instance_npcname("#box_mob_call")+"::OnMyMobDead";
	.@map$ = instance_mapname("1@ma_c");
	monster(.@map$, 30, 118, _("Buwaya's Weakness"), BUWAYA_WEAK, 1, .@label$);
	monster(.@map$, 35, 118, _("Buwaya's Weakness"), BUWAYA_WEAK, 1, .@label$);
	end;
OnDisable:
	killmonster(instance_mapname("1@ma_c"), instance_npcname("#box_mob_call")+"::OnMyMobDead");
	disablenpc(instance_npcname("#box_mob_call"));
	end;
OnMyMobDead:
	if (mobcount(instance_mapname("1@ma_c"), instance_npcname("#box_mob_call")+"::OnMyMobDead") < 1)
		donpcevent(instance_npcname("#box_out")+"::OnEnable");
	end;
}

1@ma_c,38,118,0	script	#box_out	WARPNPC,2,2,{
OnInstanceInit:
OnDisable:
	disablenpc(instance_npcname("#box_out"));
	end;
OnEnable:
	enablenpc(instance_npcname("#box_out"));
	end;
OnTouch:
	.@x = rand(1, 20) + 97;
	.@y = rand(1, 20) + 74;
	warp(instance_mapname("1@ma_c"), .@x, .@y);
	end;
}

1@ma_c,97,74,0	script	#box_call	HIDDEN_WARP_NPC,50,50,{
	end;
OnInstanceInit:
	disablenpc(instance_npcname("#box_call"));
	initnpctimer();
	end;
OnTimer30000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : I will put you in my treasure box!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	// Should execute OnTimer33000, but client doesn't render the effect fast enough.
	for(.@i = 1; .@i <= 9; ++.@i)
		donpcevent(instance_npcname("#yunobi"+.@i)+"::OnEnable");
	end;
OnTimer33000:
	donpcevent(instance_npcname("#box_out")+"::OnDisable");
	donpcevent(instance_npcname("#box_mob_call")+"::OnDisable");
	donpcevent(instance_npcname("Kidnapped People#1")+"::OnEnable");
	donpcevent(instance_npcname("Kidnapped People#2")+"::OnEnable");
	end;
OnTimer34000:
	enablenpc(instance_npcname("#box_call"));
	end;
OnTimer35000:
	stopnpctimer();
	initnpctimer();
	disablenpc(instance_npcname("#box_call"));
	end;
OnTouch:
	specialeffect(EF_GUIDEDATTACK, AREA, playerattached());
	warp(instance_mapname("1@ma_c"), 33, 112);
	end;
OnDisable:
	stopnpctimer();
	disablenpc(instance_npcname("#box_call"));
	end;
}

1@ma_c,97,74,0	script	#yunobi1	HIDDEN_WARP_NPC,{
	end;
OnInstanceInit:
	hideonnpc(instance_npcname(strnpcinfo(NPC_NAME)));
	end;
OnEnable:
	specialeffect(EF_MAPPILLAR2);
	end;
}
1@ma_c,97,94,0	duplicate(#yunobi1)	#yunobi2	HIDDEN_WARP_NPC
1@ma_c,117,94,0	duplicate(#yunobi1)	#yunobi3	HIDDEN_WARP_NPC
1@ma_c,117,74,0	duplicate(#yunobi1)	#yunobi4	HIDDEN_WARP_NPC
1@ma_c,117,54,0	duplicate(#yunobi1)	#yunobi5	HIDDEN_WARP_NPC
1@ma_c,97,54,0	duplicate(#yunobi1)	#yunobi6	HIDDEN_WARP_NPC
1@ma_c,77,54,0	duplicate(#yunobi1)	#yunobi7	HIDDEN_WARP_NPC
1@ma_c,77,74,0	duplicate(#yunobi1)	#yunobi8	HIDDEN_WARP_NPC
1@ma_c,77,94,0	duplicate(#yunobi1)	#yunobi9	HIDDEN_WARP_NPC

1@ma_c,1,1,0	script	#bunshin	HIDDEN_WARP_NPC,{
	end;
OnInstanceInit:
	initnpctimer();
	end;
OnTimer58000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : I had enough with this, let's go till the end!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	end;
OnTimer61000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : This is!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	end;
OnTimer62000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : This is...MY!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	end;
OnTimer63000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : This is...MY...Deadly!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	end;
OnTimer64000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : This is...MY...Deadly... ATTACK!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	end;
OnTimer65000:
	.@label$ = instance_npcname("#bunshin")+"::OnMyMobDead";
	.@map$ = instance_mapname("1@ma_c");
	areamonster(.@map$, 112, 89, 122, 99, _("Buwaya"), BUWAYA_GHOST, 1, .@label$);
	areamonster(.@map$, 112, 49, 122, 59, _("Buwaya"), BUWAYA_GHOST, 1, .@label$);
	areamonster(.@map$, 72, 49, 82, 59, _("Buwaya"), BUWAYA_GHOST, 1, .@label$);
	areamonster(.@map$, 72, 89, 82, 99, _("Buwaya"), BUWAYA_GHOST, 1, .@label$);
	end;
OnTimer66000:
	mapannounce(instance_mapname("1@ma_c"), _("Buwaya : Are you scared?"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	end;
OnTimer105000:
	killmonster(instance_mapname("1@ma_c"), instance_npcname("#bunshin")+"::OnMyMobDead");
	stopnpctimer();
	initnpctimer();
	end;
OnMyMobDead:
	if (mobcount(instance_mapname("1@ma_c"), instance_npcname("#bunshin")+"::OnMyMobDead") < 1) {
		stopnpctimer();
		initnpctimer();
	}
	end;
OnDisable:
	stopnpctimer();
	killmonster(instance_mapname("1@ma_c"), instance_npcname("#bunshin")+"::OnMyMobDead");
	disablenpc(instance_npcname("#bunshin"));
	end;
}

1@ma_c,2,2,0	script	#buwaya_con	HIDDEN_WARP_NPC,{
	end;
OnInstanceInit:
	areamonster(instance_mapname("1@ma_c"), 90, 67, 104, 81, _("Buwaya"), BUWAYA, 1, instance_npcname("#buwaya_con")+"::OnMyMobDead");
	end;
OnMyMobDead:
	.@map$ = instance_mapname("1@ma_c");
	if (mobcount(.@map$, instance_npcname("#buwaya_con")+"::OnMyMobDead") < 1) {
		donpcevent(instance_npcname("#box_call")+"::OnDisable");
		donpcevent(instance_npcname("#bunshin")+"::OnDisable");
		donpcevent(instance_npcname("#exit_mob")+"::OnDisable");
		donpcevent(instance_npcname("#cave_out")+"::OnEnable");
		mapannounce(.@map$, _("Guard : You did great work. Please hurry up and escape to the way you came in!"), bc_map, C_SPRINGGREEN); //FW_NORMAL 12 0 0
	}
	end;
}

1@ma_c,3,3,0	script	#exit_mob	HIDDEN_WARP_NPC,{
	end;
OnInstanceInit:
	initnpctimer();
	end;
OnTimer60000:
	.@label$ = instance_npcname("#exit_mob")+"::OnMyMobDead";
	.@map$ = instance_mapname("1@ma_c");
	if (mobcount(.@map$, .@label$) < 30)
		.@amount = 10;
	else
		.@amount = 1;
	areamonster(.@map$, 43, 58, 47, 60, _("Water Plant"), MA_SEAW, .@amount, .@label$);
	areamonster(.@map$, 43, 58, 47, 60, _("Egg"), BUWAYA_EGG, .@amount, .@label$);
	stopnpctimer();
	initnpctimer();
	end;
OnDisable:
	stopnpctimer();
	killmonster(instance_mapname("1@ma_c"), instance_npcname("#exit_mob")+"::OnMyMobDead");
	disablenpc(instance_npcname("#exit_mob"));
	end;
OnMyMobDead:
	end;
}

1@ma_c,28,57,0	script	#cave_out	WARPNPC,2,2,{
OnInstanceInit:
	disablenpc(instance_npcname("#cave_out"));
	end;
OnEnable:
	enablenpc(instance_npcname("#cave_out"));
	end;
OnTouch:
	mes("Would like to go out?");
	next();
	if (select("Yes!", "No, I will stay.") == 1)
		warp("ma_fild02", 315, 315);
	close();
}

1@ma_c,1,1,0	script	#buwaya_spawn_mobs	FAKE_NPC,{
OnInstanceInit:
	.@map$ = instance_mapname("1@ma_c");
	areamonster(.@map$, 73, 81, 93, 101, _("Seaweed"), MA_SEAW, 18);
	areamonster(.@map$, 110, 97, 116, 103, _("Seaweed"), MA_SEAW, 8);
	areamonster(.@map$, 59, 63, 63, 67, _("Seaweed"), MA_SEAW, 8);
	areamonster(.@map$, 73, 55, 77, 59, _("Seaweed"), MA_SEAW, 4);
	areamonster(.@map$, 103, 69, 107, 73, _("Seaweed"), MA_SEAW, 4);
	areamonster(.@map$, 108, 45, 122, 63, _("Seaweed"), MA_SEAW, 15);
	areamonster(.@map$, 73, 81, 93, 101, _("Buwaya's Egg"), BUWAYA_EGG, 10);
	areamonster(.@map$, 110, 97, 116, 103, _("Buwaya's Egg"), BUWAYA_EGG, 8);
	areamonster(.@map$, 59, 63, 63, 67, _("Buwaya's Egg"), BUWAYA_EGG, 4);
	areamonster(.@map$, 73, 55, 77, 59, _("Buwaya's Egg"), BUWAYA_EGG, 3);
	areamonster(.@map$, 103, 69, 107, 73, _("Buwaya's Egg"), BUWAYA_EGG, 3);
	areamonster(.@map$, 108, 45, 122, 63, _("Buwaya's Egg"), BUWAYA_EGG, 15);
	monster(.@map$, 0, 0, _("Seaweed"), MA_SEAW, 5);
	monster(.@map$, 0, 0, _("Buwaya's Slave"), BUWAYA_SLAVE, 5);
	end;
}
