@LabelIndex 110350
@StringIndex 0
class 0 c_tower_combat_manager : default_npc {
parameter:
	string	fnHi = "c_tower_switch.htm";
	string	DoorName1 = "door_en";
	string	DoorName2 = "door_ex";
	string	MonsterMakerName = "c_tower_monster_set";
	string	TrapMakerName = "c_tower_trap_lurker";
	string	NaiaGateMakerName = "gludio59_1825_top01m1";
	string	BeforeMaker = "unguya~";
	int	ControlMessage = 10001;
	int	CheckMessage = 10101;
	int	RoomNumber = 0;
	int	IsTrapRoom = 0;
	int	LimitTime = 300000;

handler:
	EventHandler CREATED() {
		myself.i_ai1 = 0;
		myself.i_ai2 = 0;
		myself.i_quest0 = 0;
		myself.i_quest1 = 0;
		gg::Castle_GateOpenClose2(DoorName1,0);
		gg::Castle_GateOpenClose2(DoorName2,1);
		super;
	}

	EventHandler TALKED(talker,party0) {
		party0 = gg::GetParty(talker);
		if( myself.i_ai1 == 1 ) {
			return;
		} else if( gg::IsNull(party0) == 1 ) {
			myself::ShowSystemMessage(talker,2291);
			return;
		} else {
			myself::ShowPage(talker,fnHi);
		}
	}

	EventHandler MENU_SELECTED(talker,ask,reply,maker0,maker1,i0,party0) {
		if( reply == 1 ) {
			party0 = gg::GetParty(talker);
			if( gg::IsNull(party0) == 0 ) {
				myself.i_quest0 = party0.id;
			} else {
				myself::ShowSystemMessage(talker,2291);
				return;
			}
			myself::InstantTeleportInMyTerritoryWithCondition(16110,243841,11616,200,2,myself.i_quest0);
			if( RoomNumber == 0 ) {
				gg::Castle_GateOpenClose2(DoorName1,1);
			} else {
				gg::Castle_GateOpenClose2(DoorName1,1);
				maker1 = gg::GetNpcMaker(BeforeMaker);
				if( gg::IsNull(maker1) == 0 ) {
					gg::SendMakerScriptEvent(maker1,88013,0,0);
				}
			}
			maker0 = gg::GetNpcMaker(MonsterMakerName);
			i0 = gg::GetIndexFromCreature(myself.sm);
			if( gg::IsNull(maker0) == 0 ) {
				gg::SendMakerScriptEvent(maker0,88008,i0,0);
			}
			myself.i_ai1 = 1;
			myself.i_ai2 = 1;
			myself::AddLogByNpc(122,talker,1,0);
			myself::AddTimerEx(1005,LimitTime);
			if( IsTrapRoom == 1 ) {
				maker1 = gg::GetNpcMaker(TrapMakerName);
				if( gg::IsNull(maker1) == 0 ) {
				}
				gg::SendMakerScriptEvent(maker1,1001,0,0);
			}
		}
	}

	EventHandler SCRIPT_EVENT(script_event_arg1,c0,maker0,maker1,timer_id) {
		if( script_event_arg1 == 88009 ) {
			myself.i_quest1 = -1;
			gg::Castle_GateOpenClose2(DoorName2,0);
			myself.i_ai2 = 0;
			if( RoomNumber == 2 ) {
				myself::AddTimerEx(1004,30000);
			}
			if( IsTrapRoom == 1 ) {
				maker0 = gg::GetNpcMaker(TrapMakerName);
				if( gg::IsNull(maker0) == 0 ) {
					gg::SendMakerScriptEvent(maker0,1000,0,0);
				}
			} else if( RoomNumber == 3 ) {
				maker1 = gg::GetNpcMaker(NaiaGateMakerName);
				if( gg::IsNull(maker1) == 0 ) {
					gg::SendMakerScriptEvent(maker1,33033,0,0);
				}
			}
			myself::AddTimerEx(9999,( LimitTime * 6 ));
		} else if( script_event_arg1 == 88013 ) {
			myself.i_ai1 = 0;
			gg::Castle_GateOpenClose2(DoorName1,0);
			gg::Castle_GateOpenClose2(DoorName2,1);
		} else if( script_event_arg1 == 10101 || script_event_arg1 == 10001 ) {
			return;
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id,maker0,maker1) {
		if( timer_id == 1005 ) {
			if( myself.i_ai2 == 1 ) {
				if( myself.i_quest1 == -1 ) {
					myself.i_quest1 = 0;
					return;
				} else if( myself.i_quest1 == 0 ) {
					myself::InstantTeleportInMyTerritory(16110,243841,11616,200);
					myself.i_ai1 = 0;
					myself.i_ai2 = 0;
					myself.i_quest0 = 0;
					myself.i_quest1 = 0;
					gg::Castle_GateOpenClose2(DoorName1,0);
					maker0 = gg::GetNpcMaker(MonsterMakerName);
					if( gg::IsNull(maker0) == 0 ) {
						gg::SendMakerScriptEvent(maker0,1000,0,0);
					}
					if( IsTrapRoom == 1 ) {
						maker1 = gg::GetNpcMaker(TrapMakerName);
						if( gg::IsNull(maker1) == 0 ) {
							gg::SendMakerScriptEvent(maker1,1000,0,0);
						}
					}
				}
			} else if( myself.i_ai2 == 0 ) {
				myself.i_quest1 = 0;
			}
		} else if( timer_id == 1004 ) {
			gg::Castle_GateOpenClose2(DoorName2,1);
			gg::Castle_GateOpenClose2(DoorName1,0);
			myself.i_ai1 = 0;
			myself.i_quest0 = 0;
			myself::InstantTeleportInMyTerritory(-47301,243971,-13376,100);
		} else if( timer_id == 9999 ) {
			if( myself.i_ai1 == 1 && myself.i_ai2 == 0 ) {
				myself::InstantTeleportInMyTerritory(16110,243841,11616,200);
				myself.i_ai1 = 0;
				gg::Castle_GateOpenClose2(DoorName1,0);
				gg::Castle_GateOpenClose2(DoorName2,1);
			}
		}
	}

}
