-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
refactor(Core/DB): normalize creature table by extracting multi-ID spawns #25197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad9b4bf
0340ec1
99f8b08
7c4862e
fe7d88a
7712f24
97f701f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||
| -- Create creature_multispawn table for multi-ID spawning | ||||||||||||||||||||||||||||
| CREATE TABLE IF NOT EXISTS `creature_multispawn` ( | ||||||||||||||||||||||||||||
| `spawnId` int unsigned NOT NULL COMMENT 'creature.guid', | ||||||||||||||||||||||||||||
| `entry` int unsigned NOT NULL COMMENT 'creature_template.entry', | ||||||||||||||||||||||||||||
| PRIMARY KEY (`spawnId`, `entry`) | ||||||||||||||||||||||||||||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Additional creature entries for multi-ID spawning'; | ||||||||||||||||||||||||||||
|
Comment on lines
+2
to
+6
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enforce parent-child cleanup for Line 2 introduces a child table keyed by 🔧 Suggested fix CREATE TABLE IF NOT EXISTS `creature_multispawn` (
- `spawnId` int unsigned NOT NULL COMMENT 'creature.guid',
- `entry` int unsigned NOT NULL COMMENT 'creature_template.entry',
- PRIMARY KEY (`spawnId`, `entry`)
+ `spawnId` int unsigned NOT NULL COMMENT 'creature.guid',
+ `entry` int unsigned NOT NULL COMMENT 'creature_template.entry',
+ PRIMARY KEY (`spawnId`, `entry`),
+ CONSTRAINT `fk_creature_multispawn_spawn`
+ FOREIGN KEY (`spawnId`) REFERENCES `creature` (`guid`)
+ ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Additional creature entries for multi-ID spawning';📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| -- Migrate id2 and id3 entries | ||||||||||||||||||||||||||||
| DELETE FROM `creature_multispawn`; | ||||||||||||||||||||||||||||
| INSERT IGNORE INTO `creature_multispawn` (`spawnId`, `entry`) | ||||||||||||||||||||||||||||
| SELECT `guid`, `id2` FROM `creature` WHERE `id2` != 0 | ||||||||||||||||||||||||||||
| UNION ALL | ||||||||||||||||||||||||||||
| SELECT `guid`, `id3` FROM `creature` WHERE `id3` != 0; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| -- Drop old index before column rename | ||||||||||||||||||||||||||||
| ALTER TABLE `creature` DROP INDEX `idx_id`; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| -- Rename id1 -> id | ||||||||||||||||||||||||||||
| ALTER TABLE `creature` CHANGE COLUMN `id1` `id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Creature Identifier'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| -- Drop id2, id3 | ||||||||||||||||||||||||||||
| ALTER TABLE `creature` DROP COLUMN `id2`, DROP COLUMN `id3`; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| -- Recreate index on renamed column | ||||||||||||||||||||||||||||
| ALTER TABLE `creature` ADD INDEX `idx_id` (`id`); | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1423,7 +1423,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask) | |||||||||
| dynamicflags = 0; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| data.id1 = GetEntry(); | ||||||||||
| data.id = GetEntry(); | ||||||||||
| data.mapid = mapid; | ||||||||||
| data.phaseMask = phaseMask; | ||||||||||
| data.displayid = displayId; | ||||||||||
|
|
@@ -1469,8 +1469,6 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask) | |||||||||
| stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_CREATURE); | ||||||||||
| stmt->SetData(index++, m_spawnId); | ||||||||||
| stmt->SetData(index++, GetEntry()); | ||||||||||
| stmt->SetData(index++, 0); | ||||||||||
| stmt->SetData(index++, 0); | ||||||||||
| stmt->SetData(index++, uint16(mapid)); | ||||||||||
| stmt->SetData(index++, spawnMask); | ||||||||||
| stmt->SetData(index++, GetPhaseMask()); | ||||||||||
|
|
@@ -1725,7 +1723,7 @@ bool Creature::LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map* map, bool ad | |||||||||
| || !groupData || (groupData->flags & SPAWNGROUP_FLAG_COMPATIBILITY_MODE); | ||||||||||
|
|
||||||||||
| // Add to world | ||||||||||
| uint32 entry = GetRandomId(data->id1, data->id2, data->id3); | ||||||||||
| uint32 entry = GetRandomId(data->id, data->id2, data->id3); | ||||||||||
|
|
||||||||||
| if (!Create(map->GenerateLowGuid<HighGuid::Unit>(), map, data->phaseMask, entry, 0, data->posX, data->posY, data->posZ, data->orientation, data)) | ||||||||||
| return false; | ||||||||||
|
|
@@ -2041,7 +2039,7 @@ void Creature::Respawn(bool force) | |||||||||
| if (!allowed && !force) // Will be rechecked on next Update call | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(m_creatureData ? m_creatureData->id1 : GetEntry(), m_spawnId); | ||||||||||
| ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(m_creatureData ? m_creatureData->id : GetEntry(), m_spawnId); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap the linked-respawn GUID construction. Line 2042 exceeds the project’s 80-column limit; split the ternary input before merge. As per coding guidelines, Proposed formatting fix- ObjectGuid dbtableHighGuid = ObjectGuid::Create<HighGuid::Unit>(m_creatureData ? m_creatureData->id : GetEntry(), m_spawnId);
+ uint32 const dbEntry = m_creatureData ? m_creatureData->id : GetEntry();
+ ObjectGuid dbtableHighGuid =
+ ObjectGuid::Create<HighGuid::Unit>(dbEntry, m_spawnId);📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||
| time_t linkedRespawntime = GetMap()->GetLinkedRespawnTime(dbtableHighGuid); | ||||||||||
|
|
||||||||||
| CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(GetEntry()); | ||||||||||
|
|
@@ -2061,7 +2059,7 @@ void Creature::Respawn(bool force) | |||||||||
| // Respawn check if spawn has 2 entries | ||||||||||
| if (data->id2) | ||||||||||
| { | ||||||||||
| uint32 entry = GetRandomId(data->id1, data->id2, data->id3); | ||||||||||
| uint32 entry = GetRandomId(data->id, data->id2, data->id3); | ||||||||||
| UpdateEntry(entry, data, true); // Select Random Entry | ||||||||||
| m_defaultMovementType = MovementGeneratorType(data->movementType); // Reload Movement Type | ||||||||||
| LoadEquipment(data->equipmentId); // Reload Equipment | ||||||||||
|
|
@@ -3169,7 +3167,7 @@ uint32 Creature::GetScriptId() const | |||||||||
| if (CreatureData const* creatureData = GetCreatureData()) | ||||||||||
| { | ||||||||||
| uint32 scriptId = creatureData->ScriptId; | ||||||||||
| if (scriptId && GetEntry() == creatureData->id1) | ||||||||||
| if (scriptId && GetEntry() == creatureData->id) | ||||||||||
| return scriptId; | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.