public void Remove(Hostile hostile)
 {
     if (ImmutableInterlocked.TryRemove(ref _hostiles, hostile.unit.Eid, out hostile))
     {
         _isDirty = true;
     }
 }
 public Hostile GetHostile(Unit unit)
 {
     return(ImmutableInterlocked.GetOrAdd(ref _hostiles, unit.Eid, eid =>
     {
         var h = new Hostile(unit);
         h.Updated += OnHostileThreatUpdated;
         _isDirty = true;
         return h;
     }));
 }
Example #3
0
        private bool TryMakeFreeLockSlotFor(Hostile hostile)
        {
            if (npc.HasFreeLockSlot)
            {
                return(true);
            }

            var weakestLock = npc.ThreatManager.Hostiles.SkipWhile(h => h != hostile).Skip(1).Select(h => npc.GetLockByUnit(h.unit)).LastOrDefault();

            if (weakestLock == null)
            {
                return(false);
            }

            weakestLock.Cancel();
            return(true);
        }
Example #4
0
        private bool IsAttackable(Hostile hostile)
        {
            if (!hostile.unit.InZone)
            {
                return(false);
            }

            if (hostile.unit.States.Dead)
            {
                return(false);
            }

            if (!hostile.unit.IsLockable)
            {
                return(false);
            }

            if (hostile.unit.IsAttackable != ErrorCodes.NoError)
            {
                return(false);
            }

            if (hostile.unit.IsInvulnerable)
            {
                return(false);
            }

            if (npc.Behavior.Type == NpcBehaviorType.Neutral)
            {
                if (hostile.IsExpired)
                {
                    return(false);
                }
            }

            var isVisible = npc.IsVisible(hostile.unit);

            if (!isVisible)
            {
                return(false);
            }

            return(true);
        }
 private void OnHostileThreatUpdated(Hostile hostile)
 {
     _isDirty = true;
 }