diff options
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 11 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.h | 4 | ||||
-rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 66 | ||||
-rw-r--r-- | src/server/game/Spells/SpellScript.cpp | 2 |
4 files changed, 60 insertions, 23 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 3a8374cbdb6..6e57a17172f 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -579,7 +579,7 @@ m_caster((info->HasAttribute(SPELL_ATTR6_CAST_BY_CHARMER) && caster->GetCharmerO unitTarget = nullptr; itemTarget = nullptr; gameObjTarget = nullptr; - corpseTarget = nullptr; + m_corpseTarget = nullptr; destTarget = nullptr; damage = 0; targetMissInfo = SPELL_MISS_NONE; @@ -593,7 +593,6 @@ m_caster((info->HasAttribute(SPELL_ATTR6_CAST_BY_CHARMER) && caster->GetCharmerO m_cast_count = 0; m_glyphIndex = 0; m_triggeredByAuraSpell = nullptr; - unitCaster = nullptr; _spellAura = nullptr; _dynObjAura = nullptr; @@ -5074,9 +5073,8 @@ void Spell::HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGoT unitTarget = pUnitTarget; itemTarget = pItemTarget; gameObjTarget = pGoTarget; - corpseTarget = pCorpseTarget; + m_corpseTarget = pCorpseTarget; destTarget = &m_destTargets[i]._position; - unitCaster = m_originalCaster ? m_originalCaster : m_caster->ToUnit(); uint8 effect = m_spellInfo->Effects[i].Effect; ASSERT(effect < TOTAL_SPELL_EFFECTS); // checked at startup @@ -7433,6 +7431,11 @@ bool Spell::IsNeedSendToClient() const m_spellInfo->Speed > 0.0f || (!m_triggeredByAuraSpell && !IsTriggered()); } +Unit* Spell::GetUnitCasterForEffectHandlers() const +{ + return m_originalCaster ? m_originalCaster : m_caster->ToUnit(); +} + SpellEvent::SpellEvent(Spell* spell) : BasicEvent() { m_Spell = spell; diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 0c60aac51b4..320cfdd94f0 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -618,13 +618,13 @@ class TC_GAME_API Spell Unit* unitTarget; Item* itemTarget; GameObject* gameObjTarget; - Corpse* corpseTarget; + Corpse* m_corpseTarget; WorldLocation* destTarget; int32 damage; SpellMissInfo targetMissInfo; SpellEffectHandleMode effectHandleMode; // used in effects handlers - Unit* unitCaster; + Unit* GetUnitCasterForEffectHandlers() const; UnitAura* _spellAura; DynObjAura* _dynObjAura; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 99813bfd327..0eeb6f023f1 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -245,13 +245,13 @@ void Spell::EffectResurrectNew(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; - if (!corpseTarget && !unitTarget) + if (!m_corpseTarget && !unitTarget) return; Player* player = nullptr; - if (corpseTarget) - player = ObjectAccessor::FindPlayer(corpseTarget->GetOwnerGUID()); + if (m_corpseTarget) + player = ObjectAccessor::FindPlayer(m_corpseTarget->GetOwnerGUID()); else if (unitTarget) player = unitTarget->ToPlayer(); @@ -289,7 +289,7 @@ void Spell::EffectInstaKill(SpellEffIndex /*effIndex*/) data << uint32(m_spellInfo->Id); m_caster->SendMessageToSet(&data, true); - Unit::DealDamage(unitCaster, unitTarget, unitTarget->GetHealth(), nullptr, NODAMAGE, SPELL_SCHOOL_MASK_NORMAL, nullptr, false); + Unit::DealDamage(GetUnitCasterForEffectHandlers(), unitTarget, unitTarget->GetHealth(), nullptr, NODAMAGE, SPELL_SCHOOL_MASK_NORMAL, nullptr, false); } void Spell::EffectEnvironmentalDMG(SpellEffIndex /*effIndex*/) @@ -305,6 +305,7 @@ void Spell::EffectEnvironmentalDMG(SpellEffIndex /*effIndex*/) unitTarget->ToPlayer()->EnvironmentalDamage(DAMAGE_FIRE, damage); else { + Unit* unitCaster = GetUnitCasterForEffectHandlers(); DamageInfo damageInfo(unitCaster, unitTarget, damage, m_spellInfo, m_spellInfo->GetSchoolMask(), SPELL_DIRECT_DAMAGE, BASE_ATTACK); Unit::CalcAbsorbResist(damageInfo); @@ -323,6 +324,7 @@ void Spell::EffectSchoolDMG(SpellEffIndex effIndex) if (unitTarget && unitTarget->IsAlive()) { bool apply_direct_bonus = true; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); switch (m_spellInfo->SpellFamilyName) { case SPELLFAMILY_GENERIC: @@ -697,7 +699,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; - if (!unitTarget && !gameObjTarget && !itemTarget && !corpseTarget) + if (!unitTarget && !gameObjTarget && !itemTarget && !m_corpseTarget) return; // pet auras @@ -727,6 +729,7 @@ void Spell::EffectTriggerSpell(SpellEffIndex effIndex) if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_SPELL && effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET) { + Unit* unitCaster = GetUnitCasterForEffectHandlers(); // special cases switch (triggered_spell_id) { @@ -970,6 +973,7 @@ void Spell::EffectTriggerRitualOfSummoning(SpellEffIndex effIndex) void Spell::CalculateJumpSpeeds(SpellInfo const* spellInfo, uint8 i, float dist, float& speedXY, float& speedZ) { + Unit* unitCaster = GetUnitCasterForEffectHandlers(); float runSpeed = unitCaster->IsControlledByPlayer() ? playerBaseMoveSpeed[MOVE_RUN] : baseMoveSpeed[MOVE_RUN]; if (Creature* creature = unitCaster->ToCreature()) runSpeed *= creature->GetCreatureTemplate()->speed_run; @@ -1000,6 +1004,7 @@ void Spell::EffectJump(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -1019,6 +1024,7 @@ void Spell::EffectJumpDest(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -1111,6 +1117,7 @@ void Spell::EffectPowerDrain(SpellEffIndex effIndex) if (!unitTarget || !unitTarget->IsAlive() || unitTarget->GetPowerType() != powerType || damage < 0) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); // add spell damage bonus if (unitCaster) { @@ -1153,8 +1160,8 @@ void Spell::EffectSendEvent(SpellEffIndex effIndex) target = unitTarget; else if (gameObjTarget) target = gameObjTarget; - else if (corpseTarget) - target = corpseTarget; + else if (m_corpseTarget) + target = m_corpseTarget; } else // if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT) { @@ -1192,6 +1199,8 @@ void Spell::EffectPowerBurn(SpellEffIndex effIndex) if (!unitTarget || !unitTarget->IsAlive() || unitTarget->GetPowerType() != powerType || damage < 0) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); + // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn) ///@todo: move this to scripts if (unitCaster && m_spellInfo->Id == 8129) @@ -1227,6 +1236,8 @@ void Spell::EffectHeal(SpellEffIndex effIndex) if (!unitTarget || !unitTarget->IsAlive() || damage < 0) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); + // Skip if m_originalCaster not available if (!unitCaster) return; @@ -1310,7 +1321,7 @@ void Spell::EffectHealPct(SpellEffIndex effIndex) return; uint32 heal = unitTarget->CountPctFromMaxHealth(damage); - if (unitCaster) + if (Unit* unitCaster = GetUnitCasterForEffectHandlers()) { heal = unitCaster->SpellHealingBonusDone(unitTarget, m_spellInfo, heal, HEAL, effIndex, { }); heal = unitTarget->SpellHealingBonusTaken(unitCaster, m_spellInfo, heal, HEAL); @@ -1328,7 +1339,7 @@ void Spell::EffectHealMechanical(SpellEffIndex effIndex) return; uint32 heal = damage; - if (unitCaster) + if (Unit* unitCaster = GetUnitCasterForEffectHandlers()) { heal = unitCaster->SpellHealingBonusDone(unitTarget, m_spellInfo, heal, HEAL, effIndex, { }); heal = unitTarget->SpellHealingBonusTaken(unitCaster, m_spellInfo, heal, HEAL); @@ -1345,6 +1356,7 @@ void Spell::EffectHealthLeech(SpellEffIndex effIndex) if (!unitTarget || !unitTarget->IsAlive() || damage < 0) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (unitCaster) { damage = unitCaster->SpellDamageBonusDone(unitTarget, m_spellInfo, uint32(damage), SPELL_DIRECT_DAMAGE, effIndex, { }); @@ -1557,6 +1569,7 @@ void Spell::EffectPersistentAA(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -1602,6 +1615,7 @@ void Spell::EffectEnergize(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster || !unitTarget) return; @@ -1673,6 +1687,7 @@ void Spell::EffectEnergizePct(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster || !unitTarget) return; @@ -2032,6 +2047,8 @@ void Spell::EffectSummonType(SpellEffIndex effIndex) if (Player* modOwner = caster->GetSpellModOwner()) modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration); + Unit* unitCaster = GetUnitCasterForEffectHandlers(); + TempSummon* summon = nullptr; // determine how many units should be summoned @@ -2777,6 +2794,7 @@ void Spell::EffectTameCreature(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster || unitCaster->GetPetGUID()) return; @@ -2834,7 +2852,7 @@ void Spell::EffectSummonPet(SpellEffIndex effIndex) return; Player* owner = nullptr; - if (unitCaster) + if (Unit* unitCaster = GetUnitCasterForEffectHandlers()) { owner = unitCaster->ToPlayer(); if (!owner && unitCaster->IsTotem()) @@ -2947,6 +2965,7 @@ void Spell::EffectTaunt(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -2986,6 +3005,7 @@ void Spell::EffectWeaponDmg(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -3276,6 +3296,7 @@ void Spell::EffectThreat(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster || !unitCaster->IsAlive()) return; @@ -3293,6 +3314,7 @@ void Spell::EffectHealMaxHealth(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -3333,7 +3355,7 @@ void Spell::EffectInterruptCast(SpellEffIndex effIndex) && ((i == CURRENT_GENERIC_SPELL && curSpellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT) || (i == CURRENT_CHANNELED_SPELL && curSpellInfo->ChannelInterruptFlags & CHANNEL_INTERRUPT_FLAG_INTERRUPT))) { - if (unitCaster) + if (Unit* unitCaster = GetUnitCasterForEffectHandlers()) { int32 duration = m_spellInfo->GetDuration(); unitTarget->GetSpellHistory()->LockSpellSchool(curSpellInfo->GetSchoolMask(), unitTarget->ModSpellDuration(m_spellInfo, unitTarget, duration, false, 1 << effIndex)); @@ -3408,6 +3430,8 @@ void Spell::EffectScriptEffect(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); + /// @todo we must implement hunter pet summon at login there (spell 6962) /// @todo: move this to scripts switch (m_spellInfo->SpellFamilyName) @@ -3725,6 +3749,7 @@ void Spell::EffectSummonPlayer(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4016,6 +4041,7 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4070,13 +4096,13 @@ void Spell::EffectResurrect(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; - if (!corpseTarget && !unitTarget) + if (!m_corpseTarget && !unitTarget) return; Player* player = nullptr; - if (corpseTarget) - player = ObjectAccessor::FindPlayer(corpseTarget->GetOwnerGUID()); + if (m_corpseTarget) + player = ObjectAccessor::FindPlayer(m_corpseTarget->GetOwnerGUID()); else if (unitTarget) player = unitTarget->ToPlayer(); @@ -4196,6 +4222,7 @@ void Spell::EffectForceDeselect(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4292,6 +4319,7 @@ void Spell::EffectCharge(SpellEffIndex /*effIndex*/) if (!unitTarget) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4326,6 +4354,7 @@ void Spell::EffectChargeDest(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4617,6 +4646,7 @@ void Spell::EffectDestroyAllTotems(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4711,6 +4741,7 @@ void Spell::EffectModifyThreatPercent(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster || !unitTarget) return; @@ -4722,6 +4753,7 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -4927,8 +4959,8 @@ void Spell::EffectSkinPlayerCorpse(SpellEffIndex /*effIndex*/) Player* target = nullptr; if (unitTarget) target = unitTarget->ToPlayer(); - else if (corpseTarget) - target = ObjectAccessor::FindPlayer(corpseTarget->GetOwnerGUID()); + else if (m_corpseTarget) + target = ObjectAccessor::FindPlayer(m_corpseTarget->GetOwnerGUID()); if (!player || !target || target->IsAlive()) return; @@ -5205,6 +5237,7 @@ void Spell::EffectRedirectThreat(SpellEffIndex /*effIndex*/) if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; @@ -5251,6 +5284,7 @@ void Spell::EffectGameObjectSetDestructionState(SpellEffIndex effIndex) void Spell::SummonGuardian(uint32 i, uint32 entry, SummonPropertiesEntry const* properties, uint32 numGuardians) { + Unit* unitCaster = GetUnitCasterForEffectHandlers(); if (!unitCaster) return; diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index c5c274f4058..136b5a525b9 100644 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -558,7 +558,7 @@ Corpse* SpellScript::GetHitCorpse() const TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::GetHitCorpse was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return nullptr; } - return m_spell->corpseTarget; + return m_spell->m_corpseTarget; } WorldLocation* SpellScript::GetHitDest() const |