@LabelIndex 136563
@StringIndex 17508
class 0 ai_castle_pailaka_npc : warrior {
parameter:
	int	Buff = 458752001;
	int	Skill01_ID = 458752001;
	int	Skill02_ID = 458752001;
	int	Skill01_Prob = 20;
	int	Skill02_Prob = 20;
	int	String_Num1 = -1;
	int	String_Num2 = -1;
	int	String_Num3 = -1;
	int	String_Num4 = -1;
	int	String_Num5 = -1;
	int	String_Num6 = -1;
	string	fnHi = "";
	string	fnNowInBattle = "";
	string	fnMissionSuccess = "";

handler:
	EventHandler CREATED() {
		if( String_Num1 > 0 ) {
			myself::Say(gg::MakeFString(String_Num1,"","","","",""));
		}
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		myself.i_ai2 = 0;
		myself.i_ai3 = gg::FloatToInt(myself.sm.max_hp);
		myself.i_ai4 = 0;
		myself.i_quest0 = 0;
		myself::AddTimerEx(1230,( 1 * 1000 ));
		myself::AddTimerEx(5617,( ( 2 * 60 ) * 1000 ));
		myself::AddTimerEx(5620,( 5 * 1000 ));
		super;
	}

	EventHandler TALKED(talker) {
		if( myself.i_quest0 == 0 ) {
			myself::ShowPage(talker,fnHi);
		} else if( myself.i_quest0 == 1 ) {
			myself::ShowPage(talker,fnNowInBattle);
		} else if( myself.i_quest0 == 2 ) {
			myself::ShowPage(talker,fnMissionSuccess);
		} else {
		}
	}

	EventHandler MENU_SELECTED(talker,ask,reply) {
		if( ask == 23000 && reply == 1 ) {
			myself::InstantZone_Leave(talker);
		}
	}

	EventHandler ATTACKED() {
		if( myself.i_ai2 == 0 ) {
			myself.i_ai2 = 1;
			myself.i_quest0 = 1;
		}
		if( myself.i_ai4 != 1 ) {
			if( myself.i_ai3 == gg::FloatToInt(myself.sm.max_hp) ) {
				if( myself.sm.hp < ( myself.sm.max_hp * 0.400000 ) ) {
					myself.i_ai3 = gg::FloatToInt(myself.sm.hp);
					if( String_Num3 > 0 ) {
						myself::Say(gg::MakeFString(String_Num3,"","","","",""));
					}
				}
			} else if( myself.sm.hp < ( myself.sm.max_hp * 0.100000 ) ) {
				if( myself.i_ai3 > gg::FloatToInt(( myself.sm.max_hp * 0.100000 )) ) {
					myself.i_ai3 = gg::FloatToInt(myself.sm.hp);
					if( String_Num4 > 0 ) {
						myself::Say(gg::MakeFString(String_Num4,"","","","",""));
					}
				}
			}
		}
	}

	EventHandler CLAN_ATTACKED(attacker,damage) {
		if( myself.i_ai2 == 0 ) {
			myself.i_ai2 = 1;
			myself.i_quest0 = 1;
		}
	}

	EventHandler SEE_CREATURE(creature,party0,c0) {
		if( myself.i_ai0 == 0 ) {
			if( creature.is_pc == 1 ) {
				party0 = gg::GetParty(creature);
				if( myself::IsNullParty(party0) == 0 ) {
					c0 = myself::GetLeaderOfParty(party0);
					myself.i_ai0 = 1;
					myself.i_ai1 = c0.id;
				} else {
					myself.i_ai0 = 1;
					myself.i_ai1 = creature.id;
				}
			} else {
			}
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id,c0,c1,party0,i0,i1) {
		if( timer_id == 1230 ) {
			if( myself.i_ai0 == 0 ) {
				myself::AddTimerEx(1230,( 3 * 1000 ));
			}
		}
		if( timer_id == 5617 ) {
			if( myself.i_ai1 != 0 ) {
				c1 = gg::GetCreatureFromID(myself.i_ai1);
				if( myself::IsNullCreature(c1) == 0 ) {
					party0 = gg::GetParty(c1);
					if( myself::IsNullParty(party0) == 0 ) {
						i0 = party0.member_count;
						for(i1 = 0; i1 < i0; i1++) {
							c0 = myself::GetMemberOfParty(party0,i1);
							if( myself::DistFromMe(c0) <= 75 ) {
								myself::CastBuffForQuestReward(c0,Buff);
							}
						}
					} else if( myself::IsNullCreature(c1) == 0 ) {
						if( myself::DistFromMe(c1) <= 75 ) {
							myself::CastBuffForQuestReward(c1,Buff);
						}
					}
				}
			}
			myself::AddTimerEx(5617,( ( 2 * 60 ) * 1000 ));
		} else if( timer_id == 5620 ) {
			myself::BroadcastScriptEvent(2117001,gg::GetIndexFromCreature(myself.sm),1500);
			myself::AddTimerEx(5620,( 10 * 1000 ));
		} else if( timer_id == 5634 ) {
			myself::Suicide();
		}
	}

	EventHandler SCRIPT_EVENT(script_event_arg1,script_event_arg2,c0) {
		if( script_event_arg1 == 2117009 || script_event_arg1 == 2117007 ) {
			myself.i_quest0 = 2;
			if( String_Num6 > 0 ) {
				myself::Shout(gg::MakeFString(String_Num6,"","","","",""));
			}
		}
	}

	EventHandler CLAN_DIED(victim,i0) {
		if( myself.i_ai4 == 0 ) {
			myself::AddTimerEx(5634,1500);
			myself.i_ai4 = 1;
		}
	}

	EventHandler MY_DYING(i0,i1,c0,c1,maker0,reply) {
		if( myself.sm.hp < 1 ) {
			myself::InstantZone_Finish(5);
		}
		if( String_Num5 > 0 ) {
			myself::Say(gg::MakeFString(String_Num5,"","","","",""));
		}
		myself.i_quest0 = 99;
	}

}
