Skip to content

Commit 4e476af

Browse files
committed
PetAI: Add basic conditions some autocasted spells
1 parent f4a0a13 commit 4e476af

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/game/AI/BaseAI/PetAI.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ std::pair<Unit*, Spell*> PetAI::PickSpellWithTarget(Unit* owner, Unit* victim, C
290290

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

330+
bool PetAI::ShouldSelfCast(SpellEntry const* spellInfo, Unit* victim)
331+
{
332+
switch (spellInfo->Id) {
333+
case 23145: // Dive Rank 1-3
334+
case 23147:
335+
case 23148:
336+
case 23099: // Dash Rank 1-3
337+
case 23109:
338+
case 23110:
339+
// Cast only when there is a victim and it is not within melee range
340+
return victim && !m_unit->CanReachWithMeleeAttack(victim);
341+
case 26064: // Shell Shield Rank 1
342+
// Cast only in combat and when HP is lower than 50%
343+
return m_inCombat && m_unit->GetHealthPercent() < 50;
344+
}
345+
return true;
346+
}
347+
330348
Player* PetAI::PickGroupMemberForSpell(Player* player, Spell* spell)
331349
{
332350
Group* group = player->GetGroup();

src/game/AI/BaseAI/PetAI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class PetAI : public CreatureAI
5050
Player* PickGroupMemberForSpell(Player* player, Spell* spell);
5151
std::pair<Unit*, Spell*> PickSpellWithTarget(Unit* owner, Unit* victim, CharmInfo* charminfo);
5252
void Cast(std::pair<Unit*, Spell*> spellWithTarget);
53+
bool ShouldSelfCast(SpellEntry const* spellInfo, Unit* victim);
5354

5455
bool m_inCombat;
5556

0 commit comments

Comments
 (0)