#include "hench_i0_ai"

void main()
{
    object oCaster = GetLastSpellCaster();
    object oTarget = OBJECT_SELF;
    int nHP = GetMaxHitPoints(oTarget);
    int nHD = GetHitDice(oCaster);
    float fXP = ((15.0+(2.0*nHP))/nHD);
    int nXP = FloatToInt(fXP);

    if(GetLastSpell() == SPELL_REMOVE_DISEASE)
     {
     ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDeath(), OBJECT_SELF);
     GiveXPToCreature(oCaster, nXP);
     }

    if(GetLastSpell() == SPELLABILITY_REMOVE_DISEASE)
     {
     ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDeath(), OBJECT_SELF);
     GiveXPToCreature(oCaster, nXP);
     }

    if(GetLastSpell() == FEAT_REMOVE_DISEASE)
     {
     ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDeath(), OBJECT_SELF);
     GiveXPToCreature(oCaster, nXP);
     }

    if(GetLastSpellHarmful())
    {
// Auldar: If someone targetted us with a spell, we've been spotted. Stop hiding.
        if (GetStealthMode(OBJECT_SELF) == STEALTH_MODE_ACTIVATED)
        {
            ActionUseSkill(SKILL_HIDE, OBJECT_SELF);
        }
        if(!GetIsFighting(OBJECT_SELF))
        {
            if(GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL))
            {
                HenchDetermineSpecialBehavior(oCaster);
            }
            else
            {
                HenchDetermineCombatRound(oCaster);
            }
        }
    }
    if(GetSpawnInCondition(NW_FLAG_SPELL_CAST_AT_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_SPELL_CAST_AT));
    }
}
