mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 09:44:45 +01:00
Core/Spells: Return CheckCast result from CastSpell (#23236)
* Return CheckCast result from CastSpell
* Return cast result from UnitAI methods too.
(cherry picked from commit 49d0a5bbb6)
This commit is contained in:
@@ -113,7 +113,7 @@ void UnitAI::SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectAg
|
||||
SelectTargetList(targetList, num, targetType, offset, DefaultTargetSelector(me, dist, playerOnly, withTank, aura));
|
||||
}
|
||||
|
||||
void UnitAI::DoCast(uint32 spellId)
|
||||
SpellCastResult UnitAI::DoCast(uint32 spellId)
|
||||
{
|
||||
Unit* target = nullptr;
|
||||
AITarget aiTargetType = AITARGET_SELF;
|
||||
@@ -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;}
|
||||
|
||||
@@ -309,11 +309,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); }
|
||||
|
||||
virtual bool ShouldSparWith(Unit const* /*target*/) const { return false; }
|
||||
|
||||
|
||||
@@ -2584,19 +2584,19 @@ bool WorldObject::IsNeutralToAll() const
|
||||
return my_faction->IsNeutralToAll();
|
||||
}
|
||||
|
||||
void WorldObject::CastSpell(CastSpellTargetArg const& targets, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
|
||||
SpellCastResult WorldObject::CastSpell(CastSpellTargetArg const& targets, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
|
||||
{
|
||||
SpellInfo const* info = sSpellMgr->GetSpellInfo(spellId, args.CastDifficulty != DIFFICULTY_NONE ? args.CastDifficulty : GetMap()->GetDifficultyID());
|
||||
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;
|
||||
}
|
||||
|
||||
if (!targets.Targets)
|
||||
{
|
||||
TC_LOG_ERROR("entities.unit", "CastSpell: Invalid target passed to spell cast %u by %s", spellId, GetGUID().ToString().c_str());
|
||||
return;
|
||||
return SPELL_FAILED_BAD_TARGETS;
|
||||
}
|
||||
|
||||
Spell* spell = new Spell(this, info, args.TriggerFlags, args.OriginalCaster, args.OriginalCastId);
|
||||
@@ -2604,7 +2604,7 @@ void WorldObject::CastSpell(CastSpellTargetArg const& targets, uint32 spellId, C
|
||||
spell->SetSpellValue(pair.first, pair.second);
|
||||
|
||||
spell->m_CastItem = args.CastItem;
|
||||
spell->prepare(*targets.Targets, args.TriggeringAura);
|
||||
return spell->prepare(*targets.Targets, args.TriggeringAura);
|
||||
}
|
||||
|
||||
// function based on function Unit::CanAttack from 13850 client
|
||||
|
||||
@@ -598,7 +598,7 @@ 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(CastSpellTargetArg const& targets, uint32 spellId, CastSpellExtraArgs const& args = { });
|
||||
SpellCastResult CastSpell(CastSpellTargetArg const& targets, 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;
|
||||
|
||||
@@ -3039,7 +3039,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)
|
||||
{
|
||||
@@ -3054,7 +3054,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
|
||||
{
|
||||
SendCastResult(SPELL_FAILED_EQUIPPED_ITEM);
|
||||
finish(false);
|
||||
return;
|
||||
return SPELL_FAILED_EQUIPPED_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3077,7 +3077,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)
|
||||
@@ -3085,7 +3085,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
|
||||
{
|
||||
SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS);
|
||||
finish(false);
|
||||
return;
|
||||
return SPELL_FAILED_SPELL_IN_PROGRESS;
|
||||
}
|
||||
|
||||
LoadScripts();
|
||||
@@ -3122,7 +3122,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
|
||||
SendCastResult(result);
|
||||
|
||||
finish(false);
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Prepare data for triggers
|
||||
@@ -3153,7 +3153,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered
|
||||
{
|
||||
SendCastResult(SPELL_FAILED_MOVING);
|
||||
finish(false);
|
||||
return;
|
||||
return SPELL_FAILED_MOVING;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3205,6 +3205,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()
|
||||
|
||||
@@ -432,7 +432,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();
|
||||
void update(uint32 difftime);
|
||||
void cast(bool skipCheck = false);
|
||||
|
||||
Reference in New Issue
Block a user