//:://////////////////////////////////////////////////
//:://////////////////////////////////////////////////
//:: NW_C2_DEFAULT7
/*
  Default OnDeath event handler for NPCs.

  Adjusts killer's alignment if appropriate and
  alerts allies to our death.
 */
//:://////////////////////////////////////////////////
//:: Copyright (c) 2002 Floodgate Entertainment
//:: Created By: Naomi Novik
//:: Created On: 12/22/2002
//:://////////////////////////////////////////////////

#include "x2_inc_compon"
#include "x0_i0_spawncond"

void main()
{
    int nClass = GetLevelByClass(CLASS_TYPE_COMMONER);
    int nAlign = GetAlignmentGoodEvil(OBJECT_SELF);
    object oKiller = GetLastKiller();
    // Create appropriate gibs.
        object oGib = CreateObject(OBJECT_TYPE_PLACEABLE, "prop_holder", GetLocation(OBJECT_SELF));
        SetLocalObject(OBJECT_SELF, "gib", oGib);
        //DestroyObject(oGib, 595.0);
// ************************************************************
// Assign blood color according to racial type
// ************************************************************
    string sTag     = GetTag(OBJECT_SELF);
    string sResRef  = GetResRef(OBJECT_SELF);
    object oCorpse  = GetNearestObjectByTag(sTag);
    object oGibs    = GetLocalObject(oCorpse, "gib");
    int iSize       = GetCreatureSize(oCorpse);
    int iRacialType = GetRacialType(oCorpse);
    effect eEffect;
    // Green Blood
    if (iRacialType == RACIAL_TYPE_OOZE ||
        iRacialType == RACIAL_TYPE_ABERRATION ||
        iRacialType == RACIAL_TYPE_UNDEAD ||
        iRacialType == RACIAL_TYPE_DRAGON)
           {
           if (iSize < CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_GREEN_SMALL);
           }
           else if (iSize >= CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_GREEN_MEDIUM);
           }
        if (sResRef == "nw_willowisp") eEffect = EffectVisualEffect(VFX_NONE);
        if (sResRef == "nw_skeleton") eEffect = EffectVisualEffect(VFX_NONE);
        if (sResRef == "nw_skelchief") eEffect = EffectVisualEffect(VFX_NONE);
        if (sResRef == "nw_skelmage") eEffect = EffectVisualEffect(VFX_NONE);
        if (sResRef == "nw_skelpriest") eEffect = EffectVisualEffect(VFX_NONE);
        if (sResRef == "nw_skelwarr01") eEffect = EffectVisualEffect(VFX_NONE);
        if (sResRef == "nw_skelwarr02") eEffect = EffectVisualEffect(VFX_NONE);
    }
    // Yellow blood
    else if (iRacialType == RACIAL_TYPE_VERMIN){
           if (iSize < CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_YELLOW_SMALL);
           }
           else if (iSize == CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_YELLOW_MEDIUM);
           }
    }
    // Debris - Golem?
    else if (iRacialType == RACIAL_TYPE_CONSTRUCT || iRacialType == RACIAL_TYPE_ELEMENTAL){
            eEffect     = EffectVisualEffect(VFX_NONE);
    }
    // Anything else (red)
    else {
           if (iSize < CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_RED_SMALL);
           }
           else if (iSize == CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_RED_MEDIUM);
           }
           else if (iSize > CREATURE_SIZE_MEDIUM){
                eEffect     = EffectVisualEffect(VFX_COM_CHUNK_RED_LARGE);
           }
    }
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eEffect, oGibs);
// ************************************************************
    // If we're a good/neutral commoner,
    // adjust the killer's alignment evil
    if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
    {
        AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    }

    // Call to allies to let them know we're dead
    SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK);

    //Shout Attack my target, only works with the On Spawn In setup
    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);

    // NOTE: the OnDeath user-defined event does not
    // trigger reliably and should probably be removed
    if(GetSpawnInCondition(NW_FLAG_DEATH_EVENT))
    {
         SignalEvent(OBJECT_SELF, EventUserDefined(1007));
    }
    craft_drop_items(oKiller);
ExecuteScript("prc_npc_death", OBJECT_SELF);
ExecuteScript("prc_pwondeath", OBJECT_SELF);
}
