class 1 warrior_casting_selfrangeddmagic_buff : warrior
{
parameter:
	int	SelfRangeDDMagic = 1032449;
	int	Buff = 1031683;

handler:
	EventHandler CREATED()
	{
		if( myself::Skill_GetConsumeMP(Buff) < myself.sm.mp && myself::Skill_GetConsumeHP(Buff) < myself.sm.hp && myself::Skill_InReuseDelay(Buff) == 0 )
		{
			myself::AddUseSkillDesire(myself.sm,Buff,1,1,1000000);
		}
		super;
	}

	EventHandler ATTACKED(attacker,damage)
	{
		if( attacker.is_pc != 0 || myself::IsInCategory(11,attacker.npc_class_id) )
		{
			if( myself.p_state != 3 && myself.p_state != 10 )
			{
				if( myself::GetAbnormalLevel(myself.sm,myself::Skill_GetAbnormalType(Buff)) <= 0 )
				{
					if( myself::Skill_GetConsumeMP(Buff) < myself.sm.mp && myself::Skill_GetConsumeHP(Buff) < myself.sm.hp && myself::Skill_InReuseDelay(Buff) == 0 )
					{
						myself::AddUseSkillDesire(myself.sm,Buff,1,1,1000000);
					}
				}
			}
			if( myself::IsNullCreature(myself.top_desire_target) == 0 )
			{
				if( gg::Rand(100) < 33 && myself.top_desire_target != attacker && myself::DistFromMe(attacker) < 200 )
				{
					if( myself::Skill_GetConsumeMP(SelfRangeDDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(SelfRangeDDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(SelfRangeDDMagic) == 0 )
					{
						myself::AddUseSkillDesire(myself.sm,SelfRangeDDMagic,0,1,1000000);
					}
				}
			}
		}
		super;
	}

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

}
