// v2.1.0 - Small variable change.
// v2.0.0 -
//::////////////////////////////////////////////////////////////////////////////
//:: FileName:  hark_ac6_damaged
//::////////////////////////////////////////////////////////////////////////////
/*
   If already fighting then ignore, else determine combat round.
*/
//::////////////////////////////////////////////////////////////////////////////
#include "hark_i0_hench_ai"
#include "hark_i0_ac6"
//::////////////////////////////////////////////////////////////////////////////
void main()
{
  if (!preEvent()) { return; }

  object oLast = GetLastDamager();
  if (GetIsPC(oLast) && !GetIsDM(oLast))
    { SetFriendly(oLast, FALSE); }

  object oMaster = GetRealMaster();
  if (!GetAssociateState(NW_ASC_IS_BUSY) && !GetAssociateState(NW_ASC_MODE_DYING))
    {
     if (!GetAssociateState(NW_ASC_MODE_STAND_GROUND) &&
         GetCurrentAction() != ACTION_FOLLOW && GetCurrentAction() != ACTION_TAUNT)
       {
        if (GetStealthMode(OBJECT_SELF) == STEALTH_MODE_ACTIVATED)
          { ActionUseSkill(SKILL_HIDE, OBJECT_SELF); }

        if (!GetIsObjectValid(GetAttemptedAttackTarget()) &&
            !GetIsObjectValid(GetAttackTarget()) &&
            !GetIsObjectValid(GetAttemptedSpellTarget()))
          {
           if (GetIsObjectValid(GetLastHostileActor()))
             {
              if (GetAssociateState(NW_ASC_MODE_DEFEND_MASTER))
                {
                 if (!GetIsObjectValid(GetLastHostileActor(oMaster)))
                   { HenchDetermineCombatRound(); }
                }
              else
                { HenchDetermineCombatRound(oLast); }
             }
          }
       }
    }
  else if (GetAssociateState(NW_ASC_MODE_DYING))
    {
     SPS(OBJECT_SELF, PWS_PLAYER_STATE_DEAD);
     if (GetIsObjectValid(oMaster))
       {
        if (oLast == oMaster)
          {
           SendMessageToPC(oMaster, GetName(OBJECT_SELF) + HEN_KILLED);
           QuitHenchman(oMaster);
          }
        else
          { FireHenchman(oMaster); }
       }
    }

  if (GetSpawnInCondition(NW_FLAG_EVENT_DAMAGED))
    { SignalEvent(OBJECT_SELF, EventUserDefined(1006)); }

  postEvent();
}
//::////////////////////////////////////////////////////////////////////////////
