From 1b4567e4da6307ef1ab1a1598b6e358e6e1bb0f0 Mon Sep 17 00:00:00 2001 From: Shauren Date: Mon, 6 Apr 2026 18:28:41 +0200 Subject: [PATCH] Core/Auras: Split SpellModifierByClassMask into separate flat/pct types --- src/server/game/Entities/Player/Player.cpp | 19 +++---- src/server/game/Entities/Player/Player.h | 50 +++++++++++++++---- .../game/Spells/Auras/SpellAuraEffects.cpp | 38 +++----------- src/server/scripts/Spells/spell_dh.cpp | 8 +-- src/server/scripts/Spells/spell_shaman.cpp | 12 +---- 5 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 518289d5f0..1063a323d6 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -22734,7 +22734,7 @@ void Player::GetSpellModValues(SpellInfo const* spellInfo, SpellModOp op, Spell* if (!IsAffectedBySpellmod(spellInfo, mod, spell)) continue; - if (base < 10000.0 && static_cast(mod)->value <= -100) + if (base < 10000.0 && static_cast(mod)->value <= -100) { modInstantSpell = mod; break; @@ -22773,7 +22773,7 @@ void Player::GetSpellModValues(SpellInfo const* spellInfo, SpellModOp op, Spell* if (!IsAffectedBySpellmod(spellInfo, mod, spell)) continue; - if (static_cast(mod)->value >= 100) + if (static_cast(mod)->value >= 100) { modCritical = mod; break; @@ -22813,7 +22813,7 @@ void Player::GetSpellModValues(SpellInfo const* spellInfo, SpellModOp op, Spell* if (!applyCount) continue; - int32 value = static_cast(mod)->value; + int32 value = static_cast(mod)->value; if (value == 0) continue; @@ -22845,7 +22845,7 @@ void Player::GetSpellModValues(SpellInfo const* spellInfo, SpellModOp op, Spell* if (base + *flat == 0) continue; - int32 value = static_cast(mod)->value; + int32 value = static_cast(mod)->value; if (value == 0) continue; @@ -22946,7 +22946,7 @@ void Player::AddSpellMod(SpellModifier* mod, bool apply) auto itr = std::ranges::lower_bound(m_spellMods, std::make_pair(mod->op, SPELLMOD_FLAT), std::ranges::less(), [](SpellModifier const* sm) { return std::make_pair(sm->op, sm->type); }); while (itr != m_spellMods.end() && (*itr)->op == mod->op && (*itr)->type == SPELLMOD_FLAT) { - SpellModifierByClassMask const* spellMod = static_cast(*itr++); + SpellFlatModifierByClassMask const* spellMod = static_cast(*itr++); if (spellMod->mask[classIndex / 32] & (1u << (classIndex % 32))) modData.ModifierValue += spellMod->value; } @@ -22957,7 +22957,7 @@ void Player::AddSpellMod(SpellModifier* mod, bool apply) auto itr = std::ranges::lower_bound(m_spellMods, std::make_pair(mod->op, SPELLMOD_PCT), std::ranges::less(), [](SpellModifier const* sm) { return std::make_pair(sm->op, sm->type); }); while (itr != m_spellMods.end() && (*itr)->op == mod->op && (*itr)->type == SPELLMOD_PCT) { - SpellModifierByClassMask const* spellMod = static_cast(*itr++); + SpellPctModifierByClassMask const* spellMod = static_cast(*itr++); if (spellMod->mask[classIndex / 32] & (1u << (classIndex % 32))) modData.ModifierValue *= 1.0f + CalculatePct(1.0f, spellMod->value); } @@ -23051,9 +23051,6 @@ void Player::SendSpellModifiers() const for (SpellModifier const* mod : m_spellMods) { - if (mod->type != SPELLMOD_FLAT && mod->type != SPELLMOD_PCT) - continue; - switch (mod->type) { case SPELLMOD_FLAT: @@ -23066,7 +23063,7 @@ void Player::SendSpellModifiers() const for (std::size_t classIndex = mask.find_first(); classIndex != decltype(mask)::npos; classIndex = mask.find_next(classIndex)) { float& modifierValue = getOrCreateModifierData(flatModifier->ModifierData, classIndex, 0.0f); - modifierValue += static_cast(mod)->value; + modifierValue += static_cast(mod)->value; } break; case SPELLMOD_PCT: @@ -23079,7 +23076,7 @@ void Player::SendSpellModifiers() const for (std::size_t classIndex = mask.find_first(); classIndex != decltype(mask)::npos; classIndex = mask.find_next(classIndex)) { float& modifierValue = getOrCreateModifierData(pctModifier->ModifierData, classIndex, 1.0f); - modifierValue *= 1.0f + CalculatePct(1.0f, static_cast(mod)->value); + modifierValue *= 1.0f + CalculatePct(1.0f, static_cast(mod)->value); } break; default: diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 14a4c49cbc..254a31bca3 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -251,7 +251,8 @@ enum SpecResetType // Spell modifier (used for modify other spells) struct SpellModifier { - SpellModifier(Aura* _ownerAura) : op(SpellModOp::HealingAndDamage), type(SPELLMOD_FLAT), spellId(0), ownerAura(_ownerAura) { } + SpellModifier(SpellModOp _op, SpellModType _type, uint32 _spellId, Aura* _ownerAura) + : op(_op), type(_type), spellId(_spellId), ownerAura(_ownerAura) { } virtual ~SpellModifier() = default; SpellModOp op; @@ -263,22 +264,53 @@ struct SpellModifier struct SpellModifierByClassMask : SpellModifier { - SpellModifierByClassMask(Aura* _ownerAura) : SpellModifier(_ownerAura), value(0), mask() { } + SpellModifierByClassMask(SpellModOp _op, SpellModType _type, uint32 _spellId, Aura* _ownerAura, flag128 const& _mask) + : SpellModifier(_op, _type, _spellId, _ownerAura), mask(_mask) { } - int32 value; flag128 mask; }; -template -struct SpellModifierByLabel : SpellModifier +struct SpellFlatModifierByClassMask : SpellModifierByClassMask { - SpellModifierByLabel(Aura* _ownerAura) : SpellModifier(_ownerAura) { } + SpellFlatModifierByClassMask(SpellModOp _op, uint32 _spellId, Aura* _ownerAura, flag128 _mask) + : SpellModifierByClassMask(_op, SPELLMOD_FLAT, _spellId, _ownerAura, _mask) { } - T value; + int32 value = { }; }; -using SpellFlatModifierByLabel = SpellModifierByLabel; -using SpellPctModifierByLabel = SpellModifierByLabel; +struct SpellPctModifierByClassMask : SpellModifierByClassMask +{ + SpellPctModifierByClassMask(SpellModOp _op, uint32 _spellId, Aura* _ownerAura, flag128 _mask) + : SpellModifierByClassMask(_op, SPELLMOD_PCT, _spellId, _ownerAura, _mask) { } + + int32 value = { }; +}; + +struct SpellFlatModifierByLabel : SpellModifier +{ + SpellFlatModifierByLabel(SpellModOp _op, uint32 _spellId, Aura* _ownerAura, uint32 _label) + : SpellModifier(_op, SPELLMOD_LABEL_FLAT, _spellId, _ownerAura) + { + value.ModIndex = int32(_op); + value.ModifierValue = 0; + value.LabelID = _label; + } + + UF::SpellFlatModByLabel value = { }; +}; + +struct SpellPctModifierByLabel : SpellModifier +{ + SpellPctModifierByLabel(SpellModOp _op, uint32 _spellId, Aura* _ownerAura, int32 _label) + : SpellModifier(_op, SPELLMOD_LABEL_PCT, _spellId, _ownerAura) + { + value.ModIndex = int32(_op); + value.ModifierValue = 0.0f; + value.LabelID = _label; + } + + UF::SpellPctModByLabel value; +}; struct SpellModifierCompare { diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 0839c34182..69fb1b45e3 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -1006,45 +1006,23 @@ void AuraEffect::CalculateSpellMod() switch (GetAuraType()) { case SPELL_AURA_ADD_FLAT_MODIFIER: + if (!m_spellmod) + m_spellmod = new SpellFlatModifierByClassMask(SpellModOp(GetMiscValue()), GetId(), GetBase(), GetSpellEffectInfo().SpellClassMask); + static_cast(m_spellmod)->value = GetAmount(); + break; case SPELL_AURA_ADD_PCT_MODIFIER: if (!m_spellmod) - { - SpellModifierByClassMask* spellmod = new SpellModifierByClassMask(GetBase()); - spellmod->op = SpellModOp(GetMiscValue()); - - spellmod->type = GetAuraType() == SPELL_AURA_ADD_PCT_MODIFIER ? SPELLMOD_PCT : SPELLMOD_FLAT; - spellmod->spellId = GetId(); - spellmod->mask = GetSpellEffectInfo().SpellClassMask; - m_spellmod = spellmod; - } - static_cast(m_spellmod)->value = GetAmount(); + m_spellmod = new SpellPctModifierByClassMask(SpellModOp(GetMiscValue()), GetId(), GetBase(), GetSpellEffectInfo().SpellClassMask); + static_cast(m_spellmod)->value = GetAmount(); break; case SPELL_AURA_ADD_FLAT_MODIFIER_BY_SPELL_LABEL: if (!m_spellmod) - { - SpellFlatModifierByLabel* spellmod = new SpellFlatModifierByLabel(GetBase()); - spellmod->op = SpellModOp(GetMiscValue()); - - spellmod->type = SPELLMOD_LABEL_FLAT; - spellmod->spellId = GetId(); - spellmod->value.ModIndex = GetMiscValue(); - spellmod->value.LabelID = GetMiscValueB(); - m_spellmod = spellmod; - } + m_spellmod = new SpellFlatModifierByLabel(SpellModOp(GetMiscValue()), GetId(), GetBase(), GetMiscValueB()); static_cast(m_spellmod)->value.ModifierValue = GetAmount(); break; case SPELL_AURA_ADD_PCT_MODIFIER_BY_SPELL_LABEL: if (!m_spellmod) - { - SpellPctModifierByLabel* spellmod = new SpellPctModifierByLabel(GetBase()); - spellmod->op = SpellModOp(GetMiscValue()); - - spellmod->type = SPELLMOD_LABEL_PCT; - spellmod->spellId = GetId(); - spellmod->value.ModIndex = GetMiscValue(); - spellmod->value.LabelID = GetMiscValueB(); - m_spellmod = spellmod; - } + m_spellmod = new SpellPctModifierByLabel(SpellModOp(GetMiscValue()), GetId(), GetBase(), GetMiscValueB()); static_cast(m_spellmod)->value.ModifierValue = 1.0f + CalculatePct(1.0f, GetAmount()); break; default: diff --git a/src/server/scripts/Spells/spell_dh.cpp b/src/server/scripts/Spells/spell_dh.cpp index f26e68c357..522ae2aabf 100644 --- a/src/server/scripts/Spells/spell_dh.cpp +++ b/src/server/scripts/Spells/spell_dh.cpp @@ -2311,12 +2311,8 @@ class spell_dh_soul_furnace_conduit : public AuraScript { if (!spellMod) { - spellMod = new SpellModifierByClassMask(GetAura()); - spellMod->op = SpellModOp::HealingAndDamage; - spellMod->type = SPELLMOD_PCT; - spellMod->spellId = GetId(); - static_cast(spellMod)->mask = flag128(0x80000000); - static_cast(spellMod)->value = GetEffect(EFFECT_1)->GetAmount() + 1; + spellMod = new SpellPctModifierByClassMask(SpellModOp::HealingAndDamage, GetId(), GetAura(), flag128(0x80000000)); + static_cast(spellMod)->value = GetEffect(EFFECT_1)->GetAmount() + 1; } } } diff --git a/src/server/scripts/Spells/spell_shaman.cpp b/src/server/scripts/Spells/spell_shaman.cpp index cd6098d0af..37ac7da248 100644 --- a/src/server/scripts/Spells/spell_shaman.cpp +++ b/src/server/scripts/Spells/spell_shaman.cpp @@ -1322,20 +1322,12 @@ class spell_sha_hailstorm : public AuraScript void CalcCleaveMod(AuraEffect const* aurEff, SpellModifier*& spellMod) const { if (!spellMod) - { - SpellModifierByClassMask* mod = new SpellModifierByClassMask(GetAura()); - mod->op = SpellModOp::ChainTargets; - mod->type = SPELLMOD_FLAT; - mod->spellId = GetId(); - mod->mask = { 0x80000000, 0x00000000, 0x00000000, 0x00000000 }; - - spellMod = mod; - } + spellMod = new SpellFlatModifierByClassMask(SpellModOp::ChainTargets, GetId(), GetAura(), { 0x80000000, 0x00000000, 0x00000000, 0x00000000 }); if (AuraEffect const* hailstormPassive = GetUnitOwner()->GetAuraEffect(SPELL_SHAMAN_HAILSTORM_TALENT, EFFECT_0)) { int32 targetCap = hailstormPassive->GetAmount() / aurEff->GetBaseAmount(); - static_cast(spellMod)->value = std::min(targetCap, GetStackAmount()) + 1; + static_cast(spellMod)->value = std::min(targetCap, GetStackAmount()) + 1; } }