From 55577ad85bb9dd5588f120dc818e6dc4cefe215d Mon Sep 17 00:00:00 2001 From: ariel- Date: Sat, 3 Sep 2022 09:40:24 +0200 Subject: [PATCH] Core/Spells: Fix some issues with channeled spells and aura duration mods --- src/server/game/Spells/Auras/SpellAuras.cpp | 4 +- src/server/game/Spells/Auras/SpellAuras.h | 3 +- src/server/game/Spells/Spell.cpp | 95 +++++++++++---------- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index da639116c3..b1aed03bdb 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -858,9 +858,9 @@ void Aura::Update(uint32 diff, Unit* caster) } } -int32 Aura::CalcMaxDuration(Unit* caster) const +/*static*/ int32 Aura::CalcMaxDuration(SpellInfo const* spellInfo, WorldObject* caster) { - return m_spellInfo->CalcDuration(caster); + return spellInfo->CalcDuration(caster); } void Aura::SetDuration(int32 duration, bool withMods) diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h index 1206057343..278660054f 100644 --- a/src/server/game/Spells/Auras/SpellAuras.h +++ b/src/server/game/Spells/Auras/SpellAuras.h @@ -149,7 +149,8 @@ class TC_GAME_API Aura int32 GetMaxDuration() const { return m_maxDuration; } void SetMaxDuration(int32 duration) { m_maxDuration = duration; } int32 CalcMaxDuration() const { return CalcMaxDuration(GetCaster()); } - int32 CalcMaxDuration(Unit* caster) const; + int32 CalcMaxDuration(Unit* caster) const { return Aura::CalcMaxDuration(GetSpellInfo(), caster); } + static int32 CalcMaxDuration(SpellInfo const* spellInfo, WorldObject* caster); int32 GetDuration() const { return m_duration; } void SetDuration(int32 duration, bool withMods = false); int32_t GetRolledOverDuration() const { return m_rolledOverDuration; } diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index d16c1aa65d..7a916d0960 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -2934,7 +2934,7 @@ SpellMissInfo Spell::PreprocessSpellHit(Unit* unit, bool scaleAura, TargetInfo& } } - hitInfo.AuraDuration = hitInfo.AuraSpellInfo->GetMaxDuration(); + hitInfo.AuraDuration = Aura::CalcMaxDuration(hitInfo.AuraSpellInfo, origCaster); // unit is immune to aura if it was diminished to 0 duration if (!hitInfo.Positive && !unit->ApplyDiminishingToDuration(hitInfo.AuraSpellInfo, triggered, hitInfo.AuraDuration, origCaster, diminishLevel)) @@ -2973,53 +2973,52 @@ void Spell::DoSpellEffectHit(Unit* unit, uint8 effIndex, TargetInfo& hitInfo) .IsRefresh = &refresh; if (Aura* aura = Aura::TryRefreshStackOrCreate(createInfo)) + { _spellAura = aura->ToUnitAura(); + + // Set aura stack amount to desired value + if (m_spellValue->AuraStackAmount > 1) + { + if (!refresh) + _spellAura->SetStackAmount(m_spellValue->AuraStackAmount); + else + _spellAura->ModStackAmount(m_spellValue->AuraStackAmount); + } + + _spellAura->SetDiminishGroup(hitInfo.DRGroup); + + hitInfo.AuraDuration = caster->ModSpellDuration(hitInfo.AuraSpellInfo, unit, hitInfo.AuraDuration, hitInfo.Positive, _spellAura->GetEffectMask()); + + // Haste modifies duration of channeled spells + if (m_spellInfo->IsChanneled()) + caster->ModSpellDurationTime(hitInfo.AuraSpellInfo, hitInfo.AuraDuration, this); + // and duration of auras affected by SPELL_AURA_PERIODIC_HASTE + else if (m_originalCaster->HasAuraTypeWithAffectMask(SPELL_AURA_PERIODIC_HASTE, hitInfo.AuraSpellInfo) || m_spellInfo->HasAttribute(SPELL_ATTR8_HASTE_AFFECTS_DURATION)) + hitInfo.AuraDuration = int32(hitInfo.AuraDuration * m_originalCaster->GetFloatValue(UNIT_MOD_CAST_SPEED)); + + if (hitInfo.AuraDuration != _spellAura->GetMaxDuration()) + { + _spellAura->SetMaxDuration(hitInfo.AuraDuration); + _spellAura->SetDuration(hitInfo.AuraDuration); + } + + if (DynamicObject* dynObj = m_originalCaster->GetDynObject(m_spellInfo->Id)) + dynObj->SetDuration(hitInfo.AuraDuration); + + if (m_spellInfo->IsChanneled() && refresh && m_spellInfo->IsRollingDurationOver()) + { + SendChannelStart(_spellAura->GetMaxDuration() - _spellAura->GetRolledOverDuration()); + SendChannelUpdate(_spellAura->GetMaxDuration()); + + // A side-effect of SendChannelStart() is to set the spell's timer to the value passed as parameter. + // However for channeled dot clipping to work properly, we need to roll over the duration. + // So we need to re-update timer with a proper value. + m_timer = _spellAura->GetMaxDuration(); + } + } } else _spellAura->AddStaticApplication(unit, aura_effmask); - - if (_spellAura) - { - // Set aura stack amount to desired value - if (m_spellValue->AuraStackAmount > 1) - { - if (!refresh) - _spellAura->SetStackAmount(m_spellValue->AuraStackAmount); - else - _spellAura->ModStackAmount(m_spellValue->AuraStackAmount); - } - - _spellAura->SetDiminishGroup(hitInfo.DRGroup); - - hitInfo.AuraDuration = caster->ModSpellDuration(hitInfo.AuraSpellInfo, unit, hitInfo.AuraDuration, hitInfo.Positive, _spellAura->GetEffectMask()); - - // Haste modifies duration of channeled spells - if (m_spellInfo->IsChanneled()) - caster->ModSpellDurationTime(hitInfo.AuraSpellInfo, hitInfo.AuraDuration, this); - // and duration of auras affected by SPELL_AURA_PERIODIC_HASTE - else if (m_originalCaster->HasAuraTypeWithAffectMask(SPELL_AURA_PERIODIC_HASTE, hitInfo.AuraSpellInfo) || m_spellInfo->HasAttribute(SPELL_ATTR8_HASTE_AFFECTS_DURATION)) - hitInfo.AuraDuration = int32(hitInfo.AuraDuration * m_originalCaster->GetFloatValue(UNIT_MOD_CAST_SPEED)); - - if (hitInfo.AuraDuration != _spellAura->GetMaxDuration()) - { - _spellAura->SetMaxDuration(hitInfo.AuraDuration); - _spellAura->SetDuration(hitInfo.AuraDuration); - } - - if (DynamicObject* dynObj = m_originalCaster->GetDynObject(m_spellInfo->Id)) - dynObj->SetDuration(hitInfo.AuraDuration); - - if (m_spellInfo->IsChanneled() && refresh && m_spellInfo->IsRollingDurationOver()) - { - SendChannelStart(_spellAura->GetMaxDuration() - _spellAura->GetRolledOverDuration()); - SendChannelUpdate(_spellAura->GetMaxDuration()); - - // A side-effect of SendChannelStart() is to set the spell's timer to the value passed as parameter. - // However for channeled dot clipping to work properly, we need to roll over the duration. - // So we need to re-update timer with a proper value. - m_timer = _spellAura->GetMaxDuration(); - } - } } } @@ -3729,8 +3728,12 @@ void Spell::handle_immediate() m_spellState = SPELL_STATE_CASTING; - // GameObjects shouldn't cast channeled spells - ASSERT_NOTNULL(m_caster->ToUnit())->AddInterruptMask(m_spellInfo->ChannelInterruptFlags, m_spellInfo->ChannelInterruptFlags2); + if (duration != 0) + { + m_spellState = SPELL_STATE_CASTING; + // GameObjects shouldn't cast channeled spells + ASSERT_NOTNULL(m_caster->ToUnit())->AddInterruptMask(m_spellInfo->ChannelInterruptFlags, m_spellInfo->ChannelInterruptFlags2); + } } PrepareTargetProcessing();