Fixed setting and unsetting of m_spellModTakingSpell

Port From (https://github.com/TrinityCore/TrinityCore/commit/fb5c07ffe8d72d32a2c47cfa41dfb3a952160b72)
This commit is contained in:
hondacrx
2019-08-17 13:04:19 -04:00
parent f2f8afb7a4
commit 1e4b1366c2
4 changed files with 25 additions and 38 deletions
+2 -2
View File
@@ -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;
-7
View File
@@ -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;
+20 -26
View File
@@ -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)
+3 -3
View File
@@ -2749,7 +2749,7 @@ namespace Game.Spells
return RecoveryTime > CategoryRecoveryTime ? RecoveryTime : CategoryRecoveryTime;
}
public List<SpellPowerCost> CalcPowerCost(Unit caster, SpellSchoolMask schoolMask)
public List<SpellPowerCost> CalcPowerCost(Unit caster, SpellSchoolMask schoolMask, Spell spell = null)
{
List<SpellPowerCost> costs = new List<SpellPowerCost>();
@@ -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)