refactor(Core/DB): normalize creature table by extracting multi-ID spawns (#25197)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Ludwig <sudlud@users.noreply.github.com>
This commit is contained in:
Andrew
2026-06-16 01:17:38 -03:00
committed by GitHub
parent eb3cdd1d1f
commit cf0d86a9ff
22 changed files with 281 additions and 200 deletions
+2 -2
View File
@@ -609,7 +609,7 @@ public:
CreatureData const* spawnpoint = nullptr;
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
if (pair.second.id1 != entry)
if (pair.second.id != entry)
{
continue;
}
@@ -633,7 +633,7 @@ public:
std::vector<CreatureData const*> spawnpoints;
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
if (pair.second.id1 != entry)
if (pair.second.id != entry)
{
continue;
}
+8 -8
View File
@@ -77,19 +77,19 @@ public:
QueryResult result;
uint32 creatureCount = 0;
result = WorldDatabase.Query("SELECT COUNT(guid) FROM creature WHERE id1='{}' OR id2='{}' OR id3='{}'", uint32(creatureId), uint32(creatureId), uint32(creatureId));
result = WorldDatabase.Query("SELECT COUNT(guid) FROM creature WHERE id = '{}' OR guid IN (SELECT spawnId FROM creature_multispawn WHERE entry = '{}')", uint32(creatureId), uint32(creatureId));
if (result)
creatureCount = (*result)[0].Get<uint64>();
if (handler->GetSession())
{
Player* player = handler->GetSession()->GetPlayer();
result = WorldDatabase.Query("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '{}', 2) + POW(position_y - '{}', 2) + POW(position_z - '{}', 2)) AS order_ FROM creature WHERE id1='{}' OR id2='{}' OR id3='{}' ORDER BY order_ ASC LIMIT {}",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), uint32(creatureId), uint32(creatureId), uint32(creatureId), count);
result = WorldDatabase.Query("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '{}', 2) + POW(position_y - '{}', 2) + POW(position_z - '{}', 2)) AS order_ FROM creature WHERE id = '{}' OR guid IN (SELECT spawnId FROM creature_multispawn WHERE entry = '{}') ORDER BY order_ ASC LIMIT {}",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), uint32(creatureId), uint32(creatureId), count);
}
else
result = WorldDatabase.Query("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id1='{}' OR id2='{}' OR id3='{}' LIMIT {}",
uint32(creatureId), uint32(creatureId), uint32(creatureId), count);
result = WorldDatabase.Query("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '{}' OR guid IN (SELECT spawnId FROM creature_multispawn WHERE entry = '{}') LIMIT {}",
uint32(creatureId), uint32(creatureId), count);
if (result)
{
@@ -557,13 +557,13 @@ public:
for (auto const& pair : map->GetCreatureRespawnTimes())
{
CreatureData const* data = sObjectMgr->GetCreatureData(pair.first);
if (!data || (entryFilter && data->id1 != *entryFilter))
if (!data || (entryFilter && data->id != *entryFilter))
continue;
CreatureTemplate const* cTemplate = sObjectMgr->GetCreatureTemplate(data->id1);
CreatureTemplate const* cTemplate = sObjectMgr->GetCreatureTemplate(data->id);
std::string name = cTemplate ? cTemplate->Name : "Unknown";
time_t remaining = pair.second > now ? pair.second - now : 0;
handler->PSendSysMessage(LANG_LIST_RESPAWNS_CREATURE_ENTRY, pair.first, name, data->id1, remaining);
handler->PSendSysMessage(LANG_LIST_RESPAWNS_CREATURE_ENTRY, pair.first, name, data->id, remaining);
++count;
if (count >= 50)
{
+4 -4
View File
@@ -2492,7 +2492,7 @@ public:
if (isAlive)
{
handler->PSendSysMessage(LANG_RESPAWN_GUID_CREATURE_ALIVE, spawnId, creData->id1);
handler->PSendSysMessage(LANG_RESPAWN_GUID_CREATURE_ALIVE, spawnId, creData->id);
return true;
}
@@ -2508,7 +2508,7 @@ public:
time_t now = GameTime::GetGameTime().count();
map->SaveCreatureRespawnTime(spawnId, now);
}
handler->PSendSysMessage(LANG_RESPAWN_GUID_CREATURE_QUEUED, spawnId, creData->id1);
handler->PSendSysMessage(LANG_RESPAWN_GUID_CREATURE_QUEUED, spawnId, creData->id);
return true;
}
@@ -2608,7 +2608,7 @@ public:
for (auto const& [spawnId, creature] : map->GetCreatureBySpawnIdStore())
{
CreatureData const* data = sObjectMgr->GetCreatureData(spawnId);
if (!data || data->id1 != entry)
if (!data || data->id != entry)
continue;
if (creature->isDead())
deadCreatures.push_back(creature);
@@ -2624,7 +2624,7 @@ public:
for (auto const& [spawnId, respawnTime] : map->GetCreatureRespawnTimes())
{
CreatureData const* data = sObjectMgr->GetCreatureData(spawnId);
if (!data || data->id1 != entry)
if (!data || data->id != entry)
continue;
if (sPoolMgr->IsPartOfAPool<Creature>(spawnId))
continue;
+9 -11
View File
@@ -229,7 +229,7 @@ public:
{
ObjectGuid::LowType guid = sObjectMgr->GenerateCreatureSpawnId();
CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
data.id1 = id;
data.id = id;
data.phaseMask = chr->GetPhaseMaskForSpawn();
data.posX = chr->GetTransOffsetX();
data.posY = chr->GetTransOffsetY();
@@ -677,7 +677,7 @@ public:
uint32 id3 = 0;
if (CreatureData const* cData = target->GetCreatureData())
{
id1 = cData->id1;
id1 = cData->id;
id2 = cData->id2;
id3 = cData->id3;
}
@@ -721,7 +721,7 @@ public:
static bool HandleNpcInfoCommandShowFromDB(ChatHandler* handler, ObjectGuid::LowType lowGuid, CreatureData const* cData)
{
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(cData->id1);
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(cData->id);
if (!cInfo)
{
handler->SendErrorMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowGuid);
@@ -730,7 +730,7 @@ public:
handler->PSendSysMessage("(Not in world - showing DB data)");
uint32 scriptId = cData->ScriptId ? cData->ScriptId : cInfo->ScriptID;
handler->PSendSysMessage(LANG_NPCINFO_CHAR, lowGuid, ObjectGuid::Create<HighGuid::Unit>(cData->id1, lowGuid).ToString(), cData->id1,
handler->PSendSysMessage(LANG_NPCINFO_CHAR, lowGuid, ObjectGuid::Create<HighGuid::Unit>(cData->id, lowGuid).ToString(), cData->id,
cData->id2, cData->id3, cData->displayid, cData->displayid, cInfo->faction,
cData->npcflag);
handler->PSendSysMessage(LANG_NPCINFO_PHASEMASK, cData->phaseMask);
@@ -763,7 +763,7 @@ public:
uint32 id3 = 0;
if (CreatureData const* cData = target->GetCreatureData())
{
id1 = cData->id1;
id1 = cData->id;
id2 = cData->id2;
id3 = cData->id3;
}
@@ -835,12 +835,10 @@ public:
continue;
uint32 entry = fields[1].Get<uint32>();
//uint32 entry2 = fields[2].Get<uint32>();
//uint32 entry3 = fields[3].Get<uint32>();
float x = fields[4].Get<float>();
float y = fields[5].Get<float>();
float z = fields[6].Get<float>();
uint16 mapId = fields[7].Get<uint16>();
float x = fields[2].Get<float>();
float y = fields[3].Get<float>();
float z = fields[4].Get<float>();
uint16 mapId = fields[5].Get<uint16>();
CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
if (!creatureTemplate)
+1 -1
View File
@@ -78,7 +78,7 @@ private:
{
if (CreatureData const* data = sObjectMgr->GetCreatureData(obj.guid))
{
entry = data->id1;
entry = data->id;
mapId = data->mapid;
x = data->posX;
y = data->posY;
+3 -3
View File
@@ -309,7 +309,7 @@ public:
CreatureData const* spawnpoint = nullptr;
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
if (pair.second.id1 != *creatureId)
if (pair.second.id != *creatureId)
continue;
if (!spawnpoint)
@@ -341,7 +341,7 @@ public:
return false;
}
CreatureTemplate const* creatureTemplate = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(spawnpoint->id1));
CreatureTemplate const* creatureTemplate = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(spawnpoint->id));
return DoNameTeleport(handler, player, spawnpoint->mapid, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, creatureTemplate->Name);
}
@@ -352,7 +352,7 @@ public:
WorldDatabase.EscapeString(normalizedName);
// May need work //PussyWizardEliteMalcrom
QueryResult result = WorldDatabase.Query("SELECT c.position_x, c.position_y, c.position_z, c.orientation, c.map, ct.name FROM creature c INNER JOIN creature_template ct ON c.id1 = ct.entry WHERE ct.name LIKE '{}'", normalizedName);
QueryResult result = WorldDatabase.Query("SELECT c.position_x, c.position_y, c.position_z, c.orientation, c.map, ct.name FROM creature c INNER JOIN creature_template ct ON c.id = ct.entry WHERE ct.name LIKE '{}'", normalizedName);
if (!result)
{
handler->SendErrorMessage(LANG_COMMAND_GOCREATNOTFOUND);
+1 -1
View File
@@ -1037,7 +1037,7 @@ public:
if (show == "off")
{
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_BY_ID);
stmt->SetArguments(1, 1, 1);
stmt->SetArguments(1, 1);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (!result)
@@ -428,7 +428,7 @@ struct npc_ahnqiraji_critter : public ScriptedAI
// Don't attack nearby players randomly if they are the Twin's pet bugs.
if (CreatureData const* crData = me->GetCreatureData())
{
ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(crData->id1, me->GetSpawnId());
ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(crData->id, me->GetSpawnId());
ObjectGuid targetGuid = sObjectMgr->GetLinkedRespawnGuid(dbtableHighGuid);
if (targetGuid.GetEntry() == NPC_VEKLOR)
@@ -84,7 +84,7 @@ public:
uint32 GetCreatureEntry(ObjectGuid::LowType /*guidLow*/, CreatureData const* data) override
{
uint32 entry = data->id1;
uint32 entry = data->id;
switch (entry)
{
case NPC_RESCUED_ALLIANCE_SLAVE:
@@ -1045,7 +1045,7 @@ public:
if (Creature* crusader = ObjectAccessor::GetCreature(*me, instance->GetGuidData(DATA_CAPTAIN_ARNATH + i)))
if (crusader->IsAlive())
{
if (crusader->GetEntry() == crusader->GetCreatureData()->id1)
if (crusader->GetEntry() == crusader->GetCreatureData()->id)
{
crusader->m_Events.AddEventAtOffset(new CaptainSurviveTalk(*crusader), delay);
delay += 6s;
@@ -1235,7 +1235,7 @@ public:
void Reset() override
{
me->SetCorpseDelay(DAY); // leave corpse for a long time so svalna can resurrect
IsUndead = (me->GetCreatureData() && me->GetCreatureData()->id1 != me->GetEntry());
IsUndead = (me->GetCreatureData() && me->GetCreatureData()->id != me->GetEntry());
}
void JustDied(Unit* /*killer*/) override
@@ -539,7 +539,7 @@ public:
uint32 GetCreatureEntry(ObjectGuid::LowType /*guidLow*/, CreatureData const* data) override
{
uint32 entry = data->id1;
uint32 entry = data->id;
switch (entry)
{
case NPC_HORDE_GUNSHIP_CANNON: