Skip to content

Commit 95fa94a

Browse files
committed
PetAI: Add basic conditions for some autocasted spells
1 parent 815a84d commit 95fa94a

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

src/game/AI/BaseAI/PetAI.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ std::pair<Unit*, Spell*> PetAI::PickSpellWithTarget(Unit* owner, Unit* victim, C
288288

289289
Spell* spell = new Spell(m_unit, spellInfo, flags);
290290

291-
// Try to cast a spell on self if the spell allows only targeting self (like Lesser Invisibility and Blood Pact)
291+
// Try to cast a spell on self if the spell allows only targeting self (Lesser Invisibility, Blood Pact) or AoE (Furious Howl, Thunderstomp)
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;
@@ -304,6 +304,33 @@ std::pair<Unit*, Spell*> PetAI::PickSpellWithTarget(Unit* owner, Unit* victim, C
304304
// don't require target but need to be targeted at specific victim for distance check.
305305
else if (victim && spell->CanAutoCast(victim))
306306
return { victim, spell };
307+
// Try to cast a spell if the spell is AoE
308+
else if (IsAreaOfEffectSpell(spellInfo))
309+
{
310+
// If it's a harmful spell (Thunderstomp, Suffering)
311+
if (!IsPositiveSpell(spellInfo->Id))
312+
{
313+
// Keep spell until the victim is in melee range
314+
if (!victim || !m_unit->CanReachWithMeleeAttack(victim))
315+
{
316+
delete spell;
317+
continue;
318+
}
319+
}
320+
else
321+
// If it's a positive spell (Furious Howl)
322+
{
323+
// Use it only in combat
324+
if (!m_inCombat)
325+
{
326+
delete spell;
327+
continue;
328+
}
329+
}
330+
331+
// Target is not required for pet AoE spells
332+
return { nullptr, spell };
333+
}
307334
// In all other cases, try to find a good use for the spell
308335
else
309336
{
@@ -327,6 +354,24 @@ std::pair<Unit*, Spell*> PetAI::PickSpellWithTarget(Unit* owner, Unit* victim, C
327354
return { nullptr, nullptr };
328355
}
329356

357+
bool PetAI::ShouldSelfCast(SpellEntry const* spellInfo, Unit* victim)
358+
{
359+
switch (spellInfo->Id) {
360+
case 23145: // Dive Rank 1-3
361+
case 23147:
362+
case 23148:
363+
case 23099: // Dash Rank 1-3
364+
case 23109:
365+
case 23110:
366+
// Cast only when there is a victim and it is not within melee range
367+
return victim && !m_unit->CanReachWithMeleeAttack(victim);
368+
case 26064: // Shell Shield Rank 1
369+
// Cast only in combat and when HP is lower than 50%
370+
return m_inCombat && m_unit->GetHealthPercent() < 50;
371+
}
372+
return true;
373+
}
374+
330375
Player* PetAI::PickGroupMemberForSpell(Player* player, Spell* spell)
331376
{
332377
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)