Core/Misc: Some refactoring, #23603 prep: (#23676)

- Split SpawnMetadata off from SpawnData
- No longer allocate Creature/Gameobject objects in ObjectGridLoader just to check their typeid and delete them afterwards

Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
This commit is contained in:
Treeston
2020-02-08 20:22:37 +01:00
committed by GitHub
parent 726d5e91b5
commit 9304e496cb
16 changed files with 333 additions and 273 deletions

View File

@@ -79,13 +79,15 @@ public:
return commandTable;
}
static bool DoTeleport(ChatHandler* handler, WorldLocation loc)
static bool DoTeleport(ChatHandler* handler, Position pos, uint32 mapId = MAPID_INVALID)
{
Player* player = handler->GetSession()->GetPlayer();
if (!MapManager::IsValidMapCoord(loc) || sObjectMgr->IsTransportMap(loc.GetMapId()))
if (mapId == MAPID_INVALID)
mapId = player->GetMapId();
if (!MapManager::IsValidMapCoord(mapId, pos) || sObjectMgr->IsTransportMap(mapId))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, loc.GetPositionX(), loc.GetPositionY(), loc.GetMapId());
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, pos.GetPositionX(), pos.GetPositionY(), mapId);
handler->SetSentErrorMessage(true);
return false;
}
@@ -96,7 +98,7 @@ public:
else
player->SaveRecallPosition(); // save only in non-flight case
player->TeleportTo(loc);
player->TeleportTo({ mapId, pos });
return true;
}
@@ -110,7 +112,7 @@ public:
return false;
}
return DoTeleport(handler, spawnpoint->spawnPoint);
return DoTeleport(handler, spawnpoint->spawnPoint, spawnpoint->mapId);
}
static bool HandleGoCreatureCIdCommand(ChatHandler* handler, Variant<Hyperlink<creature_entry>, uint32> cId)
@@ -137,7 +139,7 @@ public:
return false;
}
return DoTeleport(handler, spawnpoint->spawnPoint);
return DoTeleport(handler, spawnpoint->spawnPoint, spawnpoint->mapId);
}
static bool HandleGoGameObjectSpawnIdCommand(ChatHandler* handler, uint32 spawnId)
@@ -150,7 +152,7 @@ public:
return false;
}
return DoTeleport(handler, spawnpoint->spawnPoint);
return DoTeleport(handler, spawnpoint->spawnPoint, spawnpoint->mapId);
}
static bool HandleGoGameObjectGOIdCommand(ChatHandler* handler, uint32 goId)
@@ -177,7 +179,7 @@ public:
return false;
}
return DoTeleport(handler, spawnpoint->spawnPoint);
return DoTeleport(handler, spawnpoint->spawnPoint, spawnpoint->mapId);
}
static bool HandleGoGraveyardCommand(ChatHandler* handler, uint32 gyId)
@@ -247,7 +249,7 @@ public:
handler->SetSentErrorMessage(true);
return false;
}
return DoTeleport(handler, { node->map_id, { node->x, node->y, node->z } });
return DoTeleport(handler, { node->x, node->y, node->z }, node->map_id);
}
static bool HandleGoAreaTriggerCommand(ChatHandler* handler, Variant<Hyperlink<areatrigger>, uint32> areaTriggerId)
@@ -259,7 +261,7 @@ public:
handler->SetSentErrorMessage(true);
return false;
}
return DoTeleport(handler, { at->mapid, { at->x, at->y, at->z } });
return DoTeleport(handler, { at->x, at->y, at->z }, at->mapid);
}
//teleport at coordinates
@@ -357,7 +359,7 @@ public:
z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
}
return DoTeleport(handler, { mapId, { x, y, *z, o.get_value_or(0.0f) } });
return DoTeleport(handler, { x, y, *z, o.get_value_or(0.0f) }, mapId);
}
static bool HandleGoTicketCommand(ChatHandler* handler, uint32 ticketId)
@@ -383,7 +385,7 @@ public:
static bool HandleGoOffsetCommand(ChatHandler* handler, float dX, Optional<float> dY, Optional<float> dZ, Optional<float> dO)
{
WorldLocation loc = handler->GetSession()->GetPlayer()->GetWorldLocation();
Position loc = handler->GetSession()->GetPlayer()->GetPosition();
loc.RelocateOffset({ dX, dY.get_value_or(0.0f), dZ.get_value_or(0.0f), dO.get_value_or(0.0f) });
return DoTeleport(handler, loc);
@@ -548,9 +550,9 @@ public:
handler->PSendSysMessage(LANG_COMMAND_BOSS_MULTIPLE_SPAWNS, boss->Name.c_str(), boss->Entry);
for (CreatureData const* spawn : spawns)
{
uint32 const mapId = spawn->spawnPoint.GetMapId();
uint32 const mapId = spawn->mapId;
MapEntry const* const map = ASSERT_NOTNULL(sMapStore.LookupEntry(mapId));
handler->PSendSysMessage(LANG_COMMAND_BOSS_MULTIPLE_SPAWN_ETY, spawn->spawnId, mapId, map->name[handler->GetSessionDbcLocale()], spawn->spawnPoint.GetPosition().ToString().c_str());
handler->PSendSysMessage(LANG_COMMAND_BOSS_MULTIPLE_SPAWN_ETY, spawn->spawnId, mapId, map->name[handler->GetSessionDbcLocale()], spawn->spawnPoint.ToString().c_str());
}
handler->SetSentErrorMessage(true);
return false;
@@ -563,8 +565,8 @@ public:
player->SaveRecallPosition();
CreatureData const* const spawn = spawns.front();
uint32 const mapId = spawn->spawnPoint.GetMapId();
if (!player->TeleportTo(spawn->spawnPoint))
uint32 const mapId = spawn->mapId;
if (!player->TeleportTo({ mapId, spawn->spawnPoint }))
{
char const* const mapName = ASSERT_NOTNULL(sMapStore.LookupEntry(mapId))->name[handler->GetSessionDbcLocale()];
handler->PSendSysMessage(LANG_COMMAND_GO_BOSS_FAILED, spawn->spawnId, boss->Name.c_str(), boss->Entry, mapName);

View File

@@ -656,7 +656,7 @@ public:
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
SpawnData const& data = pair.second;
if (data.spawnPoint.GetMapId() != mapId)
if (data.mapId != mapId)
continue;
CreatureTemplate const* cTemp = sObjectMgr->GetCreatureTemplate(data.id);
if (!cTemp)
@@ -667,7 +667,7 @@ public:
for (auto const& pair : sObjectMgr->GetAllGameObjectData())
{
SpawnData const& data = pair.second;
if (data.spawnPoint.GetMapId() != mapId)
if (data.mapId != mapId)
continue;
GameObjectTemplate const* goTemp = sObjectMgr->GetGameObjectTemplate(data.id);
if (!goTemp)
@@ -709,25 +709,27 @@ public:
map->GetRespawnInfo(respawns, SpawnObjectTypeMask(1 << type));
for (RespawnInfo const* ri : respawns)
{
SpawnData const* data = sObjectMgr->GetSpawnData(ri->type, ri->spawnId);
SpawnMetadata const* data = sObjectMgr->GetSpawnMetadata(ri->type, ri->spawnId);
if (!data)
continue;
uint32 respawnZoneId = map->GetZoneId(data->spawnPoint);
if (range)
uint32 respawnZoneId = 0;
if (SpawnData const* edata = data->ToSpawnData())
{
if (!player->IsInDist(data->spawnPoint, range))
continue;
respawnZoneId = map->GetZoneId(edata->spawnPoint);
if (range)
{
if (!player->IsInDist(edata->spawnPoint, range))
continue;
}
else
{
if (zoneId != respawnZoneId)
continue;
}
}
else
{
if (zoneId != respawnZoneId)
continue;
}
uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS;
uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS;
std::string respawnTime = ri->respawnTime > GameTime::GetGameTime() ? secsToTimeString(uint64(ri->respawnTime - GameTime::GetGameTime()), true) : stringOverdue;
handler->PSendSysMessage("%u | %u | [%02u,%02u] | %s (%u) | %s%s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(respawnZoneId, locale), respawnZoneId, respawnTime.c_str(), map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? "" : " (inactive)");
}

View File

@@ -763,7 +763,7 @@ public:
return false;
}
if (player->GetMapId() != data->spawnPoint.GetMapId())
if (player->GetMapId() != data->mapId)
{
handler->PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP, lowguid);
handler->SetSentErrorMessage(true);

View File

@@ -380,8 +380,8 @@ class instance_icecrown_citadel : public InstanceMapScript
break;
case NPC_ZAFOD_BOOMBOX:
if (GameObjectTemplate const* go = sObjectMgr->GetGameObjectTemplate(GO_THE_SKYBREAKER_A))
if ((TeamInInstance == ALLIANCE && data->spawnPoint.GetMapId() == go->moTransport.mapID) ||
(TeamInInstance == HORDE && data->spawnPoint.GetMapId() != go->moTransport.mapID))
if ((TeamInInstance == ALLIANCE && data->mapId == go->moTransport.mapID) ||
(TeamInInstance == HORDE && data->mapId != go->moTransport.mapID))
return entry;
return 0;
case NPC_IGB_MURADIN_BRONZEBEARD: