Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/game/PlayerBots/CombatBotBaseAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,61 @@ Player* CombatBotBaseAI::SelectBuffTarget(SpellEntry const* pSpellEntry) const
return nullptr;
}

Player* CombatBotBaseAI::SelectBuffTarget(SpellEntry const* pSingleSpellEntry, SpellEntry const* pGroupSpellEntry, SpellEntry const*& pSelectedSpellEntry) const
{
pSelectedSpellEntry = nullptr;

if (!pSingleSpellEntry && !pGroupSpellEntry)
return nullptr;

if (!pSingleSpellEntry)
{
pSelectedSpellEntry = pGroupSpellEntry;
return SelectBuffTarget(pGroupSpellEntry);
}

if (!pGroupSpellEntry)
{
pSelectedSpellEntry = pSingleSpellEntry;
return SelectBuffTarget(pSingleSpellEntry);
}

Player* pFirstMissingMember = nullptr;
uint8 missingMemberCount = 0;
Group* pGroup = me->GetGroup();
if (pGroup)
{
for (GroupReference* itr = pGroup->GetFirstMember(); itr != nullptr; itr = itr->next())
{
if (Player* pMember = itr->getSource())
{
if (!me->IsValidHelpfulTarget(pMember) ||
pMember->IsGameMaster() ||
!me->IsWithinLOSInMap(pMember) ||
!me->IsWithinDist(pMember, 30.0f) ||
!IsValidBuffTarget(pMember, pSingleSpellEntry) ||
!IsValidBuffTarget(pMember, pGroupSpellEntry))
continue;

if (!pFirstMissingMember)
pFirstMissingMember = pMember;

++missingMemberCount;
if (missingMemberCount > 1)
{
pSelectedSpellEntry = pGroupSpellEntry;
return pFirstMissingMember;
}
}
}
}

if (missingMemberCount == 1)
pSelectedSpellEntry = pSingleSpellEntry;

return pFirstMissingMember;
}

Player* CombatBotBaseAI::SelectDispelTarget(SpellEntry const* pSpellEntry) const
{
Group* pGroup = me->GetGroup();
Expand Down
1 change: 1 addition & 0 deletions src/game/PlayerBots/CombatBotBaseAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class CombatBotBaseAI : public PlayerBotAI
Unit* SelectHealTarget(float selfHealPercent = 100.0f, float groupHealPercent = 100.0f) const;
Unit* SelectPeriodicHealTarget(float selfHealPercent = 100.0f, float groupHealPercent = 100.0f) const;
Player* SelectBuffTarget(SpellEntry const* pSpellEntry) const;
Player* SelectBuffTarget(SpellEntry const* pSingleSpellEntry, SpellEntry const* pGroupSpellEntry, SpellEntry const*& pSelectedSpellEntry) const;
Player* SelectDispelTarget(SpellEntry const* pSpellEntry) const;
bool IsValidBuffTarget(Unit const* pTarget, SpellEntry const* pSpellEntry) const;
bool IsValidHealTarget(Unit const* pTarget, float healthPercent = 100.0f) const;
Expand Down
174 changes: 45 additions & 129 deletions src/game/PlayerBots/PartyBotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void PartyBotAI::CloneFromPlayer(Player const* pPlayer)
{
me->SatisfyItemRequirements(pItem->GetProto());
me->StoreNewItemInBestSlots(pItem->GetEntry(), 1, pItem->GetEnchantmentId(EnchantmentSlot(0)));
}
}
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ bool PartyBotAI::IsValidDistancingTarget(Unit* pTarget, Unit* pEnemy)
pTarget->GetDistance(pEnemy) >= 15.0f)
return true;
}

return false;
}

Expand Down Expand Up @@ -299,7 +299,7 @@ bool PartyBotAI::CanTryToCastSpell(Unit const* pTarget, SpellEntry const* pSpell
{
float const myThreat = pEnemy->GetThreatManager().getThreat(me);
float const victimThreat = pEnemy->GetThreatManager().getThreat(pEnemy->GetVictim());

if (victimThreat < (myThreat + me->GetMaxHealth()))
return false;
}
Expand Down Expand Up @@ -543,7 +543,7 @@ void PartyBotAI::AddToPlayerGroup()
me->RemoveFromGroup();

group->AddMember(me->GetObjectGuid(), me->GetName());
}
}
}

