aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-09-21 00:45:27 +0200
committerShauren <shauren.trinity@gmail.com>2025-09-21 00:45:27 +0200
commit203ad17560057b3bf70a1632f3d715e429512701 (patch)
treefd1ae75fe23f8353223f57d36cf7beec53f03639
parentc3bc6f568b0cba2149ce3e3a3e138bf54d82aa79 (diff)
Core/Objects: Preserve phaseUseFlags, terrainSwapMap, ScriptName and StringId columns when saving creature and gameobject spawns in database
Closes #31291
-rw-r--r--src/server/database/Database/Implementation/WorldDatabase.cpp4
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp29
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp24
3 files changed, 37 insertions, 20 deletions
diff --git a/src/server/database/Database/Implementation/WorldDatabase.cpp b/src/server/database/Database/Implementation/WorldDatabase.cpp
index d26903117d4..201a2e83c4e 100644
--- a/src/server/database/Database/Implementation/WorldDatabase.cpp
+++ b/src/server/database/Database/Implementation/WorldDatabase.cpp
@@ -67,10 +67,10 @@ void WorldDatabaseConnection::DoPrepareStatements()
PrepareStatement(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_CREATURE_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM creature WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH);
- PrepareStatement(WORLD_INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnDifficulties, PhaseId, PhaseGroup, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, wander_distance, currentwaypoint, curHealthPct, MovementType, npcflag, unit_flags, unit_flags2, unit_flags3) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
+ PrepareStatement(WORLD_INS_CREATURE, "INSERT INTO creature (guid, id , map, spawnDifficulties, phaseUseFlags, PhaseId, PhaseGroup, terrainSwapMap, modelid, equipment_id, position_x, position_y, position_z, orientation, spawntimesecs, wander_distance, currentwaypoint, curHealthPct, MovementType, npcflag, unit_flags, unit_flags2, unit_flags3, ScriptName, StringId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_DEL_GAME_EVENT_CREATURE, "DELETE FROM game_event_creature WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_DEL_GAME_EVENT_MODEL_EQUIP, "DELETE FROM game_event_model_equip WHERE guid = ?", CONNECTION_ASYNC);
- PrepareStatement(WORLD_INS_GAMEOBJECT, "INSERT INTO gameobject (guid, id, map, spawnDifficulties, PhaseId, PhaseGroup, position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
+ PrepareStatement(WORLD_INS_GAMEOBJECT, "INSERT INTO gameobject (guid, id, map, spawnDifficulties, phaseUseFlags, PhaseId, PhaseGroup, terrainSwapMap, position_x, position_y, position_z, orientation, rotation0, rotation1, rotation2, rotation3, spawntimesecs, animprogress, state, ScriptName, StringId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_INS_DISABLES, "INSERT INTO disables (entry, sourceType, flags, comment) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(WORLD_SEL_DISABLES, "SELECT entry FROM disables WHERE entry = ? AND sourceType = ?", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_DISABLES, "DELETE FROM disables WHERE entry = ? AND sourceType = ?", CONNECTION_ASYNC);
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 472610d4c0f..8d89686e32f 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -1558,20 +1558,22 @@ void Creature::SaveToDB(uint32 mapid, std::vector<Difficulty> const& spawnDiffic
stmt->setUInt16(index++, uint16(mapid));
stmt->setString(index++, [&data]() -> std::string
{
- if (data.spawnDifficulties.empty())
- return "";
-
std::ostringstream os;
- auto itr = data.spawnDifficulties.begin();
- os << int32(*itr++);
+ if (!data.spawnDifficulties.empty())
+ {
+ auto itr = data.spawnDifficulties.begin();
+ os << int32(*itr++);
- for (; itr != data.spawnDifficulties.end(); ++itr)
- os << ',' << int32(*itr);
+ for (; itr != data.spawnDifficulties.end(); ++itr)
+ os << ',' << int32(*itr);
+ }
- return os.str();
+ return std::move(os).str();
}());
+ stmt->setUInt8(index++, data.phaseUseFlags);
stmt->setUInt32(index++, data.phaseId);
stmt->setUInt32(index++, data.phaseGroup);
+ stmt->setInt32(index++, data.terrainSwapMap);
stmt->setUInt32(index++, displayId);
stmt->setUInt8(index++, GetCurrentEquipmentId());
stmt->setFloat(index++, GetPositionX());
@@ -1602,6 +1604,13 @@ void Creature::SaveToDB(uint32 mapid, std::vector<Difficulty> const& spawnDiffic
stmt->setUInt32(index++, *unitFlags3);
else
stmt->setNull(index++);
+
+ stmt->setString(index++, sObjectMgr->GetScriptName(data.scriptId));
+ if (std::string_view stringId = GetStringId(StringIdType::Spawn); !stringId.empty())
+ stmt->setString(index++, stringId);
+ else
+ stmt->setNull(index++);
+
trans->Append(stmt);
WorldDatabase.CommitTransaction(trans);
@@ -3069,8 +3078,8 @@ uint64 Creature::GetMaxHealthByLevel(uint8 level) const
{
CreatureTemplate const* cInfo = GetCreatureTemplate();
CreatureDifficulty const* creatureDifficulty = GetCreatureDifficulty();
- float baseHealth = sDB2Manager.EvaluateExpectedStat(ExpectedStatType::CreatureHealth, level, creatureDifficulty->GetHealthScalingExpansion(), creatureDifficulty->ContentTuningID, Classes(cInfo->unit_class), 0);
- return std::max(baseHealth * creatureDifficulty->HealthModifier, 1.0f);
+ double baseHealth = sDB2Manager.EvaluateExpectedStat(ExpectedStatType::CreatureHealth, level, creatureDifficulty->GetHealthScalingExpansion(), creatureDifficulty->ContentTuningID, Classes(cInfo->unit_class), 0);
+ return std::max(baseHealth * creatureDifficulty->HealthModifier, 1.0);
}
float Creature::GetHealthMultiplierForTarget(WorldObject const* target) const
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 31aee1f9daf..d0076bc282b 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -1911,20 +1911,22 @@ void GameObject::SaveToDB(uint32 mapid, std::vector<Difficulty> const& spawnDiff
stmt->setUInt16(index++, uint16(mapid));
stmt->setString(index++, [&data]() -> std::string
{
- if (data.spawnDifficulties.empty())
- return "";
-
std::ostringstream os;
- auto itr = data.spawnDifficulties.begin();
- os << int32(*itr++);
+ if (!data.spawnDifficulties.empty())
+ {
+ auto itr = data.spawnDifficulties.begin();
+ os << int32(*itr++);
- for (; itr != data.spawnDifficulties.end(); ++itr)
- os << ',' << int32(*itr);
+ for (; itr != data.spawnDifficulties.end(); ++itr)
+ os << ',' << int32(*itr);
+ }
- return os.str();
+ return std::move(os).str();
}());
+ stmt->setUInt8(index++, data.phaseUseFlags);
stmt->setUInt32(index++, data.phaseId);
stmt->setUInt32(index++, data.phaseGroup);
+ stmt->setInt32(index++, data.terrainSwapMap);
stmt->setFloat(index++, GetPositionX());
stmt->setFloat(index++, GetPositionY());
stmt->setFloat(index++, GetPositionZ());
@@ -1936,6 +1938,12 @@ void GameObject::SaveToDB(uint32 mapid, std::vector<Difficulty> const& spawnDiff
stmt->setInt32(index++, int32(m_respawnDelayTime));
stmt->setUInt8(index++, GetGoAnimProgress());
stmt->setUInt8(index++, uint8(GetGoState()));
+ stmt->setString(index++, sObjectMgr->GetScriptName(data.scriptId));
+ if (std::string_view stringId = GetStringId(StringIdType::Spawn); !stringId.empty())
+ stmt->setString(index++, stringId);
+ else
+ stmt->setNull(index++);
+
trans->Append(stmt);
WorldDatabase.CommitTransaction(trans);