From 06ea822a315a771fa0b3410716361b9df091cf6f Mon Sep 17 00:00:00 2001 From: ModoX Date: Thu, 31 Aug 2023 12:15:03 +0200 Subject: [PATCH] Core/Creature: Save npcflags and unitflags as NULL in db if they are equivalent to creature_template entry Closes #29297 --- .../game/Entities/Creature/Creature.cpp | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 687f1e924d..dc3c4b86a3 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -1421,10 +1421,10 @@ void Creature::SaveToDB(uint32 mapid, std::vector const& spawnDiffic CreatureData& data = sObjectMgr->NewOrExistCreatureData(m_spawnId); uint32 displayId = GetNativeDisplayId(); - uint64 npcflag = (uint64(m_unitData->NpcFlags[1]) << 32) | m_unitData->NpcFlags[0]; - uint32 unitFlags = m_unitData->Flags; - uint32 unitFlags2 = m_unitData->Flags2; - uint32 unitFlags3 = m_unitData->Flags3; + Optional npcflag; + Optional unitFlags; + Optional unitFlags2; + Optional unitFlags3; // check if it's a custom model and if not, use 0 for displayId CreatureTemplate const* cinfo = GetCreatureTemplate(); @@ -1434,17 +1434,17 @@ void Creature::SaveToDB(uint32 mapid, std::vector const& spawnDiffic if (displayId && displayId == model.CreatureDisplayID) displayId = 0; - if (npcflag == cinfo->npcflag) - npcflag = 0; + if (npcflag != cinfo->npcflag) + unitFlags = (uint64(m_unitData->NpcFlags[1]) << 32) | m_unitData->NpcFlags[0]; - if (unitFlags == cinfo->unit_flags) - unitFlags = 0; + if (unitFlags != cinfo->unit_flags) + unitFlags = m_unitData->Flags; - if (unitFlags2 == cinfo->unit_flags2) - unitFlags2 = 0; + if (unitFlags2 != cinfo->unit_flags2) + unitFlags = m_unitData->Flags2; - if (unitFlags3 == cinfo->unit_flags3) - unitFlags3 = 0; + if (unitFlags3 != cinfo->unit_flags3) + unitFlags = m_unitData->Flags3; } if (!data.spawnId) @@ -1524,10 +1524,25 @@ void Creature::SaveToDB(uint32 mapid, std::vector const& spawnDiffic stmt->setUInt32(index++, GetHealth()); stmt->setUInt32(index++, GetPower(POWER_MANA)); stmt->setUInt8(index++, uint8(GetDefaultMovementType())); - stmt->setUInt64(index++, npcflag); - stmt->setUInt32(index++, unitFlags); - stmt->setUInt32(index++, unitFlags2); - stmt->setUInt32(index++, unitFlags3); + if (npcflag.has_value()) + stmt->setUInt64(index++, *npcflag); + else + stmt->setNull(index++); + + if (unitFlags.has_value()) + stmt->setUInt32(index++, *unitFlags); + else + stmt->setNull(index++); + + if (unitFlags2.has_value()) + stmt->setUInt32(index++, *unitFlags2); + else + stmt->setNull(index++); + + if (unitFlags3.has_value()) + stmt->setUInt32(index++, *unitFlags3); + else + stmt->setNull(index++); trans->Append(stmt); WorldDatabase.CommitTransaction(trans);