Esempio n. 1
0
        void AddThreat(Unit victim, float threat)
        {
            var reff = threatContainer.AddThreat(victim, threat);

            // Ref is not in the online refs, search the offline refs next
            if (reff == null)
            {
                reff = threatOfflineContainer.AddThreat(victim, threat);
            }

            if (reff == null) // there was no ref => create a new one
            {
                bool isFirst = threatContainer.Empty();

                // threat has to be 0 here
                var hostileRef = new HostileReference(victim, this, 0);
                threatContainer.AddReference(hostileRef);
                hostileRef.AddThreat(threat); // now we add the real threat
                if (victim.IsTypeId(TypeId.Player) && victim.ToPlayer().IsGameMaster())
                {
                    hostileRef.SetOnlineOfflineState(false); // GM is always offline
                }
                else if (isFirst)
                {
                    SetCurrentVictim(hostileRef);
                }
            }
        }
Esempio n. 2
0
 public void SetCurrentVictim(HostileReference pHostileReference)
 {
     if (pHostileReference != null && pHostileReference != currentVictim)
     {
         Owner.SendChangeCurrentVictim(pHostileReference);
     }
     currentVictim = pHostileReference;
 }
Esempio n. 3
0
        public Unit GetHostilTarget()
        {
            threatContainer.Update();
            HostileReference nextVictim = threatContainer.SelectNextVictim(GetOwner().ToCreature(), getCurrentVictim());

            SetCurrentVictim(nextVictim);
            return(GetCurrentVictim() != null?GetCurrentVictim() : null);
        }
Esempio n. 4
0
        public void ModifyThreatByPercent(Unit victim, int percent)
        {
            HostileReference refe = GetReferenceByTarget(victim);

            if (refe != null)
            {
                refe.AddThreatPercent(percent);
            }
        }
Esempio n. 5
0
        void TauntFadeOut(Unit taunter)
        {
            HostileReference refe = threatContainer.GetReferenceByTarget(taunter);

            if (refe != null)
            {
                refe.ResetTempThreat();
            }
        }
Esempio n. 6
0
        public void ProcessThreatEvent(ThreatRefStatusChangeEvent threatRefStatusChangeEvent)
        {
            threatRefStatusChangeEvent.SetThreatManager(this);     // now we can set the threat manager

            HostileReference hostilRef = threatRefStatusChangeEvent.GetReference();

            switch (threatRefStatusChangeEvent.GetEventType())
            {
            case UnitEventTypes.ThreatRefThreatChange:
                if ((getCurrentVictim() == hostilRef && threatRefStatusChangeEvent.GetFValue() < 0.0f) ||
                    (getCurrentVictim() != hostilRef && threatRefStatusChangeEvent.GetFValue() > 0.0f))
                {
                    SetDirty(true);                                 // the order in the threat list might have changed
                }
                break;

            case UnitEventTypes.ThreatRefOnlineStatus:
                if (!hostilRef.IsOnline())
                {
                    if (hostilRef == getCurrentVictim())
                    {
                        SetCurrentVictim(null);
                        SetDirty(true);
                    }
                    Owner.SendRemoveFromThreatList(hostilRef);
                    threatContainer.Remove(hostilRef);
                    threatOfflineContainer.AddReference(hostilRef);
                }
                else
                {
                    if (GetCurrentVictim() != null && hostilRef.GetThreat() > (1.1f * getCurrentVictim().GetThreat()))
                    {
                        SetDirty(true);
                    }
                    threatContainer.AddReference(hostilRef);
                    threatOfflineContainer.Remove(hostilRef);
                }
                break;

            case UnitEventTypes.ThreatRefRemoveFromList:
                if (hostilRef == getCurrentVictim())
                {
                    SetCurrentVictim(null);
                    SetDirty(true);
                }
                Owner.SendRemoveFromThreatList(hostilRef);
                if (hostilRef.IsOnline())
                {
                    threatContainer.Remove(hostilRef);
                }
                else
                {
                    threatOfflineContainer.Remove(hostilRef);
                }
                break;
            }
        }
Esempio n. 7
0
        void addThreatPercent(int percent)
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                refe.addThreatPercent(percent);
                refe = refe.next();
            }
        }
Esempio n. 8
0
        public void updateThreatTables()
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                refe.updateOnlineStatus();
                refe = refe.next();
            }
        }
Esempio n. 9
0
        public void setOnlineOfflineState(bool isOnline)
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                refe.setOnlineOfflineState(isOnline);
                refe = refe.next();
            }
        }
Esempio n. 10
0
        void AddThreatPercent(int percent)
        {
            HostileReference refe = GetFirst();

            while (refe != null)
            {
                refe.AddThreatPercent(percent);
                refe = refe.Next();
            }
        }
Esempio n. 11
0
        // The references are not needed anymore
        // tell the source to remove them from the list and free the mem
        public void deleteReferences()
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                HostileReference nextRef = refe.next();
                refe.removeReference();
                refe = nextRef;
            }
        }
Esempio n. 12
0
        // The references are not needed anymore
        // tell the source to remove them from the list and free the mem
        public void DeleteReferences()
        {
            HostileReference refe = GetFirst();

            while (refe != null)
            {
                HostileReference nextRef = refe.Next();
                refe.RemoveReference();
                refe = nextRef;
            }
        }
Esempio n. 13
0
        void TauntApply(Unit taunter)
        {
            HostileReference refe = threatContainer.GetReferenceByTarget(taunter);

            if (GetCurrentVictim() != null && refe != null && (refe.GetThreat() < getCurrentVictim().GetThreat()))
            {
                if (refe.GetTempThreatModifier() == 0.0f) // Ok, temp threat is unused
                {
                    refe.SetTempThreat(getCurrentVictim().GetThreat());
                }
            }
        }
Esempio n. 14
0
        // Remove specific faction references
        public void deleteReferencesForFaction(uint faction)
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                HostileReference nextRef = refe.next();
                if (refe.GetSource().GetOwner().GetFactionTemplateEntry().Faction == faction)
                {
                    refe.removeReference();
                }
                refe = nextRef;
            }
        }
Esempio n. 15
0
        // set state for one reference, defined by Unit
        public void setOnlineOfflineState(Unit creature, bool isOnline)
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                HostileReference nextRef = refe.next();
                if (refe.GetSource().GetOwner() == creature)
                {
                    refe.setOnlineOfflineState(isOnline);
                    break;
                }
                refe = nextRef;
            }
        }
Esempio n. 16
0
        // delete one reference, defined by Unit
        public void deleteReference(Unit creature)
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                HostileReference nextRef = refe.next();
                if (refe.GetSource().GetOwner() == creature)
                {
                    refe.removeReference();
                    break;
                }
                refe = nextRef;
            }
        }
Esempio n. 17
0
        public void UpdateVisibility()
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                HostileReference nextRef = refe.next();
                if (!refe.GetSource().GetOwner().CanSeeOrDetect(getOwner()))
                {
                    nextRef = refe.next();
                    refe.removeReference();
                }
                refe = nextRef;
            }
        }
Esempio n. 18
0
        public float GetThreat(Unit victim, bool alsoSearchOfflineList = false)
        {
            float            threat = 0.0f;
            HostileReference refe   = threatContainer.GetReferenceByTarget(victim);

            if (refe == null && alsoSearchOfflineList)
            {
                refe = threatOfflineContainer.GetReferenceByTarget(victim);
            }
            if (refe != null)
            {
                threat = refe.GetThreat();
            }
            return(threat);
        }
Esempio n. 19
0
        // delete all references out of specified range
        public void deleteReferencesOutOfRange(float range)
        {
            HostileReference refe = getFirst();

            range = range * range;
            while (refe != null)
            {
                HostileReference nextRef = refe.next();
                Unit             owner   = refe.GetSource().GetOwner();
                if (!owner.isActiveObject() && owner.GetExactDist2dSq(getOwner()) > range)
                {
                    refe.removeReference();
                }
                refe = nextRef;
            }
        }
Esempio n. 20
0
        // send threat to all my hateres for the victim
        // The victim is hated than by them as well
        // use for buffs and healing threat functionality
        public void threatAssist(Unit victim, float baseThreat, SpellInfo threatSpell = null)
        {
            HostileReference refe   = getFirst();
            float            threat = ThreatManager.calcThreat(victim, Owner, baseThreat, (threatSpell != null ? threatSpell.GetSchoolMask() : SpellSchoolMask.Normal), threatSpell);

            threat /= getSize();
            while (refe != null)
            {
                if (ThreatManager.isValidProcess(victim, refe.GetSource().GetOwner(), threatSpell))
                {
                    refe.GetSource().doAddThreat(victim, threat);
                }

                refe = refe.next();
            }
        }
Esempio n. 21
0
        public void addTempThreat(float threat, bool apply)
        {
            HostileReference refe = getFirst();

            while (refe != null)
            {
                if (apply)
                {
                    if (refe.getTempThreatModifier() == 0.0f)
                    {
                        refe.addTempThreat(threat);
                    }
                }
                else
                {
                    refe.resetTempThreat();
                }

                refe = refe.next();
            }
        }
Esempio n. 22
0
 public void AddReference(HostileReference hostileRef)
 {
     threatList.Add(hostileRef);
 }
Esempio n. 23
0
 public ThreatRefStatusChangeEvent(UnitEventTypes pType, HostileReference pHostileReference, bool pValue)
     : base(pType)
 {
     iHostileReference = pHostileReference;
     iBValue           = pValue;
 }
Esempio n. 24
0
        public HostileReference SelectNextVictim(Creature attacker, HostileReference currentVictim)
        {
            HostileReference currentRef            = null;
            bool             found                 = false;
            bool             noPriorityTargetFound = false;

            for (var i = 0; i < threatList.Count; i++)
            {
                if (found)
                {
                    break;
                }

                currentRef = threatList[i];

                Unit target = currentRef.GetTarget();
                Cypher.Assert(target);                                     // if the ref has status online the target must be there !

                // some units are prefered in comparison to others
                if (!noPriorityTargetFound && (target.IsImmunedToDamage(attacker.GetMeleeDamageSchoolMask()) || target.HasNegativeAuraWithInterruptFlag(SpellAuraInterruptFlags.TakeDamage)))
                {
                    if (i != threatList.Count - 1)
                    {
                        // current victim is a second choice target, so don't compare threat with it below
                        if (currentRef == currentVictim)
                        {
                            currentVictim = null;
                        }
                        continue;
                    }
                    else
                    {
                        // if we reached to this point, everyone in the threatlist is a second choice target. In such a situation the target with the highest threat should be attacked.
                        noPriorityTargetFound = true;
                        i = 0;
                        continue;
                    }
                }

                if (attacker.CanCreatureAttack(target))           // skip non attackable currently targets
                {
                    if (currentVictim != null)                    // select 1.3/1.1 better target in comparison current target
                    {
                        // list sorted and and we check current target, then this is best case
                        if (currentVictim == currentRef || currentRef.GetThreat() <= 1.1f * currentVictim.GetThreat())
                        {
                            if (currentVictim != currentRef && attacker.CanCreatureAttack(currentVictim.GetTarget()))
                            {
                                currentRef = currentVictim;            // for second case, if currentvictim is attackable
                            }
                            found = true;
                            break;
                        }

                        if (currentRef.GetThreat() > 1.3f * currentVictim.GetThreat() ||
                            (currentRef.GetThreat() > 1.1f * currentVictim.GetThreat() &&
                             attacker.IsWithinMeleeRange(target)))
                        {                                           //implement 110% threat rule for targets in melee range
                            found = true;                           //and 130% rule for targets in ranged distances
                            break;                                  //for selecting alive targets
                        }
                    }
                    else                                            // select any
                    {
                        found = true;
                        break;
                    }
                }
            }
            if (!found)
            {
                currentRef = null;
            }

            return(currentRef);
        }
Esempio n. 25
0
 public void Remove(HostileReference hostileRef)
 {
     threatList.Remove(hostileRef);
 }
Esempio n. 26
0
 ThreatManagerEvent(UnitEventTypes pType, HostileReference pHostileReference)
     : base(pType, pHostileReference)
 {
     iThreatContainer = null;
 }