From 52952deee3e9bde23eace4043a5984821b09cd5d Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Tue, 3 Jun 2025 21:17:25 -0400 Subject: [PATCH] Core/Spells: Replace MAX_SPELL_EFFECTS loop limits with correct upper bound depending on how many effects the spell has Port From (https://github.com/TrinityCore/TrinityCore/commit/561b122364525deaee815ad900a78f1323c37776) --- Source/Game/Entities/Player/Player.Spells.cs | 7 ++++--- Source/Game/Scripting/SpellScript.cs | 2 +- Source/Game/Spells/Auras/Aura.cs | 21 +++++++------------- Source/Game/Spells/Auras/AuraEffect.cs | 2 +- Source/Game/Spells/SpellEffects.cs | 9 +++++---- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Source/Game/Entities/Player/Player.Spells.cs b/Source/Game/Entities/Player/Player.Spells.cs index d6ae68971..0fc62c0b5 100644 --- a/Source/Game/Entities/Player/Player.Spells.cs +++ b/Source/Game/Entities/Player/Player.Spells.cs @@ -2241,8 +2241,10 @@ namespace Game.Entities RemoveOwnedAura(spellId, GetGUID()); + SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None); + // remove pet auras - for (byte i = 0; i < SpellConst.MaxEffects; ++i) + for (byte i = 0; i < spellInfo.GetEffects().Count; ++i) { PetAura petSpell = Global.SpellMgr.GetPetAura(spellId, i); if (petSpell != null) @@ -2250,8 +2252,7 @@ namespace Game.Entities } // update free primary prof.points (if not overflow setting, can be in case GM use before .learn prof. learning) - SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None); - if (spellInfo != null && spellInfo.IsPrimaryProfessionFirstRank()) + if (spellInfo.IsPrimaryProfessionFirstRank()) { uint freeProfs = GetFreePrimaryProfessionPoints() + 1; if (freeProfs <= WorldConfig.GetIntValue(WorldCfg.MaxPrimaryTradeSkill)) diff --git a/Source/Game/Scripting/SpellScript.cs b/Source/Game/Scripting/SpellScript.cs index 15187031e..f3e93a71a 100644 --- a/Source/Game/Scripting/SpellScript.cs +++ b/Source/Game/Scripting/SpellScript.cs @@ -112,7 +112,7 @@ namespace Game.Scripting uint mask = 0; if (_effIndex == SpellConst.EffectAll || _effIndex == SpellConst.EffectFirstFound) { - for (byte i = 0; i < SpellConst.MaxEffects; ++i) + for (byte i = 0; i < spellInfo.GetEffects().Count; ++i) { if (_effIndex == SpellConst.EffectFirstFound && mask != 0) return mask; diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index fa13045f9..c67dd2d27 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -826,12 +826,9 @@ namespace Game.Spells m_timeCla = 1 * Time.InMilliseconds; // also reset periodic counters - for (byte i = 0; i < SpellConst.MaxEffects; ++i) - { - AuraEffect aurEff = GetEffect(i); + foreach (AuraEffect aurEff in GetAuraEffects()) if (aurEff != null) aurEff.ResetTicks(); - } } void RefreshTimers(bool resetPeriodicTimer) @@ -851,12 +848,8 @@ namespace Game.Spells RefreshDuration(); Unit caster = GetCaster(); - for (byte i = 0; i < SpellConst.MaxEffects; ++i) - { - AuraEffect aurEff = GetEffect(i); - if (aurEff != null) - aurEff.CalculatePeriodic(caster, resetPeriodicTimer, false); - } + foreach (AuraEffect aurEff in GetAuraEffects()) + aurEff.CalculatePeriodic(caster, resetPeriodicTimer, false); } public void SetCharges(int charges) @@ -1807,10 +1800,10 @@ namespace Game.Spells // At least one effect has to pass checks to proc aura uint procEffectMask = aurApp.GetEffectMask(); - for (byte i = 0; i < SpellConst.MaxEffects; ++i) - if ((procEffectMask & (1u << i)) != 0) - if ((procEntry.DisableEffectsMask & (1u << i)) != 0 || !GetEffect(i).CheckEffectProc(aurApp, eventInfo)) - procEffectMask &= ~(1u << i); + foreach (AuraEffect aurEff in GetAuraEffects()) + if ((procEffectMask & (1u << (int)aurEff.GetEffIndex())) != 0) + if ((procEntry.DisableEffectsMask & (1u << (int)aurEff.GetEffIndex())) != 0 || !GetEffect(aurEff.GetEffIndex()).CheckEffectProc(aurApp, eventInfo)) + procEffectMask &= ~(1u << (int)aurEff.GetEffIndex()); if (procEffectMask == 0) return 0; diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 4631a1c52..e90ca67bd 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -5167,7 +5167,7 @@ namespace Game.Spells { CastSpellExtraArgs args = new(this); args.SetTriggerFlags(TriggerCastFlags.FullMask & ~(TriggerCastFlags.IgnorePowerCost | TriggerCastFlags.IgnoreReagentCost)); - for (int i = 0; i < SpellConst.MaxEffects; ++i) + for (int i = 0; i < triggeredSpellInfo.GetEffects().Count; ++i) args.AddSpellMod(SpellValueMod.BasePoint0 + i, GetAmount()); triggerCaster.CastSpell(target, triggerSpellId, args); diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 488ce99be..769db55cc 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -313,7 +313,8 @@ namespace Game.Spells args.SetOriginalCaster(originalCaster); args.OriginalCastId = originalCastId; args.OriginalCastItemLevel = itemLevel; - if (!castItemGuid.IsEmpty() && Global.SpellMgr.GetSpellInfo(triggerSpell, caster.GetMap().GetDifficultyID()).HasAttribute(SpellAttr2.RetainItemCast)) + SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(triggerSpell, caster.GetMap().GetDifficultyID()); + if (!castItemGuid.IsEmpty() && spellInfo.HasAttribute(SpellAttr2.RetainItemCast)) { Player triggeringAuraCaster = caster?.ToPlayer(); if (triggeringAuraCaster != null) @@ -322,7 +323,7 @@ namespace Game.Spells // set basepoints for trigger with value effect if (effect == SpellEffectName.TriggerSpellWithValue) - for (int i = 0; i < SpellConst.MaxEffects; ++i) + for (int i = 0; i < spellInfo.GetEffects().Count; ++i) args.AddSpellMod(SpellValueMod.BasePoint0 + i, value); if (targetCount.HasValue) @@ -395,7 +396,7 @@ namespace Game.Spells args.SetCustomArg(m_customArg); // set basepoints for trigger with value effect if (effectInfo.Effect == SpellEffectName.TriggerMissileSpellWithValue) - for (int i = 0; i < SpellConst.MaxEffects; ++i) + for (int i = 0; i < spellInfo.GetEffects().Count; ++i) args.AddSpellMod(SpellValueMod.BasePoint0 + i, damage); if (targetCount.HasValue) @@ -468,7 +469,7 @@ namespace Game.Spells args.SetTriggeringSpell(this); // set basepoints for trigger with value effect if (effectInfo.Effect == SpellEffectName.ForceCastWithValue) - for (int i = 0; i < SpellConst.MaxEffects; ++i) + for (int i = 0; i < spellInfo.GetEffects().Count; ++i) args.AddSpellMod(SpellValueMod.BasePoint0 + i, damage); unitTarget.CastSpell(m_caster, spellInfo.Id, args);