From 7a8d884209651d8702ba0221f263f630efb12a65 Mon Sep 17 00:00:00 2001 From: EricksOliveira Date: Mon, 16 Nov 2026 16:15:44 -0300 Subject: [PATCH] fix(Reset): Despawn summons of duel-reset spells With cooldown reset, a player could stack several Mechanical Dragonlings by using the trinket in a duel and forfeiting. When the duel reset leaves a spell ready (duel start, or duel end after cooldowns are restored), the creatures that spell summons directly and the player still has nearby now despawn. The player's pet (Player::GetPet) is kept. Closes #19 --- src/DuelReset.cpp | 63 +++++++++++++++++++++++++++++++++++++-- src/DuelReset.h | 4 ++- src/DuelReset_scripts.cpp | 6 ++-- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/DuelReset.cpp b/src/DuelReset.cpp index ed52769..a764346 100644 --- a/src/DuelReset.cpp +++ b/src/DuelReset.cpp @@ -19,8 +19,10 @@ #include "DuelReset.h" #include "GameTime.h" +#include "MapDefines.h" #include "Pet.h" #include "SpellMgr.h" +#include "TemporarySummon.h" DuelReset* DuelReset::instance() { @@ -28,8 +30,10 @@ DuelReset* DuelReset::instance() return &instance; } -void DuelReset::ResetSpellCooldowns(Player* player, bool onStartDuel) +std::vector DuelReset::ResetSpellCooldowns(Player* player, + bool onStartDuel) { + std::vector resetSpellIds; uint32 infTime = GameTime::GetGameTimeMS().count() + infinityCooldownDelayCheck; SpellCooldowns::iterator itr, next; @@ -61,7 +65,10 @@ void DuelReset::ResetSpellCooldowns(Player* player, bool onStartDuel) && (onStartDuel ? (totalCooldown - remainingCooldown) > m_cooldownAge * IN_MILLISECONDS : true) && (onStartDuel ? (categoryCooldown - remainingCooldown) > m_cooldownAge * IN_MILLISECONDS : true) ) + { + resetSpellIds.push_back(itr->first); player->RemoveSpellCooldown(itr->first, true); + } } if (Pet* pet = player->GetPet()) @@ -72,6 +79,8 @@ void DuelReset::ResetSpellCooldowns(Player* player, bool onStartDuel) // actually clear cooldowns pet->m_CreatureSpellCooldowns.clear(); } + + return resetSpellIds; } void DuelReset::SaveCooldownStateBeforeDuel(Player* player) @@ -89,7 +98,8 @@ void DuelReset::RestoreCooldownStateAfterDuel(Player* player) if (savedDuelCooldownsMap == m_spellCooldownsBeforeDuel.end()) return; - sDuelReset->ResetSpellCooldowns(player, false); + std::vector resetSpellIds = + sDuelReset->ResetSpellCooldowns(player, false); SpellCooldowns playerSavedDuelCooldowns = savedDuelCooldownsMap->second; uint32 curMSTime = GameTime::GetGameTimeMS().count(); @@ -132,6 +142,55 @@ void DuelReset::RestoreCooldownStateAfterDuel(Player* player) WorldPacket data; player->BuildCooldownPacket(data, SPELL_COOLDOWN_FLAG_INCLUDE_EVENT_COOLDOWNS, cooldowns); player->SendDirectMessage(&data); + + // After the restore, so summons of spells on cooldown again stay + RemoveSpellSummons(player, resetSpellIds); +} + +void DuelReset::RemoveSpellSummons(Player* player, + std::vector const& spellIds) +{ + for (uint32 spellId : spellIds) + { + // Spell is on cooldown again, its summon stays + if (player->HasSpellCooldown(spellId)) + continue; + + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); + if (!spellInfo) + continue; + + // Only direct summons; SPELL_EFFECT_SUMMON_PET is the controlled pet + std::vector entries; + for (SpellEffectInfo const& effect : spellInfo->GetEffects()) + if (effect.Effect == SPELL_EFFECT_SUMMON && effect.MiscValue > 0) + entries.push_back(uint32(effect.MiscValue)); + + if (entries.empty()) + continue; + + std::list creatures; + player->GetCreatureListWithEntryInGrid(creatures, entries, + SIZE_OF_GRIDS); + + for (Creature* creature : creatures) + { + if (creature->IsPet()) + continue; + + TempSummon* summon = creature->ToTempSummon(); + if (!summon || summon->GetSummonerGUID() != player->GetGUID()) + continue; + + // Default summon path leaves it 0, guardian path stores the spell + uint32 createdBySpell = + creature->GetUInt32Value(UNIT_CREATED_BY_SPELL); + if (createdBySpell && createdBySpell != spellId) + continue; + + summon->UnSummon(); + } + } } void DuelReset::SaveHealthBeforeDuel(Player* player) diff --git a/src/DuelReset.h b/src/DuelReset.h index 7289ff6..df21b86 100644 --- a/src/DuelReset.h +++ b/src/DuelReset.h @@ -13,9 +13,11 @@ class DuelReset void LoadConfig(bool reload); void FillWhitelist(std::string zonesAreas, std::vector &whitelist); - void ResetSpellCooldowns(Player* player, bool onStartDuel); + std::vector ResetSpellCooldowns(Player* player, bool onStartDuel); void SaveCooldownStateBeforeDuel(Player* player); void RestoreCooldownStateAfterDuel(Player* player); + void RemoveSpellSummons(Player* player, + std::vector const& spellIds); void SaveHealthBeforeDuel(Player* player); void SaveManaBeforeDuel(Player* player); diff --git a/src/DuelReset_scripts.cpp b/src/DuelReset_scripts.cpp index 6c2fa4c..29c691b 100644 --- a/src/DuelReset_scripts.cpp +++ b/src/DuelReset_scripts.cpp @@ -62,8 +62,10 @@ class DuelResetScript : public PlayerScript { sDuelReset->SaveCooldownStateBeforeDuel(player1); sDuelReset->SaveCooldownStateBeforeDuel(player2); - sDuelReset->ResetSpellCooldowns(player1, true); - sDuelReset->ResetSpellCooldowns(player2, true); + sDuelReset->RemoveSpellSummons(player1, + sDuelReset->ResetSpellCooldowns(player1, true)); + sDuelReset->RemoveSpellSummons(player2, + sDuelReset->ResetSpellCooldowns(player2, true)); } // Health and mana reset