From 4e476af64525ae155326be9e21e565f61b62f04c Mon Sep 17 00:00:00 2001 From: Yury Date: Fri, 3 Nov 2023 14:43:37 +0200 Subject: [PATCH] PetAI: Add basic conditions some autocasted spells --- src/game/AI/BaseAI/PetAI.cpp | 22 ++++++++++++++++++++-- src/game/AI/BaseAI/PetAI.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/game/AI/BaseAI/PetAI.cpp b/src/game/AI/BaseAI/PetAI.cpp index e0257d7c40..0e6d224281 100644 --- a/src/game/AI/BaseAI/PetAI.cpp +++ b/src/game/AI/BaseAI/PetAI.cpp @@ -290,8 +290,8 @@ std::pair 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; @@ -327,6 +327,24 @@ std::pair 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(); diff --git a/src/game/AI/BaseAI/PetAI.h b/src/game/AI/BaseAI/PetAI.h index 10fce1bcbf..054e110b96 100644 --- a/src/game/AI/BaseAI/PetAI.h +++ b/src/game/AI/BaseAI/PetAI.h @@ -50,6 +50,7 @@ class PetAI : public CreatureAI Player* PickGroupMemberForSpell(Player* player, Spell* spell); std::pair PickSpellWithTarget(Unit* owner, Unit* victim, CharmInfo* charminfo); void Cast(std::pair spellWithTarget); + bool ShouldSelfCast(SpellEntry const* spellInfo, Unit* victim); bool m_inCombat;