//::///////////////////////////////////////////////
//:: Default:On Death
//:: NW_C2_DEFAULT7
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Shouts to allies that they have been killed
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Oct 25, 2001
//:: Modified By: Dalantriel Jul 22, 2002
//:://////////////////////////////////////////////
#include "NW_I0_GENERIC"

void main()
{
    int nClass = GetLevelByClass(CLASS_TYPE_COMMONER);
    int nAlign = GetAlignmentGoodEvil(OBJECT_SELF);
    if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
    {
        object oKiller = GetLastKiller();
        AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    }

    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);
    if(GetSpawnInCondition(NW_FLAG_DEATH_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(1007));
    }

// Check if Primary Good NPC is still alive
    object oTrashCan = GetObjectByTag("TrashCan");
    if(!(GetLocalInt(oTrashCan, "nGoodNPCDead") > 0))
    {


        SoundObjectStop(GetObjectByTag("ZombieMoans"));
        DestroyObject(GetObjectByTag("spawnmaster"));


        // And flag the Warlord as being dead
        object oPrimaryNPC = GetObjectByTag("Henrick");
        SetLocalInt(oPrimaryNPC, "nWarlordDead", 1);
    }

    object oToDestroy =GetObjectByTag("Urn_minotaur");
    DestroyObject(oToDestroy);
    oToDestroy =GetObjectByTag("SarcophagusGood_earths");
    DestroyObject(oToDestroy);
    oToDestroy =GetObjectByTag("coffin_earths");
    DestroyObject(oToDestroy);
    oToDestroy =GetObjectByTag("coffin_vampires");
    DestroyObject(oToDestroy);
    oToDestroy =GetObjectByTag("coffin_vampires2");
    DestroyObject(oToDestroy);

    oToDestroy =GetObjectByTag("Earths");
    SetEncounterActive(FALSE, oToDestroy);
    oToDestroy =GetObjectByTag("Minotaurs");
    SetEncounterActive(FALSE, oToDestroy);
    oToDestroy =GetObjectByTag("Vampires");
    SetEncounterActive(FALSE, oToDestroy);

    location loc = GetLocation(OBJECT_SELF);
    ActionCastSpellAtLocation(SPELL_WAIL_OF_THE_BANSHEE , loc, METAMAGIC_ANY, TRUE, PROJECTILE_PATH_TYPE_DEFAULT, TRUE);
    SoundObjectPlay(GetObjectByTag("Boom"));

    object oHostileFaction = GetFirstFactionMember(OBJECT_SELF, FALSE);
    while (GetIsObjectValid(oHostileFaction))
    {
        DestroyObject(oHostileFaction);
        oHostileFaction = GetNextFactionMember(OBJECT_SELF, FALSE);
    }

    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster1")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster1"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster2")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster2"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster3")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster3"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster4")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster4"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster5")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster5"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster6")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster6"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster7")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster7"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster8")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster8"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster9")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster9"));
    }
    if(GetCurrentHitPoints(GetObjectByTag("spawnmaster10")) > 0)
    {
        DestroyObject(GetObjectByTag("spawnmaster10"));
    }

}