void PartyBotAI::OnPacketReceived(WorldPacket const* packet)
Expand Down Expand Up @@ -678,7 +678,7 @@ void PartyBotAI::UpdateAI(uint32 const diff)
m_receivedBgInvite = false;
return;
}

// Remain idle until we can join battleground.
return;
}
Expand Down Expand Up @@ -723,7 +723,7 @@ void PartyBotAI::UpdateAI(uint32 const diff)
me->CastSpell(me, PB_SPELL_HONORLESS_TARGET, true);
}
}

return;
}

Expand Down Expand Up @@ -851,7 +851,7 @@ void PartyBotAI::UpdateAI(uint32 const diff)
me->CastSpell(me, (*auraList.begin())->GetId(), true);
me->SetCheatOption(PLAYER_CHEAT_NO_CAST_TIME, oldStateCastTime);
me->SetCheatOption(PLAYER_CHEAT_NO_POWER, oldStatePower);
}
}
}
}
else if (me->IsMounted())
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void PartyBotAI::UpdateOutOfCombatAI_Paladin()
me->ClearTarget();
return;
}
}
}
}
}

Expand Down Expand Up @@ -1356,7 +1356,7 @@ void PartyBotAI::UpdateInCombatAI_Paladin()
if (DoCastSpell(me, m_spells.paladin.pBlessingOfFreedom) == SPELL_CAST_OK)
return;
}

if (GetRole() != ROLE_HEALER &&
me->GetHealthPercent() < 30.0f)
HealInjuredTarget(me);
Expand Down Expand Up @@ -1666,33 +1666,19 @@ void PartyBotAI::UpdateInCombatAI_Hunter()

void PartyBotAI::UpdateOutOfCombatAI_Mage()
{
if (m_spells.mage.pArcaneBrilliance)
SpellEntry const* pBuffSpell = nullptr;
if (Player* pTarget = SelectBuffTarget(m_spells.mage.pArcaneIntellect, m_spells.mage.pArcaneBrilliance, pBuffSpell))
{
if (CanTryToCastSpell(me, m_spells.mage.pArcaneBrilliance))
if (CanTryToCastSpell(pTarget, pBuffSpell))
{
if (DoCastSpell(me, m_spells.mage.pArcaneBrilliance) == SPELL_CAST_OK)
if (DoCastSpell(pTarget, pBuffSpell) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
else if (m_spells.mage.pArcaneIntellect)
{
if (Player* pTarget = SelectBuffTarget(m_spells.mage.pArcaneIntellect))
{
if (CanTryToCastSpell(pTarget, m_spells.mage.pArcaneIntellect))
{
if (DoCastSpell(pTarget, m_spells.mage.pArcaneIntellect) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
}

if (m_spells.mage.pIceArmor &&
CanTryToCastSpell(me, m_spells.mage.pIceArmor))
Expand Down Expand Up @@ -1875,7 +1861,7 @@ void PartyBotAI::UpdateInCombatAI_Mage()
{
if (DoCastSpell(me, m_spells.mage.pPresenceOfMind) == SPELL_CAST_OK)
return;
}
}

if (m_spells.mage.pScorch &&
(pVictim->GetHealthPercent() < 20.0f) &&
Expand Down Expand Up @@ -1925,95 +1911,42 @@ void PartyBotAI::UpdateInCombatAI_Mage()

void PartyBotAI::UpdateOutOfCombatAI_Priest()
{
if (m_spells.priest.pPrayerofFortitude)
SpellEntry const* pBuffSpell = nullptr;
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pPowerWordFortitude, m_spells.priest.pPrayerofFortitude, pBuffSpell))
{
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pPrayerofFortitude))
if (CanTryToCastSpell(pTarget, pBuffSpell))
{
if (CanTryToCastSpell(pTarget, m_spells.priest.pPrayerofFortitude))
if (DoCastSpell(pTarget, pBuffSpell) == SPELL_CAST_OK)
{
if (DoCastSpell(pTarget, m_spells.priest.pPrayerofFortitude) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
}
else if (m_spells.priest.pPowerWordFortitude)
{
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pPowerWordFortitude))
{
if (CanTryToCastSpell(pTarget, m_spells.priest.pPowerWordFortitude))
{
if (DoCastSpell(pTarget, m_spells.priest.pPowerWordFortitude) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}

if (m_spells.priest.pPrayerofSpirit)
{
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pPrayerofSpirit))
{
if (CanTryToCastSpell(pTarget, m_spells.priest.pPrayerofSpirit))
{
if (DoCastSpell(pTarget, m_spells.priest.pPrayerofSpirit) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
}
else if (m_spells.priest.pDivineSpirit)
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pDivineSpirit, m_spells.priest.pPrayerofSpirit, pBuffSpell))
{
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pDivineSpirit))
if (CanTryToCastSpell(pTarget, pBuffSpell))
{
if (CanTryToCastSpell(me, m_spells.priest.pDivineSpirit))
if (DoCastSpell(pTarget, pBuffSpell) == SPELL_CAST_OK)
{
if (DoCastSpell(me, m_spells.priest.pDivineSpirit) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}

if (m_spells.priest.pPrayerofShadowProtection)
{
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pPrayerofShadowProtection))
{
if (CanTryToCastSpell(pTarget, m_spells.priest.pPrayerofShadowProtection))
{
if (DoCastSpell(pTarget, m_spells.priest.pPrayerofShadowProtection) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
}
else if (m_spells.priest.pShadowProtection)
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pShadowProtection, m_spells.priest.pPrayerofShadowProtection, pBuffSpell))
{
if (Player* pTarget = SelectBuffTarget(m_spells.priest.pShadowProtection))
if (CanTryToCastSpell(pTarget, pBuffSpell))
{
if (CanTryToCastSpell(pTarget, m_spells.priest.pShadowProtection))
if (DoCastSpell(pTarget, pBuffSpell) == SPELL_CAST_OK)
{
if (DoCastSpell(pTarget, m_spells.priest.pShadowProtection) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
Expand Down Expand Up @@ -2859,7 +2792,7 @@ void PartyBotAI::UpdateInCombatAI_Rogue()
if (m_spells.rogue.pRupture)
vSpells.push_back(m_spells.rogue.pRupture);
}

if (!vSpells.empty())
{
SpellEntry const* pComboSpell = SelectRandomContainerElement(vSpells);
Expand Down Expand Up @@ -3016,33 +2949,16 @@ void PartyBotAI::UpdateOutOfCombatAI_Druid()
return;
}

if (m_spells.druid.pGiftoftheWild)
{
if (Player* pTarget = SelectBuffTarget(m_spells.druid.pGiftoftheWild))
{
if (CanTryToCastSpell(pTarget, m_spells.druid.pGiftoftheWild))
{
if (DoCastSpell(pTarget, m_spells.druid.pGiftoftheWild) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
}
else if (m_spells.druid.pMarkoftheWild)
SpellEntry const* pBuffSpell = nullptr;
if (Player* pTarget = SelectBuffTarget(m_spells.druid.pMarkoftheWild, m_spells.druid.pGiftoftheWild, pBuffSpell))
{
if (Player* pTarget = SelectBuffTarget(m_spells.druid.pMarkoftheWild))
if (CanTryToCastSpell(pTarget, pBuffSpell))
{
if (CanTryToCastSpell(pTarget, m_spells.druid.pMarkoftheWild))
if (DoCastSpell(pTarget, pBuffSpell) == SPELL_CAST_OK)
{
if (DoCastSpell(pTarget, m_spells.druid.pMarkoftheWild) == SPELL_CAST_OK)
{
m_isBuffing = true;
me->ClearTarget();
return;
}
m_isBuffing = true;
me->ClearTarget();
return;
}
}
}
Expand Down Expand Up @@ -3108,7 +3024,7 @@ void PartyBotAI::UpdateInCombatAI_Druid()
if (DoCastSpell(me, m_spells.druid.pBarkskin) == SPELL_CAST_OK)
return;
}

if (form == FORM_NONE)
{
if (m_spells.druid.pHibernate &&
Expand Down Expand Up @@ -3153,7 +3069,7 @@ void PartyBotAI::UpdateInCombatAI_Druid()
Unit* pVictim = me->GetVictim();
if (!pVictim)
return;

if (form != FORM_NONE &&
me->HasUnitState(UNIT_STATE_ROOT) &&
me->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT) &&
Expand All @@ -3162,7 +3078,7 @@ void PartyBotAI::UpdateInCombatAI_Druid()

if (GetRole() == ROLE_HEALER)
return;

switch (form)
{
case FORM_CAT:
Expand Down Expand Up @@ -3265,7 +3181,7 @@ void PartyBotAI::UpdateInCombatAI_Druid()
if (DoCastSpell(pVictim, m_spells.druid.pClaw) == SPELL_CAST_OK)
return;
}

break;
}
case FORM_BEAR:
Expand Down
Loading