refactor(Core/Spells): make DoCast functions use SpellCastResult (#11546)

* refactor(Core/Spells): make DoCast use SpellCastResult

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update UnitAI.cpp

* Update UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.cpp

* Update src/server/game/AI/CoreAI/UnitAI.h
This commit is contained in:
Kitzunu
2022-05-06 05:43:27 +02:00
committed by GitHub
parent 6cf82e3bd6
commit 2e13ad75e2
2 changed files with 63 additions and 43 deletions

View File

@@ -106,7 +106,7 @@ float UnitAI::DoGetSpellMaxRange(uint32 spellId, bool positive)
return spellInfo ? spellInfo->GetMaxRange(positive) : 0;
}
void UnitAI::DoAddAuraToAllHostilePlayers(uint32 spellid)
SpellCastResult UnitAI::DoAddAuraToAllHostilePlayers(uint32 spellid)
{
if (me->IsInCombat())
{
@@ -114,13 +114,22 @@ void UnitAI::DoAddAuraToAllHostilePlayers(uint32 spellid)
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
{
if (Unit* unit = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid()))
{
if (unit->GetTypeId() == TYPEID_PLAYER)
{
me->AddAura(spellid, unit);
return SPELL_CAST_OK;
}
}
else
return SPELL_FAILED_BAD_TARGETS;
}
}
return SPELL_FAILED_CUSTOM_ERROR;
}
void UnitAI::DoCastToAllHostilePlayers(uint32 spellid, bool triggered)
SpellCastResult UnitAI::DoCastToAllHostilePlayers(uint32 spellid, bool triggered)
{
if (me->IsInCombat())
{
@@ -128,13 +137,19 @@ void UnitAI::DoCastToAllHostilePlayers(uint32 spellid, bool triggered)
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
{
if (Unit* unit = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid()))
{
if (unit->GetTypeId() == TYPEID_PLAYER)
me->CastSpell(unit, spellid, triggered);
return me->CastSpell(unit, spellid, triggered);
}
else
return SPELL_FAILED_BAD_TARGETS;
}
}
return SPELL_FAILED_CUSTOM_ERROR;
}
void UnitAI::DoCast(uint32 spellId)
SpellCastResult UnitAI::DoCast(uint32 spellId)
{
Unit* target = nullptr;
@@ -149,10 +164,11 @@ void UnitAI::DoCast(uint32 spellId)
break;
case AITARGET_ENEMY:
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
bool playerOnly = spellInfo->HasAttribute(SPELL_ATTR3_ONLY_ON_PLAYER);
//float range = GetSpellMaxRange(spellInfo, false);
target = SelectTarget(SelectTargetMethod::Random, 0, spellInfo->GetMaxRange(false), playerOnly);
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
{
bool playerOnly = spellInfo->HasAttribute(SPELL_ATTR3_ONLY_ON_PLAYER);
target = SelectTarget(SelectTargetMethod::Random, 0, spellInfo->GetMaxRange(false), playerOnly);
}
break;
}
case AITARGET_ALLY:
@@ -163,59 +179,63 @@ void UnitAI::DoCast(uint32 spellId)
break;
case AITARGET_DEBUFF:
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
bool playerOnly = spellInfo->HasAttribute(SPELL_ATTR3_ONLY_ON_PLAYER);
float range = spellInfo->GetMaxRange(false);
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
{
bool playerOnly = spellInfo->HasAttribute(SPELL_ATTR3_ONLY_ON_PLAYER);
float range = spellInfo->GetMaxRange(false);
DefaultTargetSelector targetSelector(me, range, playerOnly, -(int32)spellId);
if (!(spellInfo->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_VICTIM)
&& targetSelector(me->GetVictim()))
target = me->GetVictim();
else
target = SelectTarget(SelectTargetMethod::Random, 0, targetSelector);
DefaultTargetSelector targetSelector(me, range, playerOnly, -(int32)spellId);
if (!(spellInfo->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_VICTIM)
&& targetSelector(me->GetVictim()))
target = me->GetVictim();
else
target = SelectTarget(SelectTargetMethod::Random, 0, targetSelector);
}
break;
}
}
if (target)
me->CastSpell(target, spellId, false);
return SPELL_FAILED_BAD_TARGETS;
}
void UnitAI::DoCast(Unit* victim, uint32 spellId, bool triggered)
SpellCastResult UnitAI::DoCast(Unit* victim, uint32 spellId, bool triggered)
{
if (!victim || (me->HasUnitState(UNIT_STATE_CASTING) && !triggered))
return;
if (!victim)
return SPELL_FAILED_BAD_TARGETS;
me->CastSpell(victim, spellId, triggered);
if (me->HasUnitState(UNIT_STATE_CASTING) && !triggered)
return SPELL_FAILED_SPELL_IN_PROGRESS;
return me->CastSpell(victim, spellId, triggered);
}
void UnitAI::DoCastVictim(uint32 spellId, bool triggered)
SpellCastResult UnitAI::DoCastVictim(uint32 spellId, bool triggered)
{
if (!me->GetVictim() || (me->HasUnitState(UNIT_STATE_CASTING) && !triggered))
return;
if (Unit* victim = me->GetVictim())
return DoCast(victim, spellId, triggered);
me->CastSpell(me->GetVictim(), spellId, triggered);
return SPELL_FAILED_BAD_TARGETS;
}
void UnitAI::DoCastAOE(uint32 spellId, bool triggered)
SpellCastResult UnitAI::DoCastAOE(uint32 spellId, bool triggered)
{
if (!triggered && me->HasUnitState(UNIT_STATE_CASTING))
return;
return SPELL_FAILED_SPELL_IN_PROGRESS;
me->CastSpell((Unit*)nullptr, spellId, triggered);
return me->CastSpell((Unit*)nullptr, spellId, triggered);
}
void UnitAI::DoCastRandomTarget(uint32 spellId, uint32 threatTablePosition, float dist, bool playerOnly, bool triggered)
SpellCastResult UnitAI::DoCastRandomTarget(uint32 spellId, uint32 threatTablePosition, float dist, bool playerOnly, bool triggered)
{
if (!triggered && me->HasUnitState(UNIT_STATE_CASTING))
{
return;
}
if (Unit* target = SelectTarget(SelectTargetMethod::Random, threatTablePosition, dist, playerOnly))
{
me->CastSpell(target, spellId, triggered);
return DoCast(target, spellId, triggered);
}
return SPELL_FAILED_BAD_TARGETS;
}
#define UPDATE_TARGET(a) {if (AIInfo->target<a) AIInfo->target=a;}

View File

@@ -317,14 +317,14 @@ public:
void AttackStartCaster(Unit* victim, float dist);
void DoAddAuraToAllHostilePlayers(uint32 spellid);
void DoCast(uint32 spellId);
void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
inline void DoCastSelf(uint32 spellId, bool triggered = false) { DoCast(me, spellId, triggered); }
void DoCastToAllHostilePlayers(uint32 spellid, bool triggered = false);
void DoCastVictim(uint32 spellId, bool triggered = false);
void DoCastAOE(uint32 spellId, bool triggered = false);
void DoCastRandomTarget(uint32 spellId, uint32 threatTablePosition = 0, float dist = 0.0f, bool playerOnly = true, bool triggered = false);
SpellCastResult DoAddAuraToAllHostilePlayers(uint32 spellid);
SpellCastResult DoCast(uint32 spellId);
SpellCastResult DoCast(Unit* victim, uint32 spellId, bool triggered = false);
SpellCastResult DoCastSelf(uint32 spellId, bool triggered = false) { return DoCast(me, spellId, triggered); }
SpellCastResult DoCastToAllHostilePlayers(uint32 spellid, bool triggered = false);
SpellCastResult DoCastVictim(uint32 spellId, bool triggered = false);
SpellCastResult DoCastAOE(uint32 spellId, bool triggered = false);
SpellCastResult DoCastRandomTarget(uint32 spellId, uint32 threatTablePosition = 0, float dist = 0.0f, bool playerOnly = true, bool triggered = false);
float DoGetSpellMaxRange(uint32 spellId, bool positive = false);