Core/Creature: improve DB linked_respawn handling (#21172)

* Fixed SetCreatureLinkedRespawn function possible erasing/replacing a GameObject link (instead of a creature one)
This commit is contained in:
kelno
2018-01-08 00:32:22 +01:00
committed by joschiwald
parent f0a394753a
commit 70eb18d0e5
7 changed files with 62 additions and 18 deletions

View File

@@ -24,8 +24,9 @@ void WorldDatabaseConnection::DoPrepareStatements()
m_stmts.resize(MAX_WORLDDATABASE_STATEMENTS);
PrepareStatement(WORLD_SEL_QUEST_POOLS, "SELECT entry, pool_entry FROM pool_quest", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_CRELINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_REP_CREATURE_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_DEL_LINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ? AND linkType = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_DEL_LINKED_RESPAWN_MASTER, "DELETE FROM linked_respawn WHERE linkedGuid = ? AND linkType = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_REP_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid, linkType) VALUES (?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH);

View File

@@ -29,8 +29,9 @@ enum WorldDatabaseStatements : uint32
*/
WORLD_SEL_QUEST_POOLS,
WORLD_DEL_CRELINKED_RESPAWN,
WORLD_REP_CREATURE_LINKED_RESPAWN,
WORLD_DEL_LINKED_RESPAWN,
WORLD_DEL_LINKED_RESPAWN_MASTER,
WORLD_REP_LINKED_RESPAWN,
WORLD_SEL_CREATURE_TEXT,
WORLD_SEL_SMART_SCRIPTS,
WORLD_SEL_SMARTAI_WP,

View File

@@ -1792,6 +1792,26 @@ void Creature::DeleteFromDB()
stmt->setUInt32(0, m_spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_CREATURE_TO_CREATURE);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_CREATURE_TO_GO);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN_MASTER);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_CREATURE_TO_CREATURE);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN_MASTER);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_GO_TO_CREATURE);
trans->Append(stmt);
WorldDatabase.CommitTransaction(trans);
// then delete any active instances of the creature

View File

@@ -1029,6 +1029,26 @@ void GameObject::DeleteFromDB()
stmt->setUInt32(0, m_spawnId);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_GO_TO_GO);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_GO_TO_CREATURE);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN_MASTER);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_GO_TO_GO);
trans->Append(stmt);
stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN_MASTER);
stmt->setUInt32(0, m_spawnId);
stmt->setUInt32(1, LINKED_RESPAWN_CREATURE_TO_GO);
trans->Append(stmt);
WorldDatabase.CommitTransaction(trans);
}

View File

@@ -1466,7 +1466,7 @@ void ObjectMgr::LoadLinkedRespawn()
bool error = false;
switch (linkType)
{
case CREATURE_TO_CREATURE:
case LINKED_RESPAWN_CREATURE_TO_CREATURE:
{
CreatureData const* slave = GetCreatureData(guidLow);
if (!slave)
@@ -1503,7 +1503,7 @@ void ObjectMgr::LoadLinkedRespawn()
linkedGuid = ObjectGuid(HighGuid::Unit, master->id, linkedGuidLow);
break;
}
case CREATURE_TO_GO:
case LINKED_RESPAWN_CREATURE_TO_GO:
{
CreatureData const* slave = GetCreatureData(guidLow);
if (!slave)
@@ -1540,7 +1540,7 @@ void ObjectMgr::LoadLinkedRespawn()
linkedGuid = ObjectGuid(HighGuid::GameObject, master->id, linkedGuidLow);
break;
}
case GO_TO_GO:
case LINKED_RESPAWN_GO_TO_GO:
{
GameObjectData const* slave = GetGameObjectData(guidLow);
if (!slave)
@@ -1577,7 +1577,7 @@ void ObjectMgr::LoadLinkedRespawn()
linkedGuid = ObjectGuid(HighGuid::GameObject, master->id, linkedGuidLow);
break;
}
case GO_TO_CREATURE:
case LINKED_RESPAWN_GO_TO_CREATURE:
{
GameObjectData const* slave = GetGameObjectData(guidLow);
if (!slave)
@@ -1636,8 +1636,9 @@ bool ObjectMgr::SetCreatureLinkedRespawn(ObjectGuid::LowType guidLow, ObjectGuid
if (!linkedGuidLow) // we're removing the linking
{
_linkedRespawnStore.erase(guid);
PreparedStatement *stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CRELINKED_RESPAWN);
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_LINKED_RESPAWN);
stmt->setUInt32(0, guidLow);
stmt->setUInt32(1, LINKED_RESPAWN_CREATURE_TO_CREATURE);
WorldDatabase.Execute(stmt);
return true;
}
@@ -1665,9 +1666,10 @@ bool ObjectMgr::SetCreatureLinkedRespawn(ObjectGuid::LowType guidLow, ObjectGuid
ObjectGuid linkedGuid(HighGuid::Unit, slave->id, linkedGuidLow);
_linkedRespawnStore[guid] = linkedGuid;
PreparedStatement *stmt = WorldDatabase.GetPreparedStatement(WORLD_REP_CREATURE_LINKED_RESPAWN);
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_REP_LINKED_RESPAWN);
stmt->setUInt32(0, guidLow);
stmt->setUInt32(1, linkedGuidLow);
stmt->setUInt32(2, LINKED_RESPAWN_CREATURE_TO_CREATURE);
WorldDatabase.Execute(stmt);
return true;
}

View File

@@ -1676,14 +1676,6 @@ class TC_GAME_API ObjectMgr
std::set<uint32> _difficultyEntries[MAX_DIFFICULTY - 1]; // already loaded difficulty 1 value in creatures, used in CheckCreatureTemplate
std::set<uint32> _hasDifficultyEntries[MAX_DIFFICULTY - 1]; // already loaded creatures with difficulty 1 values, used in CheckCreatureTemplate
enum CreatureLinkedRespawnType
{
CREATURE_TO_CREATURE,
CREATURE_TO_GO, // Creature is dependant on GO
GO_TO_GO,
GO_TO_CREATURE // GO is dependant on creature
};
std::set<uint32> _transportMaps; // Helper container storing map ids that are for transports only, loaded from gameobject_template
};

View File

@@ -73,4 +73,12 @@ struct SpawnData
SpawnData(SpawnObjectType t) : type(t) {}
};
enum LinkedRespawnType
{
LINKED_RESPAWN_CREATURE_TO_CREATURE = 0,
LINKED_RESPAWN_CREATURE_TO_GO = 1, // Creature is dependant on GameObject
LINKED_RESPAWN_GO_TO_GO = 2,
LINKED_RESPAWN_GO_TO_CREATURE = 3, // GameObject is dependant on Creature
};
#endif