Core/Spells: Return CheckCast result from CastSpell

Port From (https://github.com/TrinityCore/TrinityCore/commit/ab988dc98284285b8ed0253f0bca1ddeb7eb9982)
This commit is contained in:
hondacrx
2021-12-07 17:31:24 -05:00
parent f9121d6fc9
commit 7c223b9a47
3 changed files with 30 additions and 23 deletions
+13 -9
View File
@@ -241,7 +241,7 @@ namespace Game.AI
return targetList; return targetList;
} }
public void DoCast(uint spellId) public SpellCastResult DoCast(uint spellId)
{ {
Unit target = null; Unit target = null;
AITarget aiTargetType = AITarget.Self; AITarget aiTargetType = AITarget.Self;
@@ -293,27 +293,31 @@ namespace Game.AI
} }
if (target != null) if (target != null)
me.CastSpell(target, spellId, false); return me.CastSpell(target, spellId, false);
return SpellCastResult.BadTargets;
} }
public void DoCast(Unit victim, uint spellId, CastSpellExtraArgs args = null) public SpellCastResult DoCast(Unit victim, uint spellId, CastSpellExtraArgs args = null)
{ {
if (me.HasUnitState(UnitState.Casting) && !args.TriggerFlags.HasAnyFlag(TriggerCastFlags.IgnoreCastInProgress)) if (me.HasUnitState(UnitState.Casting) && !args.TriggerFlags.HasAnyFlag(TriggerCastFlags.IgnoreCastInProgress))
return; return SpellCastResult.SpellInProgress;
me.CastSpell(victim, spellId, args); return me.CastSpell(victim, spellId, args);
} }
public void DoCastSelf(uint spellId, CastSpellExtraArgs args = null) { DoCast(me, spellId, args); } public SpellCastResult DoCastSelf(uint spellId, CastSpellExtraArgs args = null) { return DoCast(me, spellId, args); }
public void DoCastVictim(uint spellId, CastSpellExtraArgs args = null) public SpellCastResult DoCastVictim(uint spellId, CastSpellExtraArgs args = null)
{ {
Unit victim = me.GetVictim(); Unit victim = me.GetVictim();
if (victim != null) if (victim != null)
DoCast(victim, spellId, args); return DoCast(victim, spellId, args);
return SpellCastResult.BadTargets;
} }
public void DoCastAOE(uint spellId, CastSpellExtraArgs args = null) { DoCast(null, spellId, args); } public SpellCastResult DoCastAOE(uint spellId, CastSpellExtraArgs args = null) { return DoCast(null, spellId, args); }
public static void FillAISpellInfo() public static void FillAISpellInfo()
{ {
+9 -8
View File
@@ -2178,19 +2178,19 @@ namespace Game.Entities
return my_faction.IsNeutralToAll(); return my_faction.IsNeutralToAll();
} }
public void CastSpell(WorldObject target, uint spellId, bool triggered = false) public SpellCastResult CastSpell(WorldObject target, uint spellId, bool triggered = false)
{ {
CastSpellExtraArgs args = new(triggered); CastSpellExtraArgs args = new(triggered);
CastSpell(target, spellId, args); return CastSpell(target, spellId, args);
} }
public void CastSpell(SpellCastTargets targets, uint spellId, CastSpellExtraArgs args) public SpellCastResult CastSpell(SpellCastTargets targets, uint spellId, CastSpellExtraArgs args)
{ {
SpellInfo info = Global.SpellMgr.GetSpellInfo(spellId, args.CastDifficulty != Difficulty.None ? args.CastDifficulty : GetMap().GetDifficultyID()); SpellInfo info = Global.SpellMgr.GetSpellInfo(spellId, args.CastDifficulty != Difficulty.None ? args.CastDifficulty : GetMap().GetDifficultyID());
if (info == null) if (info == null)
{ {
Log.outError(LogFilter.Unit, $"CastSpell: unknown spell {spellId} by caster {GetGUID()}"); Log.outError(LogFilter.Unit, $"CastSpell: unknown spell {spellId} by caster {GetGUID()}");
return; return SpellCastResult.SpellUnavailable;
} }
Spell spell = new(this, info, args.TriggerFlags, args.OriginalCaster, args.OriginalCastId); Spell spell = new(this, info, args.TriggerFlags, args.OriginalCaster, args.OriginalCastId);
@@ -2198,10 +2198,10 @@ namespace Game.Entities
spell.SetSpellValue(pair.Key, pair.Value); spell.SetSpellValue(pair.Key, pair.Value);
spell.m_CastItem = args.CastItem; spell.m_CastItem = args.CastItem;
spell.Prepare(targets, args.TriggeringAura); return spell.Prepare(targets, args.TriggeringAura);
} }
public void CastSpell(WorldObject target, uint spellId, CastSpellExtraArgs args) public SpellCastResult CastSpell(WorldObject target, uint spellId, CastSpellExtraArgs args)
{ {
SpellCastTargets targets = new(); SpellCastTargets targets = new();
if (target) if (target)
@@ -2217,11 +2217,12 @@ namespace Game.Entities
else else
{ {
Log.outError(LogFilter.Unit, $"CastSpell: Invalid target {target.GetGUID()} passed to spell cast by {GetGUID()}"); Log.outError(LogFilter.Unit, $"CastSpell: Invalid target {target.GetGUID()} passed to spell cast by {GetGUID()}");
return; return SpellCastResult.BadTargets;
} }
} }
} }
CastSpell(targets, spellId, args);
return CastSpell(targets, spellId, args);
} }
public void CastSpell(Position dest, uint spellId, CastSpellExtraArgs args) public void CastSpell(Position dest, uint spellId, CastSpellExtraArgs args)
+8 -6
View File
@@ -2218,7 +2218,7 @@ namespace Game.Spells
return channelTargetEffectMask == 0; return channelTargetEffectMask == 0;
} }
public void Prepare(SpellCastTargets targets, AuraEffect triggeredByAura = null) public SpellCastResult Prepare(SpellCastTargets targets, AuraEffect triggeredByAura = null)
{ {
if (m_CastItem != null) if (m_CastItem != null)
{ {
@@ -2234,7 +2234,7 @@ namespace Game.Spells
{ {
SendCastResult(SpellCastResult.EquippedItem); SendCastResult(SpellCastResult.EquippedItem);
Finish(false); Finish(false);
return; return SpellCastResult.EquippedItem;
} }
} }
@@ -2257,7 +2257,7 @@ namespace Game.Spells
{ {
SendCastResult(SpellCastResult.SpellUnavailable); SendCastResult(SpellCastResult.SpellUnavailable);
Finish(false); Finish(false);
return; return SpellCastResult.SpellUnavailable;
} }
// Prevent casting at cast another spell (ServerSide check) // Prevent casting at cast another spell (ServerSide check)
@@ -2265,7 +2265,7 @@ namespace Game.Spells
{ {
SendCastResult(SpellCastResult.SpellInProgress); SendCastResult(SpellCastResult.SpellInProgress);
Finish(false); Finish(false);
return; return SpellCastResult.SpellInProgress;
} }
LoadScripts(); LoadScripts();
@@ -2302,7 +2302,7 @@ namespace Game.Spells
SendCastResult(result); SendCastResult(result);
Finish(false); Finish(false);
return; return result;
} }
// Prepare data for triggers // Prepare data for triggers
@@ -2333,7 +2333,7 @@ namespace Game.Spells
{ {
SendCastResult(SpellCastResult.Moving); SendCastResult(SpellCastResult.Moving);
Finish(false); Finish(false);
return; return SpellCastResult.Moving;
} }
} }
@@ -2387,6 +2387,8 @@ namespace Game.Spells
if (m_casttime == 0 && /*m_spellInfo.StartRecoveryTime == 0 && */ GetCurrentContainer() == CurrentSpellTypes.Generic) if (m_casttime == 0 && /*m_spellInfo.StartRecoveryTime == 0 && */ GetCurrentContainer() == CurrentSpellTypes.Generic)
Cast(true); Cast(true);
} }
return SpellCastResult.SpellCastOk;
} }
public void Cancel() public void Cancel()