From 237580ab50f84162a2f12560373381d55d61902a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 12 Mar 2018 14:00:18 -0400 Subject: [PATCH] Core/Unit: added GetTotalAuraXXX overloads taking a predicate - Redefined existing overloads to use the predicate logic, avoids code duplication and not checking same stack rules --- Source/Game/Entities/Unit/Unit.Spells.cs | 276 ++++++++++++++--------- Source/Game/Entities/Unit/Unit.cs | 53 ----- Source/Game/Spells/SpellManager.cs | 3 +- 3 files changed, 166 insertions(+), 166 deletions(-) diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index ee2910949..55dc3dcc1 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -1665,7 +1665,7 @@ namespace Game.Entities var immuneAuraApply = GetAuraEffectsByType(AuraType.ModImmuneAuraApplySchool); foreach (var auraEffect in immuneAuraApply) if (Convert.ToBoolean(auraEffect.GetMiscValue() & (int)spellInfo.GetSchoolMask()) && // Check school - (!IsFriendlyTo(caster) || !spellInfo.IsPositiveEffect(index))) // Harmful + ((caster && !IsFriendlyTo(caster)) || !spellInfo.IsPositiveEffect(index))) // Harmful return true; } } @@ -2283,32 +2283,6 @@ namespace Game.Entities return healInfo.GetEffectiveHeal(); } - public int GetMaxPositiveAuraModifier(AuraType auratype) - { - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - { - if (eff.GetAmount() > modifier) - modifier = eff.GetAmount(); - } - - return modifier; - } - - public int GetMaxNegativeAuraModifier(AuraType auratype) - { - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - if (eff.GetAmount() < modifier) - modifier = eff.GetAmount(); - - return modifier; - } - public void ApplyCastTimePercentMod(float val, bool apply) { if (val > 0) @@ -3004,29 +2978,6 @@ namespace Game.Entities return result; } - public float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint miscMask) - { - Dictionary SameEffectSpellGroup = new Dictionary(); - float multiplier = 1.0f; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - { - if (eff.GetMiscValue().HasAnyFlag((int)miscMask)) - { - // 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(eff.GetSpellInfo(), eff.GetAmount(), out SameEffectSpellGroup)) - MathFunctions.AddPct(ref multiplier, eff.GetAmount()); - } - } - // Add the highest of the Same Effect Stack Rule SpellGroups to the multiplier - foreach (var group in SameEffectSpellGroup.Values) - MathFunctions.AddPct(ref multiplier, group); - - return multiplier; - } - public bool HasAura(uint spellId, ObjectGuid casterGUID = default(ObjectGuid), ObjectGuid itemCasterGUID = default(ObjectGuid), uint reqEffMask = 0) { if (GetAuraApplication(spellId, casterGUID, itemCasterGUID, reqEffMask) != null) @@ -3062,34 +3013,6 @@ namespace Game.Entities return false; } - int GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int miscValue) - { - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - { - if (eff.GetMiscValue() == miscValue && eff.GetAmount() > modifier) - modifier = eff.GetAmount(); - } - - return modifier; - } - - int GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int miscValue) - { - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - { - if (eff.GetMiscValue() == miscValue && eff.GetAmount() < modifier) - modifier = eff.GetAmount(); - } - - return modifier; - } - // target dependent range checks public float GetSpellMaxRangeForTarget(Unit target, SpellInfo spellInfo) { @@ -4375,58 +4298,189 @@ namespace Game.Entities { return m_modAuras.LookupByKey(type); } - public int GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint miscMask, AuraEffect except = null) - { - int modifier = 0; - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - { - if (except != eff && Convert.ToBoolean(eff.GetMiscValue() & miscMask) && eff.GetAmount() > modifier) - modifier = eff.GetAmount(); - } - - return modifier; - } - public int GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint miscMask) - { - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var eff in mTotalAuraList) - { - if (Convert.ToBoolean(eff.GetMiscValue() & miscMask) && eff.GetAmount() < modifier) - modifier = eff.GetAmount(); - } - - return modifier; - } public int GetTotalAuraModifier(AuraType auratype) { - Dictionary SameEffectSpellGroup = new Dictionary(); + return GetTotalAuraModifier(auratype, aurEff => { return true; }); + } + + public int GetTotalAuraModifier(AuraType auratype, Func predicate) + { + Dictionary sameEffectSpellGroup = new Dictionary(); int modifier = 0; var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var aura in mTotalAuraList) - if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(aura.GetSpellInfo(), aura.GetAmount(), out SameEffectSpellGroup)) - modifier += aura.GetAmount(); + 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(), aurEff.GetAmount(), sameEffectSpellGroup)) + modifier += aurEff.GetAmount(); + } + } - foreach (var pair in SameEffectSpellGroup) + // Add the highest of the Same Effect Stack Rule SpellGroups to the accumulator + foreach (var pair in sameEffectSpellGroup) modifier += pair.Value; return modifier; } + public float GetTotalAuraMultiplier(AuraType auratype) { + return GetTotalAuraModifier(auratype, aurEff => { return true; }); + } + + public float GetTotalAuraMultiplier(AuraType auratype, Func predicate) + { + var mTotalAuraList = GetAuraEffectsByType(auratype); + if (mTotalAuraList.Empty()) + return 1.0f; + + Dictionary sameEffectSpellGroup = new Dictionary(); float multiplier = 1.0f; - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var aura in mTotalAuraList) - MathFunctions.AddPct(ref multiplier, aura.GetAmount()); + foreach (var 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(), aurEff.GetAmount(), sameEffectSpellGroup)) + MathFunctions.AddPct(ref multiplier, aurEff.GetAmount()); + } + } + + // Add the highest of the Same Effect Stack Rule SpellGroups to the multiplier + foreach (var pair in sameEffectSpellGroup) + MathFunctions.AddPct(ref multiplier, pair.Value); return multiplier; } + public int GetMaxPositiveAuraModifier(AuraType auratype) + { + return GetTotalAuraModifier(auratype, aurEff => { return true; }); + } + + public int GetMaxPositiveAuraModifier(AuraType auratype, Func predicate) + { + var mTotalAuraList = GetAuraEffectsByType(auratype); + if (mTotalAuraList.Empty()) + return 0; + + int modifier = 0; + foreach (var aurEff in mTotalAuraList) + { + if (predicate(aurEff)) + modifier = Math.Max(modifier, aurEff.GetAmount()); + } + + return modifier; + } + + public int GetMaxNegativeAuraModifier(AuraType auratype) + { + return GetTotalAuraModifier(auratype, aurEff => { return true; }); + } + + public int GetMaxNegativeAuraModifier(AuraType auratype, Func predicate) + { + var mTotalAuraList = GetAuraEffectsByType(auratype); + if (mTotalAuraList.Empty()) + return 0; + + int modifier = 0; + foreach (var aurEff in mTotalAuraList) + if (predicate(aurEff)) + modifier = Math.Min(modifier, aurEff.GetAmount()); + + return modifier; + } + + public int GetTotalAuraModifierByMiscMask(AuraType auratype, int miscMask) + { + return GetTotalAuraModifier(auratype, aurEff => + { + if ((aurEff.GetMiscValue() & miscMask) != 0) + return true; + return false; + }); + } + + public float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint miscMask) + { + return GetTotalAuraMultiplier(auratype, aurEff => + { + if ((aurEff.GetMiscValue() & miscMask) != 0) + return true; + return false; + }); + } + + public int GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint miscMask, AuraEffect except = null) + { + return GetMaxPositiveAuraModifier(auratype, aurEff => + { + if (except != aurEff && (aurEff.GetMiscValue() & miscMask) != 0) + return true; + return false; + }); + } + + public int GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint miscMask) + { + return GetMaxNegativeAuraModifier(auratype, aurEff => + { + if ((aurEff.GetMiscValue() & miscMask) != 0) + return true; + return false; + }); + } + + public int GetTotalAuraModifierByMiscValue(AuraType auratype, int miscValue) + { + return GetTotalAuraModifier(auratype, aurEff => + { + if (aurEff.GetMiscValue() == miscValue) + return true; + return false; + }); + } + + public float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int miscValue) + { + return GetTotalAuraMultiplier(auratype, aurEff => + { + if (aurEff.GetMiscValue() == miscValue) + return true; + return false; + }); + } + + int GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int miscValue) + { + return GetMaxPositiveAuraModifier(auratype, aurEff => + { + if (aurEff.GetMiscValue() == miscValue) + return true; + return false; + }); + } + + int GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int miscValue) + { + return GetMaxNegativeAuraModifier(auratype, aurEff => + { + if (aurEff.GetMiscValue() == miscValue) + return true; + return false; + }); + } + + public void _RegisterAuraEffect(AuraEffect aurEff, bool apply) { if (apply) diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 7157eef8f..31d8cb00f 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -1688,59 +1688,6 @@ namespace Game.Entities { m_auraModifiersGroup[(int)unitMod][(int)modifierType] = value; } - public float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int miscValue) - { - Dictionary SameEffectSpellGroup = new Dictionary(); - float multiplier = 1.0f; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var i in mTotalAuraList) - { - if (i.GetMiscValue() == miscValue) - if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(i.GetSpellInfo(), i.GetAmount(), out SameEffectSpellGroup)) - MathFunctions.AddPct(ref multiplier, i.GetAmount()); - } - - foreach (var pair in SameEffectSpellGroup) - MathFunctions.AddPct(ref multiplier, pair.Value); - - return multiplier; - } - public int GetTotalAuraModifierByMiscValue(AuraType auratype, int miscValue) - { - Dictionary SameEffectSpellGroup = new Dictionary(); - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - foreach (var i in mTotalAuraList) - { - if (i.GetMiscValue() == miscValue) - if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(i.GetSpellInfo(), i.GetAmount(), out SameEffectSpellGroup)) - modifier += i.GetAmount(); - } - - foreach (var pair in SameEffectSpellGroup) - modifier += pair.Value; - - return modifier; - } - public int GetTotalAuraModifierByMiscMask(AuraType auratype, int miscMask) - { - Dictionary SameEffectSpellGroup = new Dictionary(); - int modifier = 0; - - var mTotalAuraList = GetAuraEffectsByType(auratype); - - foreach (var i in mTotalAuraList) - if (Convert.ToBoolean(i.GetMiscValue() & miscMask)) - if (!Global.SpellMgr.AddSameEffectStackRuleSpellGroups(i.GetSpellInfo(), i.GetAmount(), out SameEffectSpellGroup)) - modifier += i.GetAmount(); - - foreach (var pair in SameEffectSpellGroup) - modifier += pair.Value; - - return modifier; - } public int CalcSpellDuration(SpellInfo spellProto) { sbyte comboPoints = (sbyte)(m_playerMovingMe != null ? m_playerMovingMe.GetComboPoints() : 0); diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index b6ff29359..924b2934a 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -360,9 +360,8 @@ namespace Game.Entities } } - public bool AddSameEffectStackRuleSpellGroups(SpellInfo spellInfo, int amount, out Dictionary groups) + public bool AddSameEffectStackRuleSpellGroups(SpellInfo spellInfo, int amount, Dictionary groups) { - groups = new Dictionary(); uint spellId = spellInfo.GetFirstRankSpell().Id; var spellGroup = GetSpellSpellGroupMapBounds(spellId); // Find group with SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT if it belongs to one