class 1 ai_sailren : default_npc
{
parameter:
	float	Attack_DecayRatio = 6.600000;
	float	UseSkill_DecayRatio = 66000.000000;
	float	Attack_BoostValue = 300.000000;
	float	UseSkill_BoostValue = 100000.000000;
	int	GM_ID = 0;
	string	RaidSpawnMusic = "Rm01_A";

handler:
	EventHandler NO_DESIRE()
	{
		if( myself.sm.db_value == 3 )
		{
			myself::AddMoveAroundDesire(5,5);
		}
		else if( myself.sm.db_value == 0 )
		{
			myself::RemoveAllDesire();
		}
	}

	EventHandler CREATED(reply,i0)
	{
		if( reply == 0 )
		{
			myself::SetDBValue(myself.sm,0);
			myself::EarthQuakeByNPC(myself.sm,20,10,1,0,0,0);
		}
		myself.i_ai1 = myself::GetTick();
		if( GM_ID != 0 )
		{
			i0 = myself::GetGlobalMap(GM_ID);
			if( i0 == -1 )
			{
				myself::RegisterGlobalMap(GM_ID,myself::GetIndexFromCreature(myself.sm));
			}
		}
		if( myself.sm.db_value == 1 )
		{
			myself::AddTimerEx(1001,( ( 10 * 60 ) * 1000 ));
		}
		else if( myself.sm.db_value == 2 )
		{
			myself::InstantTeleport(myself.sm,27328,-6624,-1976);
			myself::EffectMusic(myself.sm,10000,"BS02_A");
		}
		else if( myself.sm.db_value == 3 )
		{
			myself::AddTimerEx(1002,( ( 1 * 60 ) * 1000 ));
			myself::AddTimerEx(1003,10800);
			myself.i_ai1 = myself::GetTick();
			myself::AddMoveAroundDesire(5,5);
		}
	}

	EventHandler SCRIPT_EVENT(script_event_arg1,script_event_arg2)
	{
		if( myself.sm.db_value == 0 )
		{
			myself::AddTimerEx(1001,( ( 10 * 1 ) * 1000 ));
			myself::SetDBValue(myself.sm,1);
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id)
	{
		if( timer_id == 1001 )
		{
			myself::SetDBValue(myself.sm,2);
			myself::InstantTeleport(myself.sm,27328,-6624,-1976);
			myself::EffectMusic(myself.sm,10000,"BS02_A");
			myself::AddTimerEx(1203,10000);
		}
		else if( timer_id == 1203 )
		{
			myself::SetDBValue(myself.sm,3);
			myself::AddEffectActionDesire(myself.sm,1,8000,10000000);
			myself::AddEffectActionDesire(myself.sm,2,6000,5000000);
			myself::AddTimerEx(1002,( ( 1 * 60 ) * 1000 ));
			myself::AddTimerEx(1003,10800);
			myself.i_ai1 = myself::GetTick();
		}
		else if( timer_id == 1002 )
		{
			if( ( myself::GetTick() - myself.i_ai1 ) > ( ( 15 * 60 ) * 1000 ) )
			{
				myself::SetDBValue(myself.sm,0);
				myself::RemoveAllDesire();
				myself::StopMove();
				myself::InstantTeleportInMyTerritory(80464,152294,-3534,100);
				myself::InstantTeleport(myself.sm,-107370,-251547,-15536);
				myself.i_ai2 = 0;
			}
			else
			{
				myself::AddTimerEx(1002,( ( 1 * 60 ) * 1000 ));
			}
		}
	}

	EventHandler ATTACKED(attacker,damage)
	{
		myself.i_ai1 = myself::GetTick();
		if( attacker.yongma_type == 1 && myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(1090049)) <= 0 )
		{
			if( myself::Skill_GetConsumeMP(1090049) < myself.sm.mp && myself::Skill_GetConsumeHP(1090049) < myself.sm.hp && myself::Skill_InReuseDelay(1090049) == 0 )
			{
				myself::AddUseSkillDesire(attacker,1090049,0,1,1000000);
			}
		}
		if( myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(1155841)) > 0 )
		{
			myself::AddUseSkillDesire(attacker,1109505,0,1,1000000);
		}
		if( attacker.level > ( myself.sm.level + 8 ) && myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(1155841)) < 99 )
		{
			myself::AddUseSkillDesire(attacker,1155841,0,1,1000000);
			myself::RemoveAttackDesire(attacker.id);
		}
		if( attacker.level <= ( myself.sm.level + 8 ) )
		{
			if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
			{
				if( damage == 0 )
				{
					damage = 1;
				}
				myself::AddAttackDesire(attacker,1,( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) * 20000 ));
			}
		}
	}

	EventHandler SEE_SPELL(speller,skill_name_id)
	{
		if( speller.level > ( myself.sm.level + 8 ) && myself::GetAbnormalLevel(speller,myself::Skill_GetAbnormalType(1079041)) == -1 )
		{
			myself::AddUseSkillDesire(speller,1079041,0,1,1000000);
			return;
		}
	}

	EventHandler MY_DYING()
	{
		myself::EffectMusic(myself.sm,10000,"BS01_D");
		myself::SetDBValue(myself.sm,0);
		myself::UnregisterGlobalMap(GM_ID);
	}

}
