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)
This commit is contained in:
Hondacrx
2025-06-03 21:17:25 -04:00
parent c496da9da0
commit 52952deee3
5 changed files with 18 additions and 23 deletions
+4 -3
View File
@@ -2241,8 +2241,10 @@ namespace Game.Entities
RemoveOwnedAura(spellId, GetGUID()); RemoveOwnedAura(spellId, GetGUID());
SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellId, Difficulty.None);
// remove pet auras // 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); PetAura petSpell = Global.SpellMgr.GetPetAura(spellId, i);
if (petSpell != null) 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) // 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.IsPrimaryProfessionFirstRank())
if (spellInfo != null && spellInfo.IsPrimaryProfessionFirstRank())
{ {
uint freeProfs = GetFreePrimaryProfessionPoints() + 1; uint freeProfs = GetFreePrimaryProfessionPoints() + 1;
if (freeProfs <= WorldConfig.GetIntValue(WorldCfg.MaxPrimaryTradeSkill)) if (freeProfs <= WorldConfig.GetIntValue(WorldCfg.MaxPrimaryTradeSkill))
+1 -1
View File
@@ -112,7 +112,7 @@ namespace Game.Scripting
uint mask = 0; uint mask = 0;
if (_effIndex == SpellConst.EffectAll || _effIndex == SpellConst.EffectFirstFound) 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) if (_effIndex == SpellConst.EffectFirstFound && mask != 0)
return mask; return mask;
+7 -14
View File
@@ -826,12 +826,9 @@ namespace Game.Spells
m_timeCla = 1 * Time.InMilliseconds; m_timeCla = 1 * Time.InMilliseconds;
// also reset periodic counters // also reset periodic counters
for (byte i = 0; i < SpellConst.MaxEffects; ++i) foreach (AuraEffect aurEff in GetAuraEffects())
{
AuraEffect aurEff = GetEffect(i);
if (aurEff != null) if (aurEff != null)
aurEff.ResetTicks(); aurEff.ResetTicks();
}
} }
void RefreshTimers(bool resetPeriodicTimer) void RefreshTimers(bool resetPeriodicTimer)
@@ -851,12 +848,8 @@ namespace Game.Spells
RefreshDuration(); RefreshDuration();
Unit caster = GetCaster(); Unit caster = GetCaster();
for (byte i = 0; i < SpellConst.MaxEffects; ++i) foreach (AuraEffect aurEff in GetAuraEffects())
{ aurEff.CalculatePeriodic(caster, resetPeriodicTimer, false);
AuraEffect aurEff = GetEffect(i);
if (aurEff != null)
aurEff.CalculatePeriodic(caster, resetPeriodicTimer, false);
}
} }
public void SetCharges(int charges) public void SetCharges(int charges)
@@ -1807,10 +1800,10 @@ namespace Game.Spells
// At least one effect has to pass checks to proc aura // At least one effect has to pass checks to proc aura
uint procEffectMask = aurApp.GetEffectMask(); uint procEffectMask = aurApp.GetEffectMask();
for (byte i = 0; i < SpellConst.MaxEffects; ++i) foreach (AuraEffect aurEff in GetAuraEffects())
if ((procEffectMask & (1u << i)) != 0) if ((procEffectMask & (1u << (int)aurEff.GetEffIndex())) != 0)
if ((procEntry.DisableEffectsMask & (1u << i)) != 0 || !GetEffect(i).CheckEffectProc(aurApp, eventInfo)) if ((procEntry.DisableEffectsMask & (1u << (int)aurEff.GetEffIndex())) != 0 || !GetEffect(aurEff.GetEffIndex()).CheckEffectProc(aurApp, eventInfo))
procEffectMask &= ~(1u << i); procEffectMask &= ~(1u << (int)aurEff.GetEffIndex());
if (procEffectMask == 0) if (procEffectMask == 0)
return 0; return 0;
+1 -1
View File
@@ -5167,7 +5167,7 @@ namespace Game.Spells
{ {
CastSpellExtraArgs args = new(this); CastSpellExtraArgs args = new(this);
args.SetTriggerFlags(TriggerCastFlags.FullMask & ~(TriggerCastFlags.IgnorePowerCost | TriggerCastFlags.IgnoreReagentCost)); 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()); args.AddSpellMod(SpellValueMod.BasePoint0 + i, GetAmount());
triggerCaster.CastSpell(target, triggerSpellId, args); triggerCaster.CastSpell(target, triggerSpellId, args);
+5 -4
View File
@@ -313,7 +313,8 @@ namespace Game.Spells
args.SetOriginalCaster(originalCaster); args.SetOriginalCaster(originalCaster);
args.OriginalCastId = originalCastId; args.OriginalCastId = originalCastId;
args.OriginalCastItemLevel = itemLevel; 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(); Player triggeringAuraCaster = caster?.ToPlayer();
if (triggeringAuraCaster != null) if (triggeringAuraCaster != null)
@@ -322,7 +323,7 @@ namespace Game.Spells
// set basepoints for trigger with value effect // set basepoints for trigger with value effect
if (effect == SpellEffectName.TriggerSpellWithValue) 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); args.AddSpellMod(SpellValueMod.BasePoint0 + i, value);
if (targetCount.HasValue) if (targetCount.HasValue)
@@ -395,7 +396,7 @@ namespace Game.Spells
args.SetCustomArg(m_customArg); args.SetCustomArg(m_customArg);
// set basepoints for trigger with value effect // set basepoints for trigger with value effect
if (effectInfo.Effect == SpellEffectName.TriggerMissileSpellWithValue) 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); args.AddSpellMod(SpellValueMod.BasePoint0 + i, damage);
if (targetCount.HasValue) if (targetCount.HasValue)
@@ -468,7 +469,7 @@ namespace Game.Spells
args.SetTriggeringSpell(this); args.SetTriggeringSpell(this);
// set basepoints for trigger with value effect // set basepoints for trigger with value effect
if (effectInfo.Effect == SpellEffectName.ForceCastWithValue) 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); args.AddSpellMod(SpellValueMod.BasePoint0 + i, damage);
unitTarget.CastSpell(m_caster, spellInfo.Id, args); unitTarget.CastSpell(m_caster, spellInfo.Id, args);