//::///////////////////////////////////////////////
//:: SetListeningPatterns
//:: NW_C2_DEFAULT4
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Determines the course of action to be taken
    by the generic script after dialogue or a
    shout is initiated.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Oct 24, 2001
//:://////////////////////////////////////////////

#include "NW_I0_GENERIC"

void main()
{
    int nMatch = GetListenPatternNumber();
    object oShouter = GetLastSpeaker();
    object oIntruder;

    // DMFI ALTERED CODE
    if (nMatch == -1 && GetCommandable(OBJECT_SELF))
    {
        // DMFI: Check "bConversationEnabled"
        if (GetLocalInt(OBJECT_SELF, "bConversationEnabled") == 1)
        {
            ClearAllActions();
            BeginConversation();
            // DMFI: Notify DMs conversation initiated
            SendMessageToAllDMs("Scripted conversation initiated with " + GetName(OBJECT_SELF));
        }
        else
        {
            // DMFI: Notify player conversation is disabled
            SendMessageToPC(oShouter, "This NPCs conversation is disabled -- please wait for a DM");
            // DMFI: Notify DMs conversation attempted
            SendMessageToAllDMs("Conversation attempted on " + GetName(OBJECT_SELF));
        }
    }
    else
    if(nMatch != -1 && GetIsObjectValid(oShouter) && !GetIsPC(oShouter) && GetIsFriend(oShouter))
    {
        if(nMatch == 4)
        {
            oIntruder = GetLocalObject(oShouter, "NW_BLOCKER_INTRUDER");
        }
        else if (nMatch == 5)
        {
            oIntruder = GetLastHostileActor(oShouter);
            if(!GetIsObjectValid(oIntruder))
            {
                oIntruder = GetAttemptedAttackTarget();
                if(!GetIsObjectValid(oIntruder))
                {
                    oIntruder = GetAttemptedSpellTarget();
                    if(!GetIsObjectValid(oIntruder))
                    {
                        oIntruder = OBJECT_INVALID;
                    }
                }
            }
        }
        RespondToShout(oShouter, nMatch, oIntruder);
    }


    if(GetSpawnInCondition(NW_FLAG_ON_DIALOGUE_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(1004));
    }
}
