game: fix NPCs not spawning on reconnect to same map

On disconnect/reconnect to the same map, entityManager was not cleared
and creatureInstances_ still held old entries from the previous session.
When the server re-sent CREATE_OBJECT for the same GUIDs, the spawn
callback's early-return guard (creatureInstances_.count(guid)) silently
dropped every NPC re-spawn, leaving the world empty.

Fixes:
- disconnect() now calls entityManager.clear() to purge stale entities
- WorldEntryCallback gains a bool isInitialEntry parameter (true on first
  login or reconnect, false on in-world teleport/flight landing)
- Same-map optimization path skipped when isInitialEntry=true, so
  loadOnlineWorldTerrain runs its full cleanup and properly despawns old
  creature/player instances before the server refreshes them
This commit is contained in:
Kelsi 2026-03-10 08:35:36 -07:00
parent baab997da8
commit 54246345bb
3 changed files with 13 additions and 8 deletions

View file

@ -666,8 +666,8 @@ public:
uint32_t getSkillCategory(uint32_t skillId) const;
// World entry callback (online mode - triggered when entering world)
// Parameters: mapId, x, y, z (canonical WoW coordinates)
using WorldEntryCallback = std::function<void(uint32_t mapId, float x, float y, float z)>;
// Parameters: mapId, x, y, z (canonical WoW coords), isInitialEntry=true on first login or reconnect
using WorldEntryCallback = std::function<void(uint32_t mapId, float x, float y, float z, bool isInitialEntry)>;
void setWorldEntryCallback(WorldEntryCallback cb) { worldEntryCallback_ = std::move(cb); }
// Unstuck callback (resets player Z to floor height)