From ae4b91bcf61bfe9ffeb1af868a9b6459f682db99 Mon Sep 17 00:00:00 2001 From: xinef1 Date: Sun, 19 Feb 2017 06:10:50 +0100 Subject: [PATCH] Fixed setting and unsetting of m_spellModTakingSpell --- src/server/game/Entities/Player/Player.cpp | 16 ++------- src/server/game/Spells/Spell.cpp | 42 ++++++++++------------ src/server/game/Spells/Spell.h | 1 + src/server/game/Spells/SpellInfo.cpp | 4 +-- src/server/game/Spells/SpellInfo.h | 6 ++-- 5 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index eaa9af716d..662bec42dd 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -1220,18 +1220,6 @@ void Player::Update(uint32 p_time) m_nextMailDelivereTime = 0; } - // If this is set during update SetSpellModTakingSpell call is missing somewhere in the code - // Having this would prevent more aura charges to be dropped, so let's crash - //ASSERT (!m_spellModTakingSpell); - if (m_spellModTakingSpell) - { - //TC_LOG_FATAL("entities.player", "Player has m_pad %u during update!", m_pad); - //if (m_spellModTakingSpell) - TC_LOG_FATAL("spells", "Player::Update: Player '%s' (%s) has m_spellModTakingSpell (SpellID: %u) during update!", - GetName().c_str(), GetGUID().ToString().c_str(), m_spellModTakingSpell->m_spellInfo->Id); - m_spellModTakingSpell = nullptr; - } - // Update cinematic location, if 500ms have passed and we're doing a cinematic now. _cinematicMgr->m_cinematicDiff += p_time; if (_cinematicMgr->m_activeCinematicCameraId != 0 && GetMSTimeDiffToNow(_cinematicMgr->m_lastCinematicCheck) > CINEMATIC_UPDATEDIFF) @@ -21325,10 +21313,10 @@ void Player::ApplyModToSpell(SpellModifier* mod, Spell* spell) void Player::SetSpellModTakingSpell(Spell* spell, bool apply) { - if (!spell || (m_spellModTakingSpell && m_spellModTakingSpell != spell)) + if (apply && m_spellModTakingSpell != nullptr) return; - if (apply && spell->getState() == SPELL_STATE_FINISHED) + if (!apply && (!m_spellModTakingSpell || m_spellModTakingSpell != spell)) return; m_spellModTakingSpell = apply ? spell : nullptr; diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 6adec7d244..c135651abc 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -2980,12 +2980,8 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered } LoadScripts(); - if (m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->ToPlayer()->SetSpellModTakingSpell(this, true); // Fill cost data (do not use power for item casts) - m_powerCost = m_CastItem ? 0 : m_spellInfo->CalcPowerCost(m_caster, m_spellSchoolMask); - if (m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); + m_powerCost = m_CastItem ? 0 : m_spellInfo->CalcPowerCost(m_caster, m_spellSchoolMask, this); // Set combo point requirement if ((_triggeredCastFlags & TRIGGERED_IGNORE_COMBO_POINTS) || m_CastItem || !m_caster->m_playerMovingMe) @@ -3009,11 +3005,6 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered triggeredByAura->GetBase()->SetDuration(0); } - // cleanup after mod system - // triggered spell pointer can be not removed in some cases - if (m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); - if (param1 || param2) SendCastResult(result, ¶m1, ¶m2); else @@ -3030,10 +3021,8 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered { if (!player->GetCommandStatus(CHEAT_CASTTIME)) { - player->SetSpellModTakingSpell(this, true); // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail) m_casttime = m_spellInfo->CalcCastTime(player->getLevel(), this); - player->SetSpellModTakingSpell(this, false); } else m_casttime = 0; // Set cast time to 0 if .cheat casttime is enabled. @@ -3163,6 +3152,23 @@ void Spell::cancel() } void Spell::cast(bool skipCheck) +{ + Player* modOwner = m_caster->GetSpellModOwner(); + Spell* lastSpellMod = nullptr; + if (modOwner) + { + lastSpellMod = modOwner->m_spellModTakingSpell; + if (lastSpellMod) + modOwner->SetSpellModTakingSpell(lastSpellMod, false); + } + + _cast(skipCheck); + + if (lastSpellMod) + modOwner->SetSpellModTakingSpell(lastSpellMod, true); +} + +void Spell::_cast(bool skipCheck) { // update pointers base at GUIDs to prevent access to non-existed already object if (!UpdatePointers()) @@ -3220,8 +3226,6 @@ void Spell::cast(bool skipCheck) SendCastResult(castResult, ¶m1, ¶m2); SendInterrupted(0); - // cleanup after mod system - // triggered spell pointer can be not removed in some cases if (m_caster->GetTypeId() == TYPEID_PLAYER) m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); @@ -3245,8 +3249,6 @@ void Spell::cast(bool skipCheck) SendCastResult(SPELL_FAILED_DONT_REPORT); SendInterrupted(0); - // cleanup after mod system - // triggered spell pointer can be not removed in some cases m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); finish(false); @@ -3272,8 +3274,6 @@ void Spell::cast(bool skipCheck) { SendInterrupted(0); - // cleanup after mod system - // triggered spell pointer can be not removed in some cases if (m_caster->GetTypeId() == TYPEID_PLAYER) m_caster->ToPlayer()->SetSpellModTakingSpell(this, false); @@ -7255,13 +7255,7 @@ void Spell::DoAllEffectOnLaunchTarget(TargetInfo& targetInfo, float* multiplier) } } - if (Player* modOwner = m_caster->GetSpellModOwner()) - modOwner->SetSpellModTakingSpell(this, true); - targetInfo.crit = m_caster->IsSpellCrit(unit, m_spellInfo, m_spellSchoolMask, m_attackType); - - if (Player* modOwner = m_caster->GetSpellModOwner()) - modOwner->SetSpellModTakingSpell(this, false); } SpellCastResult Spell::CanOpenLock(uint32 effIndex, uint32 lockId, SkillType& skillId, int32& reqSkillValue, int32& skillValue) diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 359506011e..49bdb1b7b9 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -526,6 +526,7 @@ class TC_GAME_API Spell bool HasGlobalCooldown() const; void TriggerGlobalCooldown(); void CancelGlobalCooldown(); + void _cast(bool skipCheck = false); void SendLoot(ObjectGuid guid, LootType loottype); std::pair GetMinMaxRange(bool strict) const; diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 2424f99008..3786f88f8b 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -3255,7 +3255,7 @@ uint32 SpellInfo::GetRecoveryTime() const return RecoveryTime > CategoryRecoveryTime ? RecoveryTime : CategoryRecoveryTime; } -int32 SpellInfo::CalcPowerCost(Unit const* caster, SpellSchoolMask schoolMask) const +int32 SpellInfo::CalcPowerCost(Unit const* caster, SpellSchoolMask schoolMask, Spell* spell) const { // Spell drain all exist power on cast (Only paladin lay of Hands) if (HasAttribute(SPELL_ATTR1_DRAIN_ALL_POWER)) @@ -3332,7 +3332,7 @@ int32 SpellInfo::CalcPowerCost(Unit const* caster, SpellSchoolMask schoolMask) c // Apply cost mod by spell if (Player* modOwner = caster->GetSpellModOwner()) - modOwner->ApplySpellMod(Id, powerCost); + modOwner->ApplySpellMod(Id, powerCost, spell); if (!caster->IsControlledByPlayer()) { diff --git a/src/server/game/Spells/SpellInfo.h b/src/server/game/Spells/SpellInfo.h index fa08a0c871..0af75d3643 100644 --- a/src/server/game/Spells/SpellInfo.h +++ b/src/server/game/Spells/SpellInfo.h @@ -538,17 +538,17 @@ class TC_GAME_API SpellInfo SpellSpecificType GetSpellSpecific() const; float GetMinRange(bool positive = false) const; - float GetMaxRange(bool positive = false, Unit* caster = NULL, Spell* spell = NULL) const; + float GetMaxRange(bool positive = false, Unit* caster = nullptr, Spell* spell = nullptr) const; int32 GetDuration() const; int32 GetMaxDuration() const; uint32 GetMaxTicks() const; - uint32 CalcCastTime(uint8 level = 0, Spell* spell = NULL) const; + uint32 CalcCastTime(uint8 level = 0, Spell* spell = nullptr) const; uint32 GetRecoveryTime() const; - int32 CalcPowerCost(Unit const* caster, SpellSchoolMask schoolMask) const; + int32 CalcPowerCost(Unit const* caster, SpellSchoolMask schoolMask, Spell* spell = nullptr) const; bool IsRanked() const; uint8 GetRank() const;