Skip to content

Commit

Permalink
PetAI: Add basic conditions some autocasted spells
Browse files Browse the repository at this point in the history
  • Loading branch information
deiteris committed Nov 3, 2023
1 parent f4a0a13 commit 4e476af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/game/AI/BaseAI/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ std::pair<Unit*, Spell*> PetAI::PickSpellWithTarget(Unit* owner, Unit* victim, C

// Try to cast a spell on self if the spell allows only targeting self (like Lesser Invisibility and Blood Pact)
if (IsOnlySelfTargeting(spellInfo)) {
// Skip the spell in case it's already applied to self
if (!spell->CanAutoCast(m_unit))
// Skip the spell in case it's already applied to self or doesn't meet specific conditions
if (!ShouldSelfCast(spellInfo, victim) || !spell->CanAutoCast(m_unit))
{
delete spell;
continue;
Expand Down Expand Up @@ -327,6 +327,24 @@ std::pair<Unit*, Spell*> PetAI::PickSpellWithTarget(Unit* owner, Unit* victim, C
return { nullptr, nullptr };
}

bool PetAI::ShouldSelfCast(SpellEntry const* spellInfo, Unit* victim)
{
switch (spellInfo->Id) {
case 23145: // Dive Rank 1-3
case 23147:
case 23148:
case 23099: // Dash Rank 1-3
case 23109:
case 23110:
// Cast only when there is a victim and it is not within melee range
return victim && !m_unit->CanReachWithMeleeAttack(victim);
case 26064: // Shell Shield Rank 1
// Cast only in combat and when HP is lower than 50%
return m_inCombat && m_unit->GetHealthPercent() < 50;
}
return true;
}

Player* PetAI::PickGroupMemberForSpell(Player* player, Spell* spell)
{
Group* group = player->GetGroup();
Expand Down
1 change: 1 addition & 0 deletions src/game/AI/BaseAI/PetAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PetAI : public CreatureAI
Player* PickGroupMemberForSpell(Player* player, Spell* spell);
std::pair<Unit*, Spell*> PickSpellWithTarget(Unit* owner, Unit* victim, CharmInfo* charminfo);
void Cast(std::pair<Unit*, Spell*> spellWithTarget);
bool ShouldSelfCast(SpellEntry const* spellInfo, Unit* victim);

bool m_inCombat;

Expand Down

0 comments on commit 4e476af

Please sign in to comment.