Core/Spells: Refactor Spell::finish to accept SpellCastResult argument instead of just a bool indicating success

Port From (https://github.com/TrinityCore/TrinityCore/commit/a8bb1739e99c503fc72b3a4a9ecede214c88396f)
This commit is contained in:
hondacrx
2023-03-13 02:45:19 -04:00
parent 17b7e6837f
commit 138d0d2ed4
5 changed files with 31 additions and 31 deletions
+2 -2
View File
@@ -863,7 +863,7 @@ namespace Game.Entities
return SpellMissInfo.None; return SpellMissInfo.None;
} }
public void FinishSpell(CurrentSpellTypes spellType, bool ok = true) public void FinishSpell(CurrentSpellTypes spellType, SpellCastResult result = SpellCastResult.SpellCastOk)
{ {
Spell spell = GetCurrentSpell(spellType); Spell spell = GetCurrentSpell(spellType);
if (spell == null) if (spell == null)
@@ -872,7 +872,7 @@ namespace Game.Entities
if (spellType == CurrentSpellTypes.Channeled) if (spellType == CurrentSpellTypes.Channeled)
spell.SendChannelUpdate(0); spell.SendChannelUpdate(0);
spell.Finish(ok); spell.Finish(result);
} }
public virtual SpellInfo GetCastSpellInfo(SpellInfo spellInfo) public virtual SpellInfo GetCastSpellInfo(SpellInfo spellInfo)
+2 -2
View File
@@ -374,7 +374,7 @@ namespace Game
if (!pet.GetSpellHistory().HasCooldown(spellid)) if (!pet.GetSpellHistory().HasCooldown(spellid))
pet.GetSpellHistory().ResetCooldown(spellid, true); pet.GetSpellHistory().ResetCooldown(spellid, true);
spell.Finish(false); spell.Finish(result);
spell.Dispose(); spell.Dispose();
// reset specific flags in case of spell fail. AI will reset other flags // reset specific flags in case of spell fail. AI will reset other flags
@@ -730,7 +730,7 @@ namespace Game
if (!caster.GetSpellHistory().HasCooldown(spellInfo.Id)) if (!caster.GetSpellHistory().HasCooldown(spellInfo.Id))
caster.GetSpellHistory().ResetCooldown(spellInfo.Id, true); caster.GetSpellHistory().ResetCooldown(spellInfo.Id, true);
spell.Finish(false); spell.Finish(result);
spell.Dispose(); spell.Dispose();
} }
} }
+1 -1
View File
@@ -938,7 +938,7 @@ namespace Game.Scripting
public void FinishCast(SpellCastResult result, int? param1 = null, int? param2 = null) public void FinishCast(SpellCastResult result, int? param1 = null, int? param2 = null)
{ {
m_spell.SendCastResult(result, param1, param2); m_spell.SendCastResult(result, param1, param2);
m_spell.Finish(result == SpellCastResult.SpellCastOk); m_spell.Finish(result);
} }
public void SetCustomCastResultMessage(SpellCustomErrors result) public void SetCustomCastResultMessage(SpellCustomErrors result)
+1 -1
View File
@@ -1687,7 +1687,7 @@ namespace Game.Spells
// prevent interrupt message // prevent interrupt message
if (GetCasterGUID() == target.GetGUID() && target.GetCurrentSpell(CurrentSpellTypes.Generic) != null) if (GetCasterGUID() == target.GetGUID() && target.GetCurrentSpell(CurrentSpellTypes.Generic) != null)
target.FinishSpell(CurrentSpellTypes.Generic, false); target.FinishSpell(CurrentSpellTypes.Generic, SpellCastResult.Interrupted);
target.InterruptNonMeleeSpells(true); target.InterruptNonMeleeSpells(true);
// stop handling the effect if it was removed by linked event // stop handling the effect if it was removed by linked event
+25 -25
View File
@@ -270,7 +270,7 @@ namespace Game.Spells
if (noTargetFound) if (noTargetFound)
{ {
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
} }
@@ -281,7 +281,7 @@ namespace Game.Spells
if (!anyNonImmuneTargetFound) if (!anyNonImmuneTargetFound)
{ {
SendCastResult(SpellCastResult.Immune); SendCastResult(SpellCastResult.Immune);
Finish(false); Finish(SpellCastResult.Immune);
return; return;
} }
} }
@@ -293,7 +293,7 @@ namespace Game.Spells
if (focusObject == null && m_UniqueTargetInfo.Empty() && m_UniqueGOTargetInfo.Empty() && m_UniqueItemInfo.Empty() && !m_targets.HasDst()) if (focusObject == null && m_UniqueTargetInfo.Empty() && m_UniqueGOTargetInfo.Empty() && m_UniqueItemInfo.Empty() && !m_targets.HasDst())
{ {
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
@@ -582,7 +582,7 @@ namespace Game.Spells
else else
{ {
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
} }
return; return;
} }
@@ -602,7 +602,7 @@ namespace Game.Spells
else else
{ {
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
} }
return; return;
} }
@@ -617,7 +617,7 @@ namespace Game.Spells
{ {
Log.outDebug(LogFilter.Spells, "Spell.SelectImplicitNearbyTargets: cannot find nearby target for spell ID {0}, effect {1}", m_spellInfo.Id, spellEffectInfo.EffectIndex); Log.outDebug(LogFilter.Spells, "Spell.SelectImplicitNearbyTargets: cannot find nearby target for spell ID {0}, effect {1}", m_spellInfo.Id, spellEffectInfo.EffectIndex);
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
@@ -626,7 +626,7 @@ namespace Game.Spells
{ {
Log.outDebug(LogFilter.Spells, $"Spell.SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set NULL target, effect {spellEffectInfo.EffectIndex}"); Log.outDebug(LogFilter.Spells, $"Spell.SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set NULL target, effect {spellEffectInfo.EffectIndex}");
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
@@ -640,7 +640,7 @@ namespace Game.Spells
{ {
Log.outDebug(LogFilter.Spells, $"Spell.SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set object of wrong type, expected unit, got {target.GetGUID().GetHigh()}, effect {effMask}"); Log.outDebug(LogFilter.Spells, $"Spell.SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set object of wrong type, expected unit, got {target.GetGUID().GetHigh()}, effect {effMask}");
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
break; break;
@@ -652,7 +652,7 @@ namespace Game.Spells
{ {
Log.outDebug(LogFilter.Spells, $"Spell.SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set object of wrong type, expected gameobject, got {target.GetGUID().GetHigh()}, effect {effMask}"); Log.outDebug(LogFilter.Spells, $"Spell.SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set object of wrong type, expected gameobject, got {target.GetGUID().GetHigh()}, effect {effMask}");
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
break; break;
@@ -664,7 +664,7 @@ namespace Game.Spells
{ {
Log.outDebug(LogFilter.Spells, $"Spell::SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set object of wrong type, expected corpse, got {target.GetGUID().GetTypeId()}, effect {effMask}"); Log.outDebug(LogFilter.Spells, $"Spell::SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id {m_spellInfo.Id} set object of wrong type, expected corpse, got {target.GetGUID().GetTypeId()}, effect {effMask}");
SendCastResult(SpellCastResult.BadImplicitTargets); SendCastResult(SpellCastResult.BadImplicitTargets);
Finish(false); Finish(SpellCastResult.BadImplicitTargets);
return; return;
} }
break; break;
@@ -929,7 +929,7 @@ namespace Game.Spells
{ {
SendCastResult(SpellCastResult.NotHere); SendCastResult(SpellCastResult.NotHere);
SendChannelUpdate(0); SendChannelUpdate(0);
Finish(false); Finish(SpellCastResult.NotHere);
return; return;
} }
@@ -937,7 +937,7 @@ namespace Game.Spells
{ {
SendCastResult(SpellCastResult.TooShallow); SendCastResult(SpellCastResult.TooShallow);
SendChannelUpdate(0); SendChannelUpdate(0);
Finish(false); Finish(SpellCastResult.TooShallow);
return; return;
} }
@@ -2408,7 +2408,7 @@ namespace Game.Spells
else else
{ {
SendCastResult(SpellCastResult.EquippedItem); SendCastResult(SpellCastResult.EquippedItem);
Finish(false); Finish(SpellCastResult.EquippedItem);
return SpellCastResult.EquippedItem; return SpellCastResult.EquippedItem;
} }
} }
@@ -2431,7 +2431,7 @@ namespace Game.Spells
if (Global.DisableMgr.IsDisabledFor(DisableType.Spell, m_spellInfo.Id, m_caster)) if (Global.DisableMgr.IsDisabledFor(DisableType.Spell, m_spellInfo.Id, m_caster))
{ {
SendCastResult(SpellCastResult.SpellUnavailable); SendCastResult(SpellCastResult.SpellUnavailable);
Finish(false); Finish(SpellCastResult.SpellUnavailable);
return SpellCastResult.SpellUnavailable; return SpellCastResult.SpellUnavailable;
} }
@@ -2439,7 +2439,7 @@ namespace Game.Spells
if (!_triggeredCastFlags.HasFlag(TriggerCastFlags.IgnoreCastInProgress) && m_caster.ToUnit() != null && m_caster.ToUnit().IsNonMeleeSpellCast(false, true, true, m_spellInfo.Id == 75) && !m_castId.IsEmpty()) if (!_triggeredCastFlags.HasFlag(TriggerCastFlags.IgnoreCastInProgress) && m_caster.ToUnit() != null && m_caster.ToUnit().IsNonMeleeSpellCast(false, true, true, m_spellInfo.Id == 75) && !m_castId.IsEmpty())
{ {
SendCastResult(SpellCastResult.SpellInProgress); SendCastResult(SpellCastResult.SpellInProgress);
Finish(false); Finish(SpellCastResult.SpellInProgress);
return SpellCastResult.SpellInProgress; return SpellCastResult.SpellInProgress;
} }
@@ -2480,7 +2480,7 @@ namespace Game.Spells
if (GetCurrentContainer() == CurrentSpellTypes.AutoRepeat && m_caster.IsUnit()) if (GetCurrentContainer() == CurrentSpellTypes.AutoRepeat && m_caster.IsUnit())
m_caster.ToUnit().SetCurrentCastSpell(this); m_caster.ToUnit().SetCurrentCastSpell(this);
Finish(false); Finish(result);
return result; return result;
} }
@@ -2495,7 +2495,7 @@ namespace Game.Spells
if (result != SpellCastResult.SpellCastOk) if (result != SpellCastResult.SpellCastOk)
{ {
SendCastResult(result); SendCastResult(result);
Finish(false); Finish(result);
return result; return result;
} }
} }
@@ -2622,7 +2622,7 @@ namespace Game.Spells
//set state back so finish will be processed //set state back so finish will be processed
m_spellState = oldState; m_spellState = oldState;
Finish(false); Finish(SpellCastResult.Interrupted);
} }
public void Cast(bool skipCheck = false) public void Cast(bool skipCheck = false)
@@ -2711,7 +2711,7 @@ namespace Game.Spells
if (modOwner) if (modOwner)
modOwner.SetSpellModTakingSpell(this, false); modOwner.SetSpellModTakingSpell(this, false);
Finish(false); Finish(result);
SetExecutedCurrently(false); SetExecutedCurrently(false);
} }
@@ -2796,7 +2796,7 @@ namespace Game.Spells
if (m_caster.IsTypeId(TypeId.Player)) if (m_caster.IsTypeId(TypeId.Player))
m_caster.ToPlayer().SetSpellModTakingSpell(this, false); m_caster.ToPlayer().SetSpellModTakingSpell(this, false);
Finish(false); Finish(SpellCastResult.Interrupted);
SetExecutedCurrently(false); SetExecutedCurrently(false);
return; return;
} }
@@ -3045,7 +3045,7 @@ namespace Game.Spells
TakeCastItem(); TakeCastItem();
if (m_spellState != SpellState.Casting) if (m_spellState != SpellState.Casting)
Finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell) Finish(); // successfully finish spell cast (not last in case autorepeat or channel spell)
} }
public ulong HandleDelayed(ulong offset) public ulong HandleDelayed(ulong offset)
@@ -3053,7 +3053,7 @@ namespace Game.Spells
if (!UpdatePointers()) if (!UpdatePointers())
{ {
// finish the spell if UpdatePointers() returned false, something wrong happened there // finish the spell if UpdatePointers() returned false, something wrong happened there
Finish(false); Finish(SpellCastResult.NoValidTargets);
return 0; return 0;
} }
@@ -3145,7 +3145,7 @@ namespace Game.Spells
// spell is finished, perform some last features of the spell here // spell is finished, perform some last features of the spell here
_handle_finish_phase(); _handle_finish_phase();
Finish(true); // successfully finish spell cast Finish(); // successfully finish spell cast
// return zero, spell is finished now // return zero, spell is finished now
return 0; return 0;
@@ -3332,7 +3332,7 @@ namespace Game.Spells
} }
} }
public void Finish(bool ok = true) public void Finish(SpellCastResult result = SpellCastResult.SpellCastOk)
{ {
if (m_spellState == SpellState.Finished) if (m_spellState == SpellState.Finished)
return; return;
@@ -3373,7 +3373,7 @@ namespace Game.Spells
if (!m_spellInfo.HasAttribute(SpellAttr3.SuppressCasterProcs)) if (!m_spellInfo.HasAttribute(SpellAttr3.SuppressCasterProcs))
Unit.ProcSkillsAndAuras(unitCaster, null, new ProcFlagsInit(ProcFlags.CastEnded), new ProcFlagsInit(), ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, this, null, null); Unit.ProcSkillsAndAuras(unitCaster, null, new ProcFlagsInit(ProcFlags.CastEnded), new ProcFlagsInit(), ProcFlagsSpellType.MaskAll, ProcFlagsSpellPhase.None, ProcFlagsHit.None, this, null, null);
if (!ok) if (result != SpellCastResult.SpellCastOk)
{ {
// on failure (or manual cancel) send TraitConfigCommitFailed to revert talent UI saved config selection // on failure (or manual cancel) send TraitConfigCommitFailed to revert talent UI saved config selection
if (m_caster.IsPlayer() && m_spellInfo.HasEffect(SpellEffectName.ChangeActiveCombatTraitConfig)) if (m_caster.IsPlayer() && m_spellInfo.HasEffect(SpellEffectName.ChangeActiveCombatTraitConfig))