/*
    PROJECT Q IV
    (c) 2022 by Pstemarie

    Purple Worm OnConversation Event Script

    Version: 1.0
    Created: 28 Jan 2003
    Author:  Lacero

*/

#include "NW_I0_GENERIC"
#include "q_i0_worm"

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

    if (nMatch == -1 && GetCommandable(OBJECT_SELF))
    {
        ClearAllActions();
        BeginConversation();
    }
    else
    if(nMatch != -1 && GetIsObjectValid(oShouter) && !GetIsPC(oShouter) && GetIsFriend(oShouter))
    {
        object oTarget = GetLastHostileActor(oShouter);
        if(!GetIsObjectValid(GetAttemptedAttackTarget()) && !GetIsObjectValid(GetAttemptedSpellTarget()))
        {
            if(GetIsObjectValid(oTarget))
            {
                if(!GetIsFriend(oTarget) && GetIsFriend(oShouter))
                {
                    pw_DetermineCombatRound(oTarget);
                }
            }
        }
    }


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

