fix(Core): Hunter Readiness crash fix (#12987)

Co-authored-by: Angelo Venturini <nefertum.dev@protonmail.com>
This commit is contained in:
ZhengPeiRu21
2022-09-20 12:07:30 -06:00
committed by GitHub
parent d5f839a4be
commit fd08f6150f

View File

@@ -655,13 +655,12 @@ class spell_hun_readiness : public SpellScript
SpellCooldowns& cooldowns = caster->GetSpellCooldownMap(); SpellCooldowns& cooldowns = caster->GetSpellCooldownMap();
SpellCooldowns::iterator itr, next; std::set<std::pair<uint32, bool>> spellsToRemove;
for (itr = cooldowns.begin(); itr != cooldowns.end(); itr = next) std::set<uint32> categoriesToRemove;
{
next = itr;
++next;
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itr->first); for (const auto& [spellId, cooldown] : cooldowns)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (spellInfo if (spellInfo
&& spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER
&& spellInfo->Id != SPELL_HUNTER_READINESS && spellInfo->Id != SPELL_HUNTER_READINESS
@@ -669,12 +668,18 @@ class spell_hun_readiness : public SpellScript
&& spellInfo->Id != SPELL_DRAENEI_GIFT_OF_THE_NAARU) && spellInfo->Id != SPELL_DRAENEI_GIFT_OF_THE_NAARU)
{ {
if (spellInfo->RecoveryTime > 0) if (spellInfo->RecoveryTime > 0)
caster->RemoveSpellCooldown(spellInfo->Id, itr->second.needSendToClient); spellsToRemove.insert(std::make_pair(spellInfo->Id, cooldown.needSendToClient));
if (spellInfo->CategoryRecoveryTime > 0) if (spellInfo->CategoryRecoveryTime > 0)
caster->RemoveCategoryCooldown(spellInfo->GetCategory()); categoriesToRemove.insert(spellInfo->GetCategory());
} }
} }
// we can't remove spell cooldowns while iterating.
for (const auto& [spellId, sendToClient] : spellsToRemove)
caster->RemoveSpellCooldown(spellId, sendToClient);
for (const auto& category : categoriesToRemove)
caster->RemoveCategoryCooldown(category);
} }
void Register() override void Register() override