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:
@@ -863,7 +863,7 @@ namespace Game.Entities
|
||||
return SpellMissInfo.None;
|
||||
}
|
||||
|
||||
public void FinishSpell(CurrentSpellTypes spellType, bool ok = true)
|
||||
public void FinishSpell(CurrentSpellTypes spellType, SpellCastResult result = SpellCastResult.SpellCastOk)
|
||||
{
|
||||
Spell spell = GetCurrentSpell(spellType);
|
||||
if (spell == null)
|
||||
@@ -872,7 +872,7 @@ namespace Game.Entities
|
||||
if (spellType == CurrentSpellTypes.Channeled)
|
||||
spell.SendChannelUpdate(0);
|
||||
|
||||
spell.Finish(ok);
|
||||
spell.Finish(result);
|
||||
}
|
||||
|
||||
public virtual SpellInfo GetCastSpellInfo(SpellInfo spellInfo)
|
||||
|
||||
@@ -374,7 +374,7 @@ namespace Game
|
||||
if (!pet.GetSpellHistory().HasCooldown(spellid))
|
||||
pet.GetSpellHistory().ResetCooldown(spellid, true);
|
||||
|
||||
spell.Finish(false);
|
||||
spell.Finish(result);
|
||||
spell.Dispose();
|
||||
|
||||
// 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))
|
||||
caster.GetSpellHistory().ResetCooldown(spellInfo.Id, true);
|
||||
|
||||
spell.Finish(false);
|
||||
spell.Finish(result);
|
||||
spell.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -938,7 +938,7 @@ namespace Game.Scripting
|
||||
public void FinishCast(SpellCastResult result, int? param1 = null, int? param2 = null)
|
||||
{
|
||||
m_spell.SendCastResult(result, param1, param2);
|
||||
m_spell.Finish(result == SpellCastResult.SpellCastOk);
|
||||
m_spell.Finish(result);
|
||||
}
|
||||
|
||||
public void SetCustomCastResultMessage(SpellCustomErrors result)
|
||||
|
||||
@@ -1687,7 +1687,7 @@ namespace Game.Spells
|
||||
|
||||
// prevent interrupt message
|
||||
if (GetCasterGUID() == target.GetGUID() && target.GetCurrentSpell(CurrentSpellTypes.Generic) != null)
|
||||
target.FinishSpell(CurrentSpellTypes.Generic, false);
|
||||
target.FinishSpell(CurrentSpellTypes.Generic, SpellCastResult.Interrupted);
|
||||
target.InterruptNonMeleeSpells(true);
|
||||
|
||||
// stop handling the effect if it was removed by linked event
|
||||
|
||||
+25
-25
@@ -270,7 +270,7 @@ namespace Game.Spells
|
||||
if (noTargetFound)
|
||||
{
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -281,7 +281,7 @@ namespace Game.Spells
|
||||
if (!anyNonImmuneTargetFound)
|
||||
{
|
||||
SendCastResult(SpellCastResult.Immune);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.Immune);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,7 @@ namespace Game.Spells
|
||||
if (focusObject == null && m_UniqueTargetInfo.Empty() && m_UniqueGOTargetInfo.Empty() && m_UniqueItemInfo.Empty() && !m_targets.HasDst())
|
||||
{
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -582,7 +582,7 @@ namespace Game.Spells
|
||||
else
|
||||
{
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -602,7 +602,7 @@ namespace Game.Spells
|
||||
else
|
||||
{
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
}
|
||||
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);
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
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}");
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
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}");
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
return;
|
||||
}
|
||||
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}");
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
return;
|
||||
}
|
||||
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}");
|
||||
SendCastResult(SpellCastResult.BadImplicitTargets);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.BadImplicitTargets);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -929,7 +929,7 @@ namespace Game.Spells
|
||||
{
|
||||
SendCastResult(SpellCastResult.NotHere);
|
||||
SendChannelUpdate(0);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.NotHere);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -937,7 +937,7 @@ namespace Game.Spells
|
||||
{
|
||||
SendCastResult(SpellCastResult.TooShallow);
|
||||
SendChannelUpdate(0);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.TooShallow);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2408,7 +2408,7 @@ namespace Game.Spells
|
||||
else
|
||||
{
|
||||
SendCastResult(SpellCastResult.EquippedItem);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.EquippedItem);
|
||||
return SpellCastResult.EquippedItem;
|
||||
}
|
||||
}
|
||||
@@ -2431,7 +2431,7 @@ namespace Game.Spells
|
||||
if (Global.DisableMgr.IsDisabledFor(DisableType.Spell, m_spellInfo.Id, m_caster))
|
||||
{
|
||||
SendCastResult(SpellCastResult.SpellUnavailable);
|
||||
Finish(false);
|
||||
Finish(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())
|
||||
{
|
||||
SendCastResult(SpellCastResult.SpellInProgress);
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.SpellInProgress);
|
||||
return SpellCastResult.SpellInProgress;
|
||||
}
|
||||
|
||||
@@ -2480,7 +2480,7 @@ namespace Game.Spells
|
||||
if (GetCurrentContainer() == CurrentSpellTypes.AutoRepeat && m_caster.IsUnit())
|
||||
m_caster.ToUnit().SetCurrentCastSpell(this);
|
||||
|
||||
Finish(false);
|
||||
Finish(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2495,7 +2495,7 @@ namespace Game.Spells
|
||||
if (result != SpellCastResult.SpellCastOk)
|
||||
{
|
||||
SendCastResult(result);
|
||||
Finish(false);
|
||||
Finish(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2622,7 +2622,7 @@ namespace Game.Spells
|
||||
//set state back so finish will be processed
|
||||
m_spellState = oldState;
|
||||
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.Interrupted);
|
||||
}
|
||||
|
||||
public void Cast(bool skipCheck = false)
|
||||
@@ -2711,7 +2711,7 @@ namespace Game.Spells
|
||||
if (modOwner)
|
||||
modOwner.SetSpellModTakingSpell(this, false);
|
||||
|
||||
Finish(false);
|
||||
Finish(result);
|
||||
SetExecutedCurrently(false);
|
||||
}
|
||||
|
||||
@@ -2796,7 +2796,7 @@ namespace Game.Spells
|
||||
if (m_caster.IsTypeId(TypeId.Player))
|
||||
m_caster.ToPlayer().SetSpellModTakingSpell(this, false);
|
||||
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.Interrupted);
|
||||
SetExecutedCurrently(false);
|
||||
return;
|
||||
}
|
||||
@@ -3045,7 +3045,7 @@ namespace Game.Spells
|
||||
TakeCastItem();
|
||||
|
||||
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)
|
||||
@@ -3053,7 +3053,7 @@ namespace Game.Spells
|
||||
if (!UpdatePointers())
|
||||
{
|
||||
// finish the spell if UpdatePointers() returned false, something wrong happened there
|
||||
Finish(false);
|
||||
Finish(SpellCastResult.NoValidTargets);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3145,7 +3145,7 @@ namespace Game.Spells
|
||||
// spell is finished, perform some last features of the spell here
|
||||
_handle_finish_phase();
|
||||
|
||||
Finish(true); // successfully finish spell cast
|
||||
Finish(); // successfully finish spell cast
|
||||
|
||||
// return zero, spell is finished now
|
||||
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)
|
||||
return;
|
||||
@@ -3373,7 +3373,7 @@ namespace Game.Spells
|
||||
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);
|
||||
|
||||
if (!ok)
|
||||
if (result != SpellCastResult.SpellCastOk)
|
||||
{
|
||||
// on failure (or manual cancel) send TraitConfigCommitFailed to revert talent UI saved config selection
|
||||
if (m_caster.IsPlayer() && m_spellInfo.HasEffect(SpellEffectName.ChangeActiveCombatTraitConfig))
|
||||
|
||||
Reference in New Issue
Block a user