diff options
author | brotalnia <brotalnia@gmail.com> | 2019-05-10 19:58:26 +0300 |
---|---|---|
committer | Giacomo Pozzoni <giacomopoz@gmail.com> | 2019-05-10 18:58:26 +0200 |
commit | 49d0a5bbb69dd352bac0009625ded2c472b66805 (patch) | |
tree | c91c5805d02684b8f4b4166a0a4fb8eda31633fd /src | |
parent | b7d63b0331af55ea006f366cd56f42cad4dafd7f (diff) |
Core/Spells: Return CheckCast result from CastSpell (#23236)
* Return CheckCast result from CastSpell
* Return cast result from UnitAI methods too.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.cpp | 18 | ||||
-rw-r--r-- | src/server/game/AI/CoreAI/UnitAI.h | 10 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 16 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.h | 6 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 12 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.h | 2 |
6 files changed, 35 insertions, 29 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index 39d9a9b14dc..9581eea365c 100644 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -117,7 +117,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; @@ -164,21 +164,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;} diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index e28454cedaf..5929643a5bc 100644 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -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); diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index afb05f8c962..53fc92ed088 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2757,13 +2757,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); @@ -2771,10 +2771,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) @@ -2786,17 +2786,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 diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index f8981999f9f..8b8838a5028 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -442,9 +442,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; diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index aa7438fc091..af4a1f131fd 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -2929,7 +2929,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) { @@ -2982,7 +2982,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) @@ -2990,7 +2990,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(); @@ -3022,7 +3022,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered SendCastResult(result); finish(false); - return; + return result; } // Prepare data for triggers @@ -3051,7 +3051,7 @@ void Spell::prepare(SpellCastTargets const& targets, AuraEffect const* triggered { SendCastResult(SPELL_FAILED_MOVING); finish(false); - return; + return SPELL_FAILED_MOVING; } } @@ -3110,6 +3110,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() diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 9915a2384d9..c412ef3f2a2 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -415,7 +415,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); |