@LabelIndex 55577
@StringIndex 0
class 0 party_leader_heretic2 : party_leader_physicalspecial2 {
parameter:
	int	SpecialAttack = 0;
	int	SelfMagicHeal = 458752001;
	int	HelpCastRange = 500;
	int	DistNoDesire = 500;

handler:
	EventHandler CREATED() {
		myself.i_ai3 = 0;
		super;
		myself::AddMoveToDesire(myself.start_x,myself.start_y,myself.start_z,30);
	}

	EventHandler NO_DESIRE() {
		myself::AddMoveToDesire(myself.start_x,myself.start_y,myself.start_z,30);
	}

	EventHandler SEE_CREATURE(creature,i0,f0) {
		if( creature.is_pc == 0 && myself::IsInCategory(12,creature.class_id) == 0 ) {
			if( creature != myself.sm ) {
				if( myself::Skill_GetConsumeMP(SpecialAttack) < myself.sm.mp && myself::Skill_GetConsumeHP(SpecialAttack) < myself.sm.hp && myself::Skill_InReuseDelay(SpecialAttack) == 0 ) {
					myself::AddUseSkillDesire(creature,SpecialAttack,0,1,1000000);
				}
				if( myself::Skill_GetConsumeMP(SelfMagicHeal) < myself.sm.mp && myself::Skill_GetConsumeHP(SelfMagicHeal) < myself.sm.hp && myself::Skill_InReuseDelay(SelfMagicHeal) == 0 ) {
					myself::AddUseSkillDesire(myself.sm,SelfMagicHeal,1,1,1000000);
				}
			}
			return;
		}
		super;
	}

	EventHandler ATTACKED(attacker) {
		if( myself.p_state != 3 && myself.p_state != 10 ) {
			myself::BroadcastScriptEventEx(10033,gg::GetIndexFromCreature(attacker),gg::GetIndexFromCreature(myself.sm),HelpCastRange);
		}
		if( myself.sm.hp < ( myself.sm.max_hp * 0.400000 ) && gg::Rand(100) < 33 ) {
			if( gg::Rand(100) < 33 && ( attacker.occupation == 5 || attacker.occupation == 90 || myself::IsInCategory(3,attacker.occupation) ) ) {
				myself::BroadcastScriptEventEx(10002,gg::GetIndexFromCreature(attacker),gg::GetIndexFromCreature(myself.sm),HelpCastRange);
			}
		}
		super;
	}

	EventHandler PARTY_ATTACKED(attacker,private,damage,f0,i0) {
		if( myself.sm.hp < ( myself.sm.max_hp * 0.400000 ) && gg::Rand(100) < 33 ) {
			if( myself.i_ai3 == 0 ) {
				myself::LookNeighbor(300);
			}
		}
		super;
	}

	EventHandler USE_SKILL_FINISHED(target,skill_name_id,success) {
		if( skill_name_id == SelfMagicHeal && success == 1 ) {
			myself.i_ai3 = 1;
		}
	}

	EventHandler SEE_SPELL(speller,skill_name_id,target,f0,i0) {
		if( speller.is_pc != 0 && myself::IsInCategory(12,speller.class_id) == 0 ) {
			if( myself.sm.hp < ( myself.sm.max_hp * 0.400000 ) && gg::Rand(100) < 33 ) {
				if( myself::IsInCategory(3,speller.occupation) ) {
					myself::BroadcastScriptEventEx(10002,gg::GetIndexFromCreature(speller),gg::GetIndexFromCreature(myself.sm),HelpCastRange);
				}
			}
		}
		super;
	}

	EventHandler OUT_OF_TERRITORY() {
		myself::RemoveAllAttackDesire();
		myself::AddMoveToDesire(myself.start_x,myself.start_y,myself.start_z,100);
		myself::BroadcastScriptEventEx(10035,0,gg::GetIndexFromCreature(myself.sm),DistNoDesire);
	}

}
