From 1e4b1366c2b45e4ba2fb4bf73f3c21bf83939961 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 17 Aug 2019 13:04:19 -0400 Subject: [PATCH] Fixed setting and unsetting of m_spellModTakingSpell Port From (https://github.com/TrinityCore/TrinityCore/commit/fb5c07ffe8d72d32a2c47cfa41dfb3a952160b72) --- Source/Game/Entities/Player/Player.Spells.cs | 4 +- Source/Game/Entities/Player/Player.cs | 7 --- Source/Game/Spells/Spell.cs | 46 +++++++++----------- Source/Game/Spells/SpellInfo.cs | 6 +-- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/Source/Game/Entities/Player/Player.Spells.cs b/Source/Game/Entities/Player/Player.Spells.cs index 8a17791d9..9fd021d81 100644 --- a/Source/Game/Entities/Player/Player.Spells.cs +++ b/Source/Game/Entities/Player/Player.Spells.cs @@ -2969,10 +2969,10 @@ namespace Game.Entities public void SetSpellModTakingSpell(Spell spell, bool apply) { - if (spell == null || (m_spellModTakingSpell != null && m_spellModTakingSpell != spell)) + if (apply && m_spellModTakingSpell != null) return; - if (apply && spell.getState() == SpellState.Finished) + if (!apply && (m_spellModTakingSpell == null || m_spellModTakingSpell != spell)) return; m_spellModTakingSpell = apply ? spell : null; diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index c30c2e89d..4f8b1f67a 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -446,13 +446,6 @@ namespace Game.Entities // It will be recalculate at mailbox open (for unReadMails important non-0 until mailbox open, it also will be recalculated) 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 - if (m_spellModTakingSpell != null) - { - Log.outFatal(LogFilter.Spells, "Player has m_spellModTakingSpell {0} during update!", m_spellModTakingSpell.m_spellInfo.Id); - m_spellModTakingSpell = null; - } // Update cinematic location, if 500ms have passed and we're doing a cinematic now. _cinematicMgr.m_cinematicDiff += diff; diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 7f670fe01..c6f9438cc 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -2366,13 +2366,9 @@ namespace Game.Spells } LoadScripts(); - if (m_caster.IsTypeId(TypeId.Player)) - m_caster.ToPlayer().SetSpellModTakingSpell(this, true); // Fill cost data (not use power for item casts - if (!m_CastItem) - m_powerCost = m_spellInfo.CalcPowerCost(m_caster, m_spellSchoolMask); - if (m_caster.IsTypeId(TypeId.Player)) - m_caster.ToPlayer().SetSpellModTakingSpell(this, false); + if (m_CastItem) + m_powerCost = m_spellInfo.CalcPowerCost(m_caster, m_spellSchoolMask, this); // Set combo point requirement if (Convert.ToBoolean(_triggeredCastFlags & TriggerCastFlags.IgnoreComboPoints) || m_CastItem != null || m_caster.m_playerMovingMe == null) @@ -2396,11 +2392,6 @@ namespace Game.Spells triggeredByAura.GetBase().SetDuration(0); } - // cleanup after mod system - // triggered spell pointer can be not removed in some cases - if (m_caster.IsTypeId(TypeId.Player)) - m_caster.ToPlayer().SetSpellModTakingSpell(this, false); - if (param1 != 0 || param2 != 0) SendCastResult(result, param1, param2); else @@ -2417,9 +2408,8 @@ namespace Game.Spells { if (!m_caster.ToPlayer().GetCommandStatus(PlayerCommandStates.Casttime)) { - m_caster.ToPlayer().SetSpellModTakingSpell(this, true); + // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail) m_casttime = m_spellInfo.CalcCastTime(m_caster.getLevel(), this); - m_caster.ToPlayer().SetSpellModTakingSpell(this, false); } else m_casttime = 0; @@ -2554,6 +2544,23 @@ namespace Game.Spells } public void cast(bool skipCheck = false) + { + Player modOwner = m_caster.GetSpellModOwner(); + Spell lastSpellMod = null; + if (modOwner) + { + lastSpellMod = modOwner.m_spellModTakingSpell; + if (lastSpellMod) + modOwner.SetSpellModTakingSpell(lastSpellMod, false); + } + + _cast(skipCheck); + + if (lastSpellMod) + modOwner.SetSpellModTakingSpell(lastSpellMod, true); + } + + void _cast(bool skipCheck = false) { if (!UpdatePointers()) { @@ -2614,8 +2621,6 @@ namespace Game.Spells SendCastResult(castResult, param1, param2); SendInterrupted(0); - // cleanup after mod system - // triggered spell pointer can be not removed in some cases if (m_caster.IsTypeId(TypeId.Player)) m_caster.ToPlayer().SetSpellModTakingSpell(this, false); @@ -2640,7 +2645,6 @@ namespace Game.Spells SendCastResult(SpellCastResult.DontReport); SendInterrupted(0); - // cleanup after mod system m_caster.ToPlayer().SetSpellModTakingSpell(this, false); finish(false); @@ -2671,8 +2675,6 @@ namespace Game.Spells { SendInterrupted(0); - // cleanup after mod system - // triggered spell pointer can be not removed in some cases if (m_caster.IsTypeId(TypeId.Player)) m_caster.ToPlayer().SetSpellModTakingSpell(this, false); @@ -6613,15 +6615,7 @@ namespace Game.Spells } } - Player modOwner = m_caster.GetSpellModOwner(); - if (modOwner) - modOwner.SetSpellModTakingSpell(this, true); - targetInfo.crit = m_caster.IsSpellCrit(unit, m_spellInfo, m_spellSchoolMask, m_attackType); - - modOwner = m_caster.GetSpellModOwner(); - if (modOwner) - modOwner.SetSpellModTakingSpell(this, false); } SpellCastResult CanOpenLock(uint effIndex, uint lockId, ref SkillType skillId, ref int reqSkillValue, ref int skillValue) diff --git a/Source/Game/Spells/SpellInfo.cs b/Source/Game/Spells/SpellInfo.cs index 99e12320d..b8b7ec696 100644 --- a/Source/Game/Spells/SpellInfo.cs +++ b/Source/Game/Spells/SpellInfo.cs @@ -2749,7 +2749,7 @@ namespace Game.Spells return RecoveryTime > CategoryRecoveryTime ? RecoveryTime : CategoryRecoveryTime; } - public List CalcPowerCost(Unit caster, SpellSchoolMask schoolMask) + public List CalcPowerCost(Unit caster, SpellSchoolMask schoolMask, Spell spell = null) { List costs = new List(); @@ -2857,9 +2857,9 @@ namespace Game.Spells if (modOwner) { if (power.OrderIndex == 0) - modOwner.ApplySpellMod(Id, SpellModOp.Cost, ref powerCost); + modOwner.ApplySpellMod(Id, SpellModOp.Cost, ref powerCost, spell); else if (power.OrderIndex == 1) - modOwner.ApplySpellMod(Id, SpellModOp.SpellCost2, ref powerCost); + modOwner.ApplySpellMod(Id, SpellModOp.SpellCost2, ref powerCost, spell); } if (!caster.IsControlledByPlayer() && MathFunctions.fuzzyEq(power.PowerCostPct, 0.0f) && SpellLevel != 0)