From a837d7f55b565c7c2a8088831066d2f0575bd42a Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 25 Jul 2024 21:34:06 +0800 Subject: [PATCH] [Class spell] Optimize toggle pet spell --- src/strategy/actions/GenericActions.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/strategy/actions/GenericActions.cpp b/src/strategy/actions/GenericActions.cpp index 5e292369..9b16ee7a 100644 --- a/src/strategy/actions/GenericActions.cpp +++ b/src/strategy/actions/GenericActions.cpp @@ -20,6 +20,7 @@ bool TogglePetSpellAutoCastAction::Execute(Event event) { if (!pet) { return false; } + bool toggled = false; for (PetSpellMap::const_iterator itr = pet->m_spells.begin(); itr != pet->m_spells.end(); ++itr) { if(itr->second.state == PETSPELL_REMOVED) @@ -29,17 +30,29 @@ bool TogglePetSpellAutoCastAction::Execute(Event event) { const SpellInfo* spellInfo = sSpellMgr->GetSpellInfo(spellId); if (spellInfo->IsPassive()) continue; - + + bool shouldApply = true; // imp's spell, felhunte's intelligence, ghoul's leap, cat stealth if (spellId == 4511 || spellId == 1742 || spellId == 54424 || spellId == 57564 || spellId == 57565 || spellId == 57566 || spellId == 57567 || spellId == 47482 || spellId == 24450) { - pet->ToggleAutocast(spellInfo, false); - } else { - pet->ToggleAutocast(spellInfo, true); + shouldApply = false; + } + bool isAutoCast = false; + for (unsigned int &m_autospell : pet->m_autospells) + { + if (m_autospell == spellId) + { + isAutoCast = true; + break; + } + } + if (shouldApply != isAutoCast) { + pet->ToggleAutocast(spellInfo, shouldApply); + toggled = true; } } - return true; + return toggled; } bool PetAttackAction::Execute(Event event)