#include "NW_I0_GENERIC"
#include "sr_summontanarii"

void main()
{
    if(!GetFleeToExit())
    {
        if(!GetSpawnInCondition(NW_FLAG_SET_WARNINGS))
        {
            if(!GetIsObjectValid(GetAttemptedAttackTarget()) && !GetIsObjectValid(GetAttemptedSpellTarget()))
            {
                if(GetIsObjectValid(GetLastAttacker()))
                {
                    if(GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL))
                    {
                        //AdjustReputation(GetLastAttacker(), OBJECT_SELF, -100);
                        SetSummonHelpIfAttacked();
                        DetermineSpecialBehavior(GetLastAttacker());
                    }
                    else
                    {
                        if(GetArea(GetLastAttacker()) == GetArea(OBJECT_SELF))
                        {
                            SetSummonHelpIfAttacked();
                            DetermineCombatRound();
                        }
                    }
                    //Shout Attack my target, only works with the On Spawn In setup
                    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
                    //Shout that I was attacked
                    SpeakString("NW_I_WAS_ATTACKED", TALKVOLUME_SILENT_TALK);
                }
            }
        }
        else
        {
            //Put a check in to see if this attacker was the last attacker
            //Possibly change the GetNPCWarning function to make the check
            SetSpawnInCondition(NW_FLAG_SET_WARNINGS, FALSE);
        }
    }
    else
    {
        ActivateFleeToExit();
    }
    if(GetSpawnInCondition(NW_FLAG_ATTACK_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(1005));
    }

    // Tanarii Summoning Scripts.
    if (GetLocalFloat(OBJECT_SELF, "Minute") == -1.0) {
        if (GetTag(OBJECT_SELF) == "sr_dretchdemon")
            SummonTanarii(1);
        if (GetTag(OBJECT_SELF) == "sr_succubus")
            SummonTanarii(2);
        if (GetTag(OBJECT_SELF) == "sr_vrock")
            SummonTanarii(3);
        if (GetTag(OBJECT_SELF) == "sr_hezroudemon")
            SummonTanarii(4);
        if (GetTag(OBJECT_SELF) == "sr_glabrezudemon")
            SummonTanarii(5);
        if (GetTag(OBJECT_SELF) == "sr_nalfeshdemom")
            SummonTanarii(6);
        if (GetTag(OBJECT_SELF) == "sr_marilithdemon")
            SummonTanarii(7);
        if (GetTag(OBJECT_SELF) == "sr_balordemon")
            SummonTanarii(8);
    }

}
