Skip to content

Commit

Permalink
Map/SpawnManager: Fix spawning of dynguid mobs with spawnmask and fix…
Browse files Browse the repository at this point in the history
… infinite loop
  • Loading branch information
killerwife committed Jan 11, 2025
1 parent e3752ec commit 7cc85cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/game/Maps/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool Map::CanSpawn(TypeID typeId, uint32 dbGuid)
{
if (typeId == TYPEID_UNIT)
return GetCreatureLinkingHolder()->CanSpawn(dbGuid, this, nullptr, 0.f, 0.f);
else if (TYPEID_GAMEOBJECT)
else if (typeId == TYPEID_GAMEOBJECT)
{
GameObjectData const* data = sObjectMgr.GetGOData(dbGuid);
if (data)
Expand Down
13 changes: 9 additions & 4 deletions src/game/Maps/SpawnManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void SpawnManager::Initialize()
if (m_map.GetPersistentState()->GetCreatureRespawnTime(dbGuid) < now)
{
auto data = sObjectMgr.GetCreatureData(dbGuid);
m_map.GetPersistentState()->AddCreatureToGrid(dbGuid, data);
if (m_map.GetCreatureLinkingHolder()->CanSpawn(dbGuid, &m_map, nullptr, 0.f, 0.f)) // copy of Map::CanSpawn
m_map.GetPersistentState()->AddCreatureToGrid(dbGuid, data);
}
else
AddCreature(dbGuid);
Expand All @@ -72,7 +73,8 @@ void SpawnManager::Initialize()
if (m_map.GetPersistentState()->GetGORespawnTime(dbGuid) < now)
{
auto data = sObjectMgr.GetGOData(dbGuid);
m_map.GetPersistentState()->AddGameobjectToGrid(dbGuid, data);
if ((data->spawnMask & (1 << m_map.GetDifficulty())) != 0) // copy of Map::CanSpawn
m_map.GetPersistentState()->AddGameobjectToGrid(dbGuid, data);
}
else
AddGameObject(dbGuid);
Expand Down Expand Up @@ -239,14 +241,17 @@ bool SpawnManager::IsEventGuid(uint32 dbguid, HighGuid high) const

void SpawnManager::RespawnAll()
{
for (auto itr = m_spawns.begin(); itr != m_spawns.end();)
for (auto itr = m_spawns.begin(); itr != m_spawns.end(); )
{
auto& spawnInfo = *itr;
if (spawnInfo.GetHighGuid() == HIGHGUID_GAMEOBJECT)
m_map.GetPersistentState()->SaveGORespawnTime(spawnInfo.GetDbGuid(), 0);
if (spawnInfo.GetHighGuid() == HIGHGUID_UNIT)
m_map.GetPersistentState()->SaveCreatureRespawnTime(spawnInfo.GetDbGuid(), 0);
spawnInfo.ConstructForMap(m_map);
if (spawnInfo.ConstructForMap(m_map))
itr = m_spawns.erase(itr);
else
++itr;
}
}

Expand Down

0 comments on commit 7cc85cc

Please sign in to comment.