class 1 warrior_casting_3skill_magical : warrior
{
parameter:
	int	SleepMagic = 1035777;
	int	DDMagic = 1024257;
	int	CancelMagic = 1048065;
	int	CheckMagic = 0;
	int	CheckMagic1 = 0;
	int	CheckMagic2 = 0;

handler:
	EventHandler CREATED()
	{
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		super;
	}

	EventHandler ATTACKED(attacker,damage,i6)
	{
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			if( myself::IsNullCreature(myself.top_desire_target) == 1 )
			{
			}
			else if( myself.top_desire_target != attacker )
			{
				i6 = gg::Rand(100);
				if( myself.i_ai0 == 0 )
				{
					myself.i_ai0 = 1;
				}
				else if( myself.i_ai0 == 1 && i6 < 30 && myself.sm.hp > ( myself.sm.max_hp / 10.000000 ) )
				{
					if( myself::Skill_GetConsumeMP(SleepMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(SleepMagic) < myself.sm.hp && myself::Skill_InReuseDelay(SleepMagic) == 0 )
					{
						myself::AddUseSkillDesire(attacker,SleepMagic,0,1,1000000);
					}
				}
			}
			else if( myself::DistFromMe(attacker) > 100 )
			{
				i6 = gg::Rand(100);
				if( myself.top_desire_target == attacker && i6 < 33 )
				{
					if( myself::Skill_GetConsumeMP(DDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(DDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(DDMagic) == 0 )
					{
						myself::AddUseSkillDesire(attacker,DDMagic,0,1,1000000);
					}
				}
			}
			else if( gg::Rand(200) < 1 && myself.i_ai1 == 0 && myself.sm.hp > ( myself.sm.max_hp * 0.600000 ) )
			{
				if( ( CheckMagic == 0 || myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(CheckMagic)) <= 0 ) && ( ( CheckMagic1 == 0 || myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(CheckMagic1)) <= 0 ) && ( CheckMagic2 == 0 || myself::GetAbnormalLevel(attacker,myself::Skill_GetAbnormalType(CheckMagic2)) <= 0 ) ) )
				{
					if( myself::Skill_GetConsumeMP(CancelMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(CancelMagic) < myself.sm.hp && myself::Skill_InReuseDelay(CancelMagic) == 0 )
					{
						myself::AddUseSkillDesire(attacker,CancelMagic,0,1,1000000);
					}
					myself.i_ai1 = 1;
				}
			}
		}
		super;
	}

	EventHandler CLAN_ATTACKED(attacker,damage,i6)
	{
		if( ( myself::GetLifeTime() > 7 && ( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) ) ) && myself.p_state != 3 )
		{
			i6 = gg::Rand(100);
			if( myself::DistFromMe(attacker) > 100 && i6 < 33 )
			{
				if( myself::Skill_GetConsumeMP(DDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(DDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(DDMagic) == 0 )
				{
					myself::AddUseSkillDesire(attacker,DDMagic,0,1,1000000);
				}
			}
		}
		super;
	}

}
