class 1 warrior_casting_ddmagic : warrior
{
parameter:
	int	DDMagic = 1024257;

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

	EventHandler ATTACKED(attacker,damage,i6)
	{
		if( myself.i_ai1 == 1 )
		{
			if( myself.top_desire_target == attacker )
			{
				myself.i_ai2 = 1;
			}
		}
		else
		{
			myself::AddTimerEx(2001,5000);
			myself.i_ai1 = 1;
		}
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			i6 = gg::Rand(100);
			if( myself::DistFromMe(attacker) > 100 )
			{
				if( myself::IsNullCreature(myself.top_desire_target) == 0 )
				{
					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);
						}
					}
				}
			}
		}
		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;
	}

	EventHandler TIMER_FIRED_EX(timer_id)
	{
		if( timer_id == 2001 )
		{
			if( myself.p_state != 3 && myself.p_state != 10 )
			{
				myself.i_ai1 = 0;
				myself.i_ai2 = 0;
			}
			else if( myself.i_ai2 == 0 )
			{
				if( myself::IsNullCreature(myself.top_desire_target) == 0 && gg::Rand(100) < 50 )
				{
					if( myself::GetAbnormalLevel(myself.top_desire_target,myself::Skill_GetAbnormalType(DDMagic)) <= 0 )
					{
						if( myself::Skill_GetConsumeMP(DDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(DDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(DDMagic) == 0 )
						{
							myself::AddUseSkillDesire(myself.top_desire_target,DDMagic,0,1,1000000);
						}
					}
				}
			}
			myself::AddTimerEx(2001,5000);
			myself.i_ai2 = 0;
		}
		super;
	}

}
