Merge pull request #6438 from MrSmite/PetAI_autocast_fix
Fix pet autocast spells such as Furious Howl and Leap
This commit is contained in:
@@ -153,25 +153,42 @@ void PetAI::UpdateAI(const uint32 diff)
|
|||||||
|
|
||||||
if (spellInfo->IsPositive())
|
if (spellInfo->IsPositive())
|
||||||
{
|
{
|
||||||
// non combat spells allowed
|
|
||||||
// only pet spells have IsNonCombatSpell and not fit this reqs:
|
|
||||||
// Consume Shadows, Lesser Invisibility, so ignore checks for its
|
|
||||||
if (spellInfo->CanBeUsedInCombat())
|
if (spellInfo->CanBeUsedInCombat())
|
||||||
{
|
{
|
||||||
// allow only spell without spell cost or with spell cost but not duration limit
|
// check spell cooldown
|
||||||
int32 duration = spellInfo->GetDuration();
|
if (me->HasSpellCooldown(spellInfo->Id))
|
||||||
if ((spellInfo->ManaCost || spellInfo->ManaCostPercentage || spellInfo->ManaPerSecond) && duration > 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// allow only spell without cooldown > duration
|
// Check if we're in combat or commanded to attack
|
||||||
int32 cooldown = spellInfo->GetRecoveryTime();
|
if (!me->isInCombat() && !me->GetCharmInfo()->IsCommandAttack())
|
||||||
if (cooldown >= 0 && duration >= 0 && cooldown > duration)
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE, 0);
|
Spell* spell = new Spell(me, spellInfo, TRIGGERED_NONE, 0);
|
||||||
|
|
||||||
bool spellUsed = false;
|
bool spellUsed = false;
|
||||||
|
|
||||||
|
// Some spells can target enemy or friendly (DK Ghoul's Leap)
|
||||||
|
// Check for enemy first (pet then owner)
|
||||||
|
if (Unit* target = me->getAttackerForHelper())
|
||||||
|
{
|
||||||
|
if (CanAttack(target) && spell->CanAutoCast(target))
|
||||||
|
{
|
||||||
|
targetSpellStore.push_back(std::make_pair(target, spell));
|
||||||
|
spellUsed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Unit* target = me->GetCharmerOrOwner()->getAttackerForHelper())
|
||||||
|
{
|
||||||
|
if (CanAttack(target) && spell->CanAutoCast(target))
|
||||||
|
{
|
||||||
|
targetSpellStore.push_back(std::make_pair(target, spell));
|
||||||
|
spellUsed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No enemy, check friendly
|
||||||
|
if (!spellUsed)
|
||||||
|
{
|
||||||
for (std::set<uint64>::const_iterator tar = m_AllySet.begin(); tar != m_AllySet.end(); ++tar)
|
for (std::set<uint64>::const_iterator tar = m_AllySet.begin(); tar != m_AllySet.end(); ++tar)
|
||||||
{
|
{
|
||||||
Unit* target = ObjectAccessor::GetUnit(*me, *tar);
|
Unit* target = ObjectAccessor::GetUnit(*me, *tar);
|
||||||
@@ -187,6 +204,9 @@ void PetAI::UpdateAI(const uint32 diff)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No valid targets at all
|
||||||
if (!spellUsed)
|
if (!spellUsed)
|
||||||
delete spell;
|
delete spell;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user