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