diff --git a/Source/Game/Combat/ThreatManager.cs b/Source/Game/Combat/ThreatManager.cs index fcd07675c..7fb845902 100644 --- a/Source/Game/Combat/ThreatManager.cs +++ b/Source/Game/Combat/ThreatManager.cs @@ -346,23 +346,20 @@ namespace Game.Combat public void TauntUpdate() { var tauntEffects = _owner.GetAuraEffectsByType(AuraType.ModTaunt); - ThreatReference tauntRef = null; + TauntState state = TauntState.Taunt; + Dictionary tauntStates = new(); + // Only the last taunt effect applied by something still on our threat list is considered foreach (var auraEffect in tauntEffects) - { - var refe = _myThreatListEntries.LookupByKey(auraEffect.GetCasterGUID()); - if (refe == null) - continue; - - if (!refe.IsAvailable()) - continue; - - tauntRef = refe; - break; - } + tauntStates[auraEffect.GetCasterGUID()] = state++; foreach (var pair in _myThreatListEntries) - pair.Value.UpdateTauntState(pair.Value == tauntRef); + { + if (tauntStates.TryGetValue(pair.Key, out TauntState tauntState)) + pair.Value.UpdateTauntState(tauntState); + else + pair.Value.UpdateTauntState(); + } } public void ResetAllThreat() @@ -716,9 +713,9 @@ namespace Game.Combat public enum TauntState { - Detaunt = -1, - None = 0, - Taunt = 1 + Detaunt = 0, + None = 1, + Taunt = 2 } public enum OnlineState { @@ -822,27 +819,17 @@ namespace Game.Combat return OnlineState.Online; } - public void UpdateTauntState(bool victimIsTaunting) + public void UpdateTauntState(TauntState state = TauntState.None) { - if (victimIsTaunting) - { - _taunted = TauntState.Taunt; - ListNotifyChanged(); - return; - } - // Check for SPELL_AURA_MOD_DETAUNT (applied from owner to victim) - foreach (AuraEffect eff in _victim.GetAuraEffectsByType(AuraType.ModDetaunt)) - { - if (eff.GetCasterGUID() == _owner.GetGUID()) - { - _taunted = TauntState.Detaunt; - ListNotifyChanged(); - return; - } - } + if (state < TauntState.Taunt && _victim.HasAuraTypeWithCaster(AuraType.ModDetaunt, _owner.GetGUID())) + state = TauntState.Detaunt; + + if (state == _taunted) + return; + + Extensions.Swap(ref state, ref _taunted); - _taunted = TauntState.None; ListNotifyChanged(); } @@ -859,8 +846,8 @@ namespace Game.Combat public bool IsOnline() { return (_online >= OnlineState.Online); } public bool IsAvailable() { return (_online > OnlineState.Offline); } public bool IsOffline() { return (_online <= OnlineState.Offline); } - public TauntState GetTauntState() { return _taunted; } - public bool IsTaunting() { return _taunted == TauntState.Taunt; } + public TauntState GetTauntState() { return IsTaunting() ? TauntState.Taunt : _taunted; } + public bool IsTaunting() { return _taunted >= TauntState.Taunt; } public bool IsDetaunted() { return _taunted == TauntState.Detaunt; } public void SetThreat(float amount) diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index 0c70eea76..cd0305be9 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -2622,36 +2622,36 @@ namespace Game.Entities { return !m_modAuras.LookupByKey(auraType).Empty(); } - public bool HasAuraTypeWithCaster(AuraType auratype, ObjectGuid caster) + public bool HasAuraTypeWithCaster(AuraType auraType, ObjectGuid caster) { - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var aura in mTotalAuraList) - if (caster == aura.GetCasterGUID()) + foreach (var auraEffect in GetAuraEffectsByType(auraType)) + if (caster == auraEffect.GetCasterGUID()) return true; + return false; } - public bool HasAuraTypeWithMiscvalue(AuraType auratype, int miscvalue) + public bool HasAuraTypeWithMiscvalue(AuraType auraType, int miscvalue) { - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var aura in mTotalAuraList) - if (miscvalue == aura.GetMiscValue()) + foreach (var auraEffect in GetAuraEffectsByType(auraType)) + if (miscvalue == auraEffect.GetMiscValue()) return true; + return false; } - public bool HasAuraTypeWithAffectMask(AuraType auratype, SpellInfo affectedSpell) + public bool HasAuraTypeWithAffectMask(AuraType auraType, SpellInfo affectedSpell) { - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var aura in mTotalAuraList) - if (aura.IsAffectingSpell(affectedSpell)) + foreach (var auraEffect in GetAuraEffectsByType(auraType)) + if (auraEffect.IsAffectingSpell(affectedSpell)) return true; + return false; } - public bool HasAuraTypeWithValue(AuraType auratype, int value) + public bool HasAuraTypeWithValue(AuraType auraType, int value) { - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var aura in mTotalAuraList) - if (value == aura.GetAmount()) + foreach (var auraEffect in GetAuraEffectsByType(auraType)) + if (value == auraEffect.GetAmount()) return true; + return false; } @@ -4008,24 +4008,24 @@ namespace Game.Entities return m_modAuras.LookupByKey(type); } - public int GetTotalAuraModifier(AuraType auratype) + public int GetTotalAuraModifier(AuraType auraType) { - return GetTotalAuraModifier(auratype, aurEff => true); + return GetTotalAuraModifier(auraType, aurEff => true); } - public int GetTotalAuraModifier(AuraType auratype, Func predicate) + public int GetTotalAuraModifier(AuraType auraType, Func predicate) { Dictionary sameEffectSpellGroup = new(); int modifier = 0; - var mTotalAuraList = GetAuraEffectsByType(auratype); + var mTotalAuraList = GetAuraEffectsByType(auraType); foreach (AuraEffect aurEff in mTotalAuraList) { if (predicate(aurEff)) { // Check if the Aura Effect has a the Same Effect Stack Rule and if so, use the highest amount of that SpellGroup // If the Aura Effect does not have this Stack Rule, it returns false so we can add to the multiplier as usual - if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(aurEff.GetSpellInfo(), auratype, aurEff.GetAmount(), sameEffectSpellGroup)) + if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(aurEff.GetSpellInfo(), auraType, aurEff.GetAmount(), sameEffectSpellGroup)) modifier += aurEff.GetAmount(); } } @@ -4037,14 +4037,14 @@ namespace Game.Entities return modifier; } - public float GetTotalAuraMultiplier(AuraType auratype) + public float GetTotalAuraMultiplier(AuraType auraType) { - return GetTotalAuraMultiplier(auratype, aurEff => true); + return GetTotalAuraMultiplier(auraType, aurEff => true); } - public float GetTotalAuraMultiplier(AuraType auratype, Func predicate) + public float GetTotalAuraMultiplier(AuraType auraType, Func predicate) { - var mTotalAuraList = GetAuraEffectsByType(auratype); + var mTotalAuraList = GetAuraEffectsByType(auraType); if (mTotalAuraList.Empty()) return 1.0f; @@ -4057,7 +4057,7 @@ namespace Game.Entities { // Check if the Aura Effect has a the Same Effect Stack Rule and if so, use the highest amount of that SpellGroup // If the Aura Effect does not have this Stack Rule, it returns false so we can add to the multiplier as usual - if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(aurEff.GetSpellInfo(), auratype, aurEff.GetAmount(), sameEffectSpellGroup)) + if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(aurEff.GetSpellInfo(), auraType, aurEff.GetAmount(), sameEffectSpellGroup)) MathFunctions.AddPct(ref multiplier, aurEff.GetAmount()); } } @@ -4069,14 +4069,14 @@ namespace Game.Entities return multiplier; } - public int GetMaxPositiveAuraModifier(AuraType auratype) + public int GetMaxPositiveAuraModifier(AuraType auraType) { - return GetMaxPositiveAuraModifier(auratype, aurEff => true); + return GetMaxPositiveAuraModifier(auraType, aurEff => true); } - public int GetMaxPositiveAuraModifier(AuraType auratype, Func predicate) + public int GetMaxPositiveAuraModifier(AuraType auraType, Func predicate) { - var mTotalAuraList = GetAuraEffectsByType(auratype); + var mTotalAuraList = GetAuraEffectsByType(auraType); if (mTotalAuraList.Empty()) return 0; @@ -4090,14 +4090,14 @@ namespace Game.Entities return modifier; } - public int GetMaxNegativeAuraModifier(AuraType auratype) + public int GetMaxNegativeAuraModifier(AuraType auraType) { - return GetMaxNegativeAuraModifier(auratype, aurEff => true); + return GetMaxNegativeAuraModifier(auraType, aurEff => true); } - public int GetMaxNegativeAuraModifier(AuraType auratype, Func predicate) + public int GetMaxNegativeAuraModifier(AuraType auraType, Func predicate) { - var mTotalAuraList = GetAuraEffectsByType(auratype); + var mTotalAuraList = GetAuraEffectsByType(auraType); if (mTotalAuraList.Empty()) return 0; @@ -4109,9 +4109,9 @@ namespace Game.Entities return modifier; } - public int GetTotalAuraModifierByMiscMask(AuraType auratype, int miscMask) + public int GetTotalAuraModifierByMiscMask(AuraType auraType, int miscMask) { - return GetTotalAuraModifier(auratype, aurEff => + return GetTotalAuraModifier(auraType, aurEff => { if ((aurEff.GetMiscValue() & miscMask) != 0) return true; @@ -4119,9 +4119,9 @@ namespace Game.Entities }); } - public float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint miscMask) + public float GetTotalAuraMultiplierByMiscMask(AuraType auraType, uint miscMask) { - return GetTotalAuraMultiplier(auratype, aurEff => + return GetTotalAuraMultiplier(auraType, aurEff => { if ((aurEff.GetMiscValue() & miscMask) != 0) return true; @@ -4129,9 +4129,9 @@ namespace Game.Entities }); } - public int GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint miscMask, AuraEffect except = null) + public int GetMaxPositiveAuraModifierByMiscMask(AuraType auraType, uint miscMask, AuraEffect except = null) { - return GetMaxPositiveAuraModifier(auratype, aurEff => + return GetMaxPositiveAuraModifier(auraType, aurEff => { if (except != aurEff && (aurEff.GetMiscValue() & miscMask) != 0) return true; @@ -4139,9 +4139,9 @@ namespace Game.Entities }); } - public int GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint miscMask) + public int GetMaxNegativeAuraModifierByMiscMask(AuraType auraType, uint miscMask) { - return GetMaxNegativeAuraModifier(auratype, aurEff => + return GetMaxNegativeAuraModifier(auraType, aurEff => { if ((aurEff.GetMiscValue() & miscMask) != 0) return true; @@ -4149,9 +4149,9 @@ namespace Game.Entities }); } - public int GetTotalAuraModifierByMiscValue(AuraType auratype, int miscValue) + public int GetTotalAuraModifierByMiscValue(AuraType auraType, int miscValue) { - return GetTotalAuraModifier(auratype, aurEff => + return GetTotalAuraModifier(auraType, aurEff => { if (aurEff.GetMiscValue() == miscValue) return true; @@ -4159,9 +4159,9 @@ namespace Game.Entities }); } - public float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int miscValue) + public float GetTotalAuraMultiplierByMiscValue(AuraType auraType, int miscValue) { - return GetTotalAuraMultiplier(auratype, aurEff => + return GetTotalAuraMultiplier(auraType, aurEff => { if (aurEff.GetMiscValue() == miscValue) return true; @@ -4169,9 +4169,9 @@ namespace Game.Entities }); } - int GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int miscValue) + int GetMaxPositiveAuraModifierByMiscValue(AuraType auraType, int miscValue) { - return GetMaxPositiveAuraModifier(auratype, aurEff => + return GetMaxPositiveAuraModifier(auraType, aurEff => { if (aurEff.GetMiscValue() == miscValue) return true; @@ -4179,9 +4179,9 @@ namespace Game.Entities }); } - public int GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int miscValue) + public int GetMaxNegativeAuraModifierByMiscValue(AuraType auraType, int miscValue) { - return GetMaxNegativeAuraModifier(auratype, aurEff => + return GetMaxNegativeAuraModifier(auraType, aurEff => { if (aurEff.GetMiscValue() == miscValue) return true;