//::///////////////////////////////////////////////
//:: Custom User Defined Event
//:: FileName
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*

*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////

void main()
{
    int nUser = GetUserDefinedEventNumber();

    if(nUser == 1001) //HEARTBEAT
    {

    }
    else if(nUser == 1002) // PERCEIVE
    {
        //if ( GetLocalInt(GetFirstPC(), "nSawHeroOnce") == 0 )
        //{
        //    if (GetLastPerceived() == GetFirstPC())
        //    {
        //        SetLocalInt(GetFirstPC(), "nSawHeroOnce", 1);
        //        //Haspaar appears
        //        CreateObject(OBJECT_TYPE_CREATURE, "Haspaar001", GetLocation(GetFirstPC()));
        //
        //    }
        //}
    }
    else if(nUser == 1003) // END OF COMBAT
    {

    }
    else if(nUser == 1004) // ON DIALOGUE
    {

    }
    else if(nUser == 1005) // ATTACKED
    {


    }
    else if(nUser == 1006) // DAMAGED
    {
        if (GetLocalInt(GetModule(), "bDMPresent") == 0)
        {
            if ( GetLocalInt(GetModule(), "nHeroBeenDamaged") == 0 )
            {
                SetLocalObject(OBJECT_SELF, "oAttacker", GetLastDamager());
                SignalEvent(OBJECT_SELF, EventUserDefined(2000));
            }
        }
    }
    else if(nUser == 1007) // DEATH
    {

        if (GetLocalInt(GetModule(), "bDMPresent") == 0)
        {
            // just in case something manages to kill a hero other than a PC
            // (most likely a pet or familiar)
            if ( GetLocalInt(GetModule(), "nHeroBeenDamaged") == 0 )
            {
                SetLocalObject(OBJECT_SELF, "oAttacker", GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC));
                SignalEvent(OBJECT_SELF, EventUserDefined(2000));
            }

            int nTotal = GetLocalInt(GetModule(), "nTotalGoblinHeroesKilled") + 1;
            SetLocalInt(GetModule(), "nTotalGoblinHeroesKilled", nTotal);
            //SendMessageToPC(GetFirstPC(), "Total goblin heroes killed = " + IntToString(nTotal));
            if (nTotal >= GetLocalInt(GetModule(), "nTotalGoblinHeroes"))
            {
                // DEBUG
                //SendMessageToPC(GetFirstPC(), "All the goblin heroes have been vanquished!");
                SetLocalInt(GetModule(), "nGoblinHeroesExhaustedFlag", 1);
            }
        }
    }
    else if(nUser == 1008) // DISTURBED
    {

    }
    else if(nUser == 2000) // Trigger appearance of Haspaar
    {
        object oDamager = GetLocalObject(OBJECT_SELF, "oAttacker");

        // Haspaar appears only if a DM is not in the game
        if (GetLocalInt(GetModule(), "bDMPresent") == 0)
        {
            if (GetIsPC(oDamager))
            {
                SetLocalInt(GetModule(), "nHeroBeenDamaged", 1);
                //Haspaar appears
                object oNearestPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
                CreateObject(OBJECT_TYPE_CREATURE, "Haspaar001", GetLocation(oNearestPC), TRUE);
                object oDragon = GetObjectByTag("Haspaar");
                AssignCommand(oDragon, ClearAllActions());
                DelayCommand(2.0, SendMessageToPC(oNearestPC, "Suddenly, Haspaar flies in and lands next to you."));
                AssignCommand(oDragon, DelayCommand(3.0, SpeakString("Need some help, little one?", TALKVOLUME_SHOUT)));

            }
        }
    }
}
