Core/Spells: Return CheckCast result from CastSpell (#23236)

* Return CheckCast result from CastSpell

* Return cast result from UnitAI methods too.
This commit is contained in:
brotalnia authored and Ovahlord committed 2022-09-12 09:15:23 +02:00
1 parent 89d0f363cf
commit 7cc33f1bb7
6 files changed
+35 -35

No files matched your search

+11 -7
View File
@@ -116,7 +116,7 @@ float UnitAI::DoGetSpellMaxRange(uint32 spellId, bool positive)
return spellInfo ? spellInfo->GetMaxRange(positive) : 0;
}
void UnitAI::DoCast(uint32 spellId)
SpellCastResult UnitAI::DoCast(uint32 spellId)
{
Unit* target = nullptr;
@@ -162,21 +162,25 @@ void UnitAI::DoCast(uint32 spellId)
}
if (target)
me->CastSpell(target, spellId, false);
return me->CastSpell(target, spellId, false);
return SPELL_FAILED_BAD_TARGETS;
}
void UnitAI::DoCast(Unit* victim, uint32 spellId, CastSpellExtraArgs const& args)
SpellCastResult UnitAI::DoCast(Unit* victim, uint32 spellId, CastSpellExtraArgs const& args)
{
if (me->HasUnitState(UNIT_STATE_CASTING) && !(args.TriggerFlags & TRIGGERED_IGNORE_CAST_IN_PROGRESS))
return;
return SPELL_FAILED_SPELL_IN_PROGRESS;
me->CastSpell(victim, spellId, args);
return me->CastSpell(victim, spellId, args);
}
void UnitAI::DoCastVictim(uint32 spellId, CastSpellExtraArgs const& args)
SpellCastResult UnitAI::DoCastVictim(uint32 spellId, CastSpellExtraArgs const& args)
{
if (Unit* victim = me->GetVictim())
DoCast(victim, spellId, args);
return DoCast(victim, spellId, args);
return SPELL_FAILED_BAD_TARGETS;
}
#define UPDATE_TARGET(a) {if (AIInfo->target<a) AIInfo->target=a;}
+5 -5
View File
@@ -308,11 +308,11 @@ class TC_GAME_API UnitAI
void AttackStartCaster(Unit* victim, float dist);
void DoCast(uint32 spellId);
void DoCast(Unit* victim, uint32 spellId, CastSpellExtraArgs const& args = {});
void DoCastSelf(uint32 spellId, CastSpellExtraArgs const& args = {}) { DoCast(me, spellId, args); }
void DoCastVictim(uint32 spellId, CastSpellExtraArgs const& args = {});
void DoCastAOE(uint32 spellId, CastSpellExtraArgs const& args = {}) { DoCast(nullptr, spellId, args); }
SpellCastResult DoCast(uint32 spellId);
SpellCastResult DoCast(Unit* victim, uint32 spellId, CastSpellExtraArgs const& args = {});
SpellCastResult DoCastSelf(uint32 spellId, CastSpellExtraArgs const& args = {}) { return DoCast(me, spellId, args); }
SpellCastResult DoCastVictim(uint32 spellId, CastSpellExtraArgs const& args = {});
SpellCastResult DoCastAOE(uint32 spellId, CastSpellExtraArgs const& args = {}) { return DoCast(nullptr, spellId, args); }
float DoGetSpellMaxRange(uint32 spellId, bool positive = false);
void DoMeleeAttackIfReady();
+8 -8
View File
@@ -2894,13 +2894,13 @@ bool WorldObject::IsNeutralToAll() const
return my_faction->IsNeutralToAll();
}
void WorldObject::CastSpell(SpellCastTargets const& targets, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
SpellCastResult WorldObject::CastSpell(SpellCastTargets const& targets, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
{
SpellInfo const* info = sSpellMgr->GetSpellInfo(spellId);
if (!info)
{
TC_LOG_ERROR("entities.unit", "CastSpell: unknown spell %u by caster %s", spellId, GetGUID().ToString().c_str());
return;
return SPELL_FAILED_SPELL_UNAVAILABLE;
}
Spell* spell = new Spell(this, info, args.TriggerFlags, args.OriginalCaster);
@@ -2908,10 +2908,10 @@ void WorldObject::CastSpell(SpellCastTargets const& targets, uint32 spellId, Cas
spell->SetSpellValue(pair.first, pair.second);
spell->m_CastItem = args.CastItem;
spell->prepare(targets, args.TriggeringAura);
return spell->prepare(targets, args.TriggeringAura);
}
void WorldObject::CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
SpellCastResult WorldObject::CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
{
SpellCastTargets targets;
if (target)
@@ -2923,17 +2923,17 @@ void WorldObject::CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraA
else
{
TC_LOG_ERROR("entities.unit", "CastSpell: Invalid target %s passed to spell cast by %s", target->GetGUID().ToString().c_str(), GetGUID().ToString().c_str());
return;
return SPELL_FAILED_BAD_TARGETS;
}
}
CastSpell(targets, spellId, args);
return CastSpell(targets, spellId, args);
}
void WorldObject::CastSpell(Position const& dest, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
SpellCastResult WorldObject::CastSpell(Position const& dest, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
{
SpellCastTargets targets;
targets.SetDst(dest);
CastSpell(targets, spellId, args);
return CastSpell(targets, spellId, args);
}
// function based on function Unit::CanAttack from 13850 client
+3 -3
View File
@@ -465,9 +465,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
bool IsNeutralToAll() const;
// CastSpell's third arg can be a variety of things - check out CastSpellExtraArgs' constructors!
void CastSpell(SpellCastTargets const& targets, uint32 spellId, CastSpellExtraArgs const& args = { });
void CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraArgs const& args = { });
void CastSpell(Position const& dest, uint32 spellId, CastSpellExtraArgs const& args = { });
SpellCastResult CastSpell(SpellCastTargets const& targets, uint32 spellId, CastSpellExtraArgs const& args = { });
SpellCastResult CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraArgs const& args = { });
SpellCastResult CastSpell(Position const& dest, uint32 spellId, CastSpellExtraArgs const& args = { });
bool IsValidAttackTarget(WorldObject const* target, SpellInfo const* bySpell = nullptr) const;
bool IsValidAssistTarget(WorldObject const* target, SpellInfo const* bySpell = nullptr) const;
+7 -11
View File
@@ -3138,7 +3138,7 @@ bool Spell::UpdateChanneledTargetList()
return channelTargetEffectMask == 0;
}
void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggeredByAura)
SpellCastResult Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggeredByAura)
{
if (m_CastItem)
{
@@ -3191,7 +3191,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
{
SendCastResult(SPELL_FAILED_SPELL_UNAVAILABLE);
finish(false);
return;
return SPELL_FAILED_SPELL_UNAVAILABLE;
}
// Prevent casting at cast another spell (ServerSide check)
@@ -3199,15 +3199,9 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
{
SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS);
finish(false);
return;
return SPELL_FAILED_SPELL_IN_PROGRESS;
}
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_SPELL, m_spellInfo->Id, m_caster))
{
SendCastResult(SPELL_FAILED_SPELL_UNAVAILABLE);
finish(false);
return;
}
LoadScripts();
// Fill cost data (do not use power for item casts)
@@ -3246,7 +3240,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
SendCastResult(result);
finish(false);
return;
return result;
}
// Prepare data for triggers
@@ -3278,7 +3272,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
{
SendCastResult(SPELL_FAILED_MOVING);
finish(false);
return;
return SPELL_FAILED_MOVING;
}
}
@@ -3332,6 +3326,8 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
if (!m_casttime && /*!m_spellInfo->StartRecoveryTime && */ GetCurrentContainer() == CURRENT_GENERIC_SPELL)
cast(true);
}
return SPELL_CAST_OK;
}
void Spell::cancel(Spell* interruptingSpell /* = nullptr */)
+1 -1
View File
@@ -440,7 +440,7 @@ class TC_GAME_API Spell
GameObject* SearchSpellFocus();
void prepare(SpellCastTargets const& targets, AuraEffect const* triggeredByAura = nullptr);
SpellCastResult prepare(SpellCastTargets const& targets, AuraEffect const* triggeredByAura = nullptr);
void cancel(Spell* interruptingSpell = nullptr);
void update(uint32 difftime);
void cast(bool skipCheck = false);