diff --git a/src/server/game/Spells/SpellHistory.cpp b/src/server/game/Spells/SpellHistory.cpp index 3c1f70b108..a64646a391 100644 --- a/src/server/game/Spells/SpellHistory.cpp +++ b/src/server/game/Spells/SpellHistory.cpp @@ -34,8 +34,6 @@ #include "World.h" #include -SpellHistory::Duration const SpellHistory::InfinityCooldownDelay = Seconds(MONTH); - template<> struct SpellHistory::PersistenceHelper { @@ -224,7 +222,7 @@ void SpellHistory::Update() TimePoint now = time_point_cast(GameTime::GetTime()); for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();) { - if (itr->second->CategoryEnd < now) + if (itr->second->CategoryEnd < now && !itr->second->OnHold) itr = _categoryCooldowns.erase(itr); else ++itr; @@ -232,7 +230,7 @@ void SpellHistory::Update() for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();) { - if (itr->second.CooldownEnd < now) + if (itr->second.CooldownEnd < now && !itr->second.OnHold) itr = EraseCooldown(itr); else ++itr; @@ -387,9 +385,6 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel Duration cooldown = Duration::zero(); Duration categoryCooldown = Duration::zero(); - TimePoint curTime = time_point_cast(GameTime::GetTime()); - TimePoint catrecTime; - TimePoint recTime; bool needsCooldownPacket = false; if (!forcedCooldown) @@ -398,13 +393,7 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel cooldown = *forcedCooldown; // overwrite time for selected category - if (onHold) - { - // use +MONTH as infinite cooldown marker - catrecTime = categoryCooldown > Duration::zero() ? (curTime + InfinityCooldownDelay) : curTime; - recTime = cooldown > Duration::zero() ? (curTime + InfinityCooldownDelay) : catrecTime; - } - else + if (!onHold) { if (!forcedCooldown) { @@ -509,11 +498,12 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel // no cooldown after applying spell mods if (cooldown == Duration::zero() && categoryCooldown == Duration::zero()) return; - - catrecTime = categoryCooldown != Duration::zero() ? curTime + categoryCooldown : curTime; - recTime = cooldown != Duration::zero() ? curTime + cooldown : catrecTime; } + TimePoint curTime = time_point_cast(GameTime::GetTime()); + TimePoint catrecTime = categoryCooldown != Duration::zero() ? curTime + categoryCooldown : curTime; + TimePoint recTime = cooldown != Duration::zero() ? curTime + cooldown : catrecTime; + // self spell cooldown if (recTime != curTime) { @@ -579,7 +569,7 @@ void SpellHistory::AddCooldown(uint32 spellId, uint32 itemId, TimePoint cooldown void SpellHistory::ModifySpellCooldown(uint32 spellId, Duration cooldownMod, bool withoutCategoryCooldown) { auto itr = _spellCooldowns.find(spellId); - if (itr == _spellCooldowns.end()) + if (itr == _spellCooldowns.end() || itr->second.OnHold) return; ModifySpellCooldown(itr, cooldownMod, withoutCategoryCooldown); @@ -657,7 +647,7 @@ void SpellHistory::ModifyCooldown(SpellInfo const* spellInfo, Duration cooldownM void SpellHistory::ResetCooldown(uint32 spellId, bool update /*= false*/) { auto itr = _spellCooldowns.find(spellId); - if (itr == _spellCooldowns.end()) + if (itr == _spellCooldowns.end() || itr->second.OnHold) return; ResetCooldown(itr, update); @@ -682,18 +672,7 @@ void SpellHistory::ResetCooldown(CooldownStorageType::iterator& itr, bool update void SpellHistory::ResetAllCooldowns() { - if (GetPlayerOwner()) - { - std::vector cooldowns; - cooldowns.reserve(_spellCooldowns.size()); - for (auto const& [spellId, _] : _spellCooldowns) - cooldowns.push_back(spellId); - - SendClearCooldowns(cooldowns); - } - - _categoryCooldowns.clear(); - _spellCooldowns.clear(); + ResetCooldowns([](CooldownEntry const&) { return true; }, true); } bool SpellHistory::HasCooldown(SpellInfo const* spellInfo, uint32 itemId /*= 0*/) const @@ -725,13 +704,21 @@ SpellHistory::Duration SpellHistory::GetRemainingCooldown(SpellInfo const* spell TimePoint end; auto itr = _spellCooldowns.find(spellInfo->Id); if (itr != _spellCooldowns.end()) + { + if (itr->second.OnHold) + return Duration::max(); + end = itr->second.CooldownEnd; + } else { auto catItr = _categoryCooldowns.find(spellInfo->GetCategory()); if (catItr == _categoryCooldowns.end()) return Duration::zero(); + if (catItr->second->OnHold) + return Duration::max(); + end = catItr->second->CategoryEnd; } @@ -749,6 +736,9 @@ SpellHistory::Duration SpellHistory::GetRemainingCategoryCooldown(uint32 categor if (catItr == _categoryCooldowns.end()) return Duration::zero(); + if (catItr->second->OnHold) + return Duration::max(); + TimePoint end = catItr->second->CategoryEnd; TimePoint now = time_point_cast(GameTime::GetTime()); @@ -1063,7 +1053,8 @@ void SpellHistory::ResumeCooldowns() Duration pausedDuration = time_point_cast(GameTime::GetTime()) - *_pauseTime; for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();) - itr->second.CooldownEnd += pausedDuration; + if (!itr->second.OnHold) + itr->second.CooldownEnd += pausedDuration; for (auto& [chargeCategoryId, chargeRefreshTimes] : _categoryCharges) for (ChargeEntry& chargeEntry : chargeRefreshTimes) @@ -1079,13 +1070,13 @@ Player* SpellHistory::GetPlayerOwner() const return _owner->GetCharmerOrOwnerPlayerOrPlayerItself(); } -void SpellHistory::SendClearCooldowns(std::vector const& cooldowns) const +void SpellHistory::SendClearCooldowns(std::vector&& cooldowns) const { if (Player const* playerOwner = GetPlayerOwner()) { WorldPackets::Spells::ClearCooldowns clearCooldowns; clearCooldowns.IsPet = _owner != playerOwner; - clearCooldowns.SpellID = cooldowns; + clearCooldowns.SpellID = std::move(cooldowns); playerOwner->SendDirectMessage(clearCooldowns.Write()); } } diff --git a/src/server/game/Spells/SpellHistory.h b/src/server/game/Spells/SpellHistory.h index f7f360560b..c14e1568b5 100644 --- a/src/server/game/Spells/SpellHistory.h +++ b/src/server/game/Spells/SpellHistory.h @@ -112,8 +112,6 @@ public: void WritePacket(WorldPackets::Pet::PetSpells* petSpells) const; // Cooldowns - static Duration const InfinityCooldownDelay; // used for set "infinity cooldowns" for spells and check - void StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spell* spell = nullptr, bool onHold = false, Optional forcedCooldown = {}); void SendCooldownEvent(SpellInfo const* spellInfo, uint32 itemId = 0, Spell* spell = nullptr, bool startCooldown = true); @@ -131,7 +129,7 @@ public: { for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();) { - if (std::forward(predicate)(itr->second)) + if (!itr->second.OnHold && std::forward(predicate)(itr->second)) ModifySpellCooldown(itr, cooldownMod, withoutCategoryCooldown); else ++itr; @@ -143,7 +141,7 @@ public: { for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end(); ++itr) { - if (std::forward(predicate)(itr->second)) + if (!itr->second.OnHold && std::forward(predicate)(itr->second)) UpdateCooldownRecoveryRate(itr, modChange, apply); } } @@ -156,7 +154,7 @@ public: resetCooldowns.reserve(_spellCooldowns.size()); for (auto itr = _spellCooldowns.begin(); itr != _spellCooldowns.end();) { - if (std::forward(predicate)(itr->second)) + if (!itr->second.OnHold && std::forward(predicate)(itr->second)) { resetCooldowns.push_back(int32(itr->first)); ResetCooldown(itr, false); @@ -166,7 +164,7 @@ public: } if (update && !resetCooldowns.empty()) - SendClearCooldowns(resetCooldowns); + SendClearCooldowns(std::move(resetCooldowns)); } void ResetAllCooldowns(); @@ -214,7 +212,7 @@ private: void ModifySpellCooldown(CooldownStorageType::iterator& itr, Duration cooldownMod, bool withoutCategoryCooldown); void UpdateCooldownRecoveryRate(CooldownStorageType::iterator& itr, float modChange, bool apply); void ResetCooldown(CooldownStorageType::iterator& itr, bool update = false); - void SendClearCooldowns(std::vector const& cooldowns) const; + void SendClearCooldowns(std::vector&& cooldowns) const; CooldownStorageType::iterator EraseCooldown(CooldownStorageType::iterator itr); void SendSetSpellCharges(uint32 chargeCategoryId, ChargeEntryCollection const& chargeCollection) const; diff --git a/src/server/scripts/Battlegrounds/SeethingShore/battleground_seething_shore.cpp b/src/server/scripts/Battlegrounds/SeethingShore/battleground_seething_shore.cpp index 01750456ef..e096797ba2 100644 --- a/src/server/scripts/Battlegrounds/SeethingShore/battleground_seething_shore.cpp +++ b/src/server/scripts/Battlegrounds/SeethingShore/battleground_seething_shore.cpp @@ -22,7 +22,6 @@ #include "BattlegroundScript.h" #include "Containers.h" #include "CreatureAI.h" -#include "G3DPosition.hpp" #include "GameObject.h" #include "GameObjectAI.h" #include "Map.h" @@ -34,7 +33,6 @@ #include "Spell.h" #include "SpellAuras.h" #include "SpellScript.h" -#include "SpellHistory.h" #include "TaskScheduler.h" #include "TemporarySummon.h" #include "WaypointDefines.h" @@ -650,7 +648,7 @@ class spell_bg_seething_shore_speed_up : public SpellScript // Unsure about which spells should reset and which not // It's not the same list as the ones that reset on encounter reset if (Player* player = GetCaster()->ToPlayer()) - player->GetSpellHistory()->ResetAllCooldowns(); + player->RemoveArenaSpellCooldowns(); } void Register() override diff --git a/src/server/scripts/World/duel_reset.cpp b/src/server/scripts/World/duel_reset.cpp index 6d3dca3d16..a380266b15 100644 --- a/src/server/scripts/World/duel_reset.cpp +++ b/src/server/scripts/World/duel_reset.cpp @@ -114,7 +114,6 @@ class DuelResetScript : public PlayerScript applySpellMod(categoryCooldown); return remainingCooldown > 0ms - && !cooldown.OnHold && Milliseconds(totalCooldown) < 10min && Milliseconds(categoryCooldown) < 10min && Milliseconds(remainingCooldown) < 10min