Merge e2dd8a57a24a32a1641eb97e7493c90c4fc820c9 into 5bef92d5eaca3e2ecc317f9d599312bc23eb71aa

This commit is contained in:
天鹭 2025-11-09 22:43:11 +00:00 committed by GitHub
commit 4aeb56c9bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -120,7 +120,7 @@ class EventProcessor
[[nodiscard]] uint64 CalculateQueueTime(uint64 delay) const; [[nodiscard]] uint64 CalculateQueueTime(uint64 delay) const;
void CancelEventGroup(uint8 group); void CancelEventGroup(uint8 group);
bool HaveEventList() const { return !m_events.empty(); } bool HasEvents() const { return !m_events.empty(); }
protected: protected:
uint64 m_time{0}; uint64 m_time{0};

View File

@ -54,6 +54,10 @@ Map::~Map()
{ {
// UnloadAll must be called before deleting the map // UnloadAll must be called before deleting the map
// Kill all scheduled events without executing them, since the map and its objects are being destroyed.
// This prevents events from running on invalid or deleted objects during map destruction.
Events.KillAllEvents(false);
sScriptMgr->OnDestroyMap(this); sScriptMgr->OnDestroyMap(this);
if (!m_scriptSchedule.empty()) if (!m_scriptSchedule.empty())
@ -447,7 +451,7 @@ void Map::Update(const uint32 t_diff, const uint32 s_diff, bool /*thread*/)
} }
} }
_creatureRespawnScheduler.Update(t_diff); Events.Update(t_diff);
if (!t_diff) if (!t_diff)
{ {
@ -2758,13 +2762,13 @@ void Map::RemoveOldCorpses()
void Map::ScheduleCreatureRespawn(ObjectGuid creatureGuid, Milliseconds respawnTimer, Position pos) void Map::ScheduleCreatureRespawn(ObjectGuid creatureGuid, Milliseconds respawnTimer, Position pos)
{ {
_creatureRespawnScheduler.Schedule(respawnTimer, [this, creatureGuid, pos](TaskContext) Events.AddEventAtOffset([this, creatureGuid, pos]()
{ {
if (Creature* creature = GetCreature(creatureGuid)) if (Creature* creature = GetCreature(creatureGuid))
creature->Respawn(); creature->Respawn();
else else
SummonCreature(creatureGuid.GetEntry(), pos); SummonCreature(creatureGuid.GetEntry(), pos);
}); }, respawnTimer);
} }
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned) /// Send a packet to all players (or players selected team) in the zone (except self if mentioned)

View File

@ -23,6 +23,7 @@
#include "DataMap.h" #include "DataMap.h"
#include "Define.h" #include "Define.h"
#include "DynamicTree.h" #include "DynamicTree.h"
#include "EventProcessor.h"
#include "GameObjectModel.h" #include "GameObjectModel.h"
#include "GridDefines.h" #include "GridDefines.h"
#include "GridRefMgr.h" #include "GridRefMgr.h"
@ -33,7 +34,6 @@
#include "PathGenerator.h" #include "PathGenerator.h"
#include "Position.h" #include "Position.h"
#include "SharedDefines.h" #include "SharedDefines.h"
#include "TaskScheduler.h"
#include "Timer.h" #include "Timer.h"
#include "GridTerrainData.h" #include "GridTerrainData.h"
#include <bitset> #include <bitset>
@ -172,7 +172,7 @@ public:
// currently unused for normal maps // currently unused for normal maps
bool CanUnload(uint32 diff) bool CanUnload(uint32 diff)
{ {
if (!m_unloadTimer) if (!m_unloadTimer || Events.HasEvents())
return false; return false;
if (m_unloadTimer <= diff) if (m_unloadTimer <= diff)
@ -430,7 +430,7 @@ public:
void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone); void UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone);
[[nodiscard]] uint32 ApplyDynamicModeRespawnScaling(WorldObject const* obj, uint32 respawnDelay) const; [[nodiscard]] uint32 ApplyDynamicModeRespawnScaling(WorldObject const* obj, uint32 respawnDelay) const;
TaskScheduler _creatureRespawnScheduler; EventProcessor Events;
void ScheduleCreatureRespawn(ObjectGuid /*creatureGuid*/, Milliseconds /*respawnTimer*/, Position pos = Position()); void ScheduleCreatureRespawn(ObjectGuid /*creatureGuid*/, Milliseconds /*respawnTimer*/, Position pos = Position());