From 44d037c078166e3e9a5b2f8177b52a71feaf4324 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 25 May 2021 13:55:12 +0200 Subject: [PATCH] [General] Add creature soul values to RecordDynamic packets --- .../openmw-mp/Script/Functions/RecordsDynamic.cpp | 15 +++++++++++++++ .../openmw-mp/Script/Functions/RecordsDynamic.hpp | 11 +++++++++++ apps/openmw/mwmp/RecordHelper.cpp | 3 +++ components/openmw-mp/Base/BaseWorldstate.hpp | 2 ++ .../Packets/Worldstate/PacketRecordDynamic.cpp | 2 ++ 5 files changed, 33 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index a4465c1d1..427a81f84 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -1344,6 +1344,21 @@ void RecordsDynamicFunctions::SetRecordFatigue(int fatigue) noexcept tempOverrides.hasFatigue = true; } +void RecordsDynamicFunctions::SetRecordSoulValue(int soulValue) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE) + tempCreature.data.mData.mSoul = soulValue; + else + { + LOG_MESSAGE_SIMPLE(TimedLog::LOG_ERROR, "Tried to set soul value for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasSoulValue = true; +} + void RecordsDynamicFunctions::SetRecordAIFight(int aiFight) noexcept { unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index ff9d25b32..3749c4069 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -93,6 +93,8 @@ {"SetRecordMagicka", RecordsDynamicFunctions::SetRecordMagicka},\ {"SetRecordFatigue", RecordsDynamicFunctions::SetRecordFatigue},\ \ + {"SetRecordSoulValue", RecordsDynamicFunctions::SetRecordSoulValue},\ + \ {"SetRecordAIFight", RecordsDynamicFunctions::SetRecordAIFight},\ {"SetRecordAIFlee", RecordsDynamicFunctions::SetRecordAIFlee},\ {"SetRecordAIAlarm", RecordsDynamicFunctions::SetRecordAIAlarm},\ @@ -807,6 +809,15 @@ public: */ static void SetRecordFatigue(int fatigue) noexcept; + /** + * \brief Set the soul value of the temporary record stored on the server for the + * currently specified record type. + * + * \param soulValue The soul value of the record. + * \return void + */ + static void SetRecordSoulValue(int soulValue) noexcept; + /** * \brief Set the AI fight value of the temporary record stored on the server for the * currently specified record type. diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index 6c105a0a3..ddaf0ccc5 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -564,6 +564,9 @@ void RecordHelper::overrideRecord(const mwmp::CreatureRecord& record) if (record.baseOverrides.hasFatigue) finalData.mData.mFatigue = recordData.mData.mFatigue; + if (record.baseOverrides.hasSoulValue) + finalData.mData.mSoul = recordData.mData.mSoul; + if (record.baseOverrides.hasAiFight) finalData.mAiData.mFight = recordData.mAiData.mFight; diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 8eaeb5f94..fed41a096 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -132,6 +132,8 @@ namespace mwmp bool hasMagicka = false; bool hasFatigue = false; + bool hasSoulValue = false; + bool hasAiFight = false; bool hasAiFlee = false; bool hasAiAlarm = false; diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index 7446a0399..23815df88 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -551,6 +551,7 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(recordData.mData.mHealth, send); RW(recordData.mData.mMana, send); RW(recordData.mData.mFatigue, send); + RW(recordData.mData.mSoul, send); RW(recordData.mAiData.mFight, send); RW(recordData.mAiData.mFlee, send); RW(recordData.mAiData.mAlarm, send); @@ -571,6 +572,7 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) RW(overrides.hasHealth, send); RW(overrides.hasMagicka, send); RW(overrides.hasFatigue, send); + RW(overrides.hasSoulValue, send); RW(overrides.hasAiFight, send); RW(overrides.hasAiFlee, send); RW(overrides.hasAiAlarm, send);