diff options
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 687f1e924d3..dc3c4b86a32 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<Difficulty> 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<uint64> npcflag; + Optional<uint32> unitFlags; + Optional<uint32> unitFlags2; + Optional<uint32> 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<Difficulty> 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<Difficulty> 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); |