diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index 4f22347f9..b46e2678b 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -295,6 +295,16 @@ double RecordsDynamicFunctions::GetRecordWeight(unsigned int index) noexcept return -1; } +unsigned int RecordsDynamicFunctions::GetRecordQuantity(unsigned int index) noexcept +{ + unsigned short readRecordsType = RecordsDynamicFunctions::GetRecordType(); + + if (readRecordsType == mwmp::RECORD_TYPE::POTION) + return WorldstateFunctions::readWorldstate->potionRecords.at(index).quantity; + + return 1; +} + unsigned int RecordsDynamicFunctions::GetRecordEffectId(unsigned int recordIndex, unsigned int effectIndex) noexcept { return GetRecordEffects(recordIndex).mList.at(effectIndex).mEffectID; diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index 3487452d3..3c0e7180d 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -27,6 +27,7 @@ {"GetRecordFlags", RecordsDynamicFunctions::GetRecordFlags},\ {"GetRecordValue", RecordsDynamicFunctions::GetRecordValue},\ {"GetRecordWeight", RecordsDynamicFunctions::GetRecordWeight},\ + {"GetRecordQuantity", RecordsDynamicFunctions::GetRecordQuantity},\ \ {"GetRecordEffectId", RecordsDynamicFunctions::GetRecordEffectId},\ {"GetRecordEffectAttribute", RecordsDynamicFunctions::GetRecordEffectAttribute},\ @@ -300,6 +301,15 @@ public: */ static double GetRecordWeight(unsigned int index) noexcept; + /** + * \brief Get the quantity of the record at a certain index in the read worldstate's + * dynamic records of the current type. + * + * \param index The index of the record. + * \return The brewed count of the record. + */ + static unsigned int GetRecordQuantity(unsigned int index) noexcept; + /** * \brief Get the ID of the effect at a certain index in the read worldstate's * current records. diff --git a/apps/openmw/mwmechanics/alchemy.cpp b/apps/openmw/mwmechanics/alchemy.cpp index 9c6f8e6e0..743f41ce3 100644 --- a/apps/openmw/mwmechanics/alchemy.cpp +++ b/apps/openmw/mwmechanics/alchemy.cpp @@ -317,8 +317,8 @@ void MWMechanics::Alchemy::addPotion (const std::string& name) Start of tes3mp change (major) Don't create a record and don't add the potion to the player's inventory; - instead just send its record to the server and expect the server to add it - to the player's inventory + instead just store its record in preparation for sending it to the server + and expect the server to add it to the player's inventory */ /* const ESM::Potion* record = getRecord(newRecord); @@ -329,8 +329,7 @@ void MWMechanics::Alchemy::addPotion (const std::string& name) mAlchemist.getClass().getContainerStore (mAlchemist).add (record->mId, 1, mAlchemist); */ - - mwmp::Main::get().getNetworking()->getWorldstate()->sendPotionRecord(&newRecord); + mStoredPotion = newRecord; /* End of tes3mp change (major) */ @@ -546,6 +545,18 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na } count = brewedCount; + + /* + Start of tes3mp addition + + Send an ID_RECORD_DYNAMIC packet with the potion we've been creating + now that we know its quantity + */ + mwmp::Main::get().getNetworking()->getWorldstate()->sendPotionRecord(&mStoredPotion, brewedCount); + /* + End of tes3mp addition + */ + return result; } diff --git a/apps/openmw/mwmechanics/alchemy.hpp b/apps/openmw/mwmechanics/alchemy.hpp index 9f9f0b21c..b700e3a46 100644 --- a/apps/openmw/mwmechanics/alchemy.hpp +++ b/apps/openmw/mwmechanics/alchemy.hpp @@ -4,6 +4,16 @@ #include #include +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include +/* + End of tes3mp addition +*/ + #include #include "../mwworld/ptr.hpp" @@ -53,6 +63,17 @@ namespace MWMechanics int mValue; std::string mPotionName; + /* + Start of tes3mp addition + + Keep a copy of the last created potion record so it can be sent to the + server once we have determined its brewedCount + */ + ESM::Potion mStoredPotion; + /* + End of tes3mp addition + */ + void applyTools (int flags, float& value) const; void updateEffects(); diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index a4b97c13a..7efbcf6fc 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -522,7 +522,7 @@ void Worldstate::sendEnchantmentRecord(const ESM::Enchantment* enchantment) getNetworking()->getWorldstatePacket(ID_RECORD_DYNAMIC)->Send(); } -void Worldstate::sendPotionRecord(const ESM::Potion* potion) +void Worldstate::sendPotionRecord(const ESM::Potion* potion, unsigned int quantity) { potionRecords.clear(); @@ -532,6 +532,7 @@ void Worldstate::sendPotionRecord(const ESM::Potion* potion) mwmp::PotionRecord record; record.data = *potion; + record.quantity = quantity; potionRecords.push_back(record); getNetworking()->getWorldstatePacket(ID_RECORD_DYNAMIC)->setWorldstate(this); diff --git a/apps/openmw/mwmp/Worldstate.hpp b/apps/openmw/mwmp/Worldstate.hpp index 695a9d814..8551815be 100644 --- a/apps/openmw/mwmp/Worldstate.hpp +++ b/apps/openmw/mwmp/Worldstate.hpp @@ -29,7 +29,7 @@ namespace mwmp void sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor); void sendEnchantmentRecord(const ESM::Enchantment* enchantment); - void sendPotionRecord(const ESM::Potion* potion); + void sendPotionRecord(const ESM::Potion* potion, unsigned int quantity); void sendSpellRecord(const ESM::Spell* spell); void sendArmorRecord(const ESM::Armor* armor, std::string baseRefId = ""); diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 6ff653803..8810e3d4f 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -260,6 +260,7 @@ namespace mwmp struct PotionRecord { ESM::Potion data; + unsigned int quantity = 1; std::string baseId; BaseOverrides baseOverrides; }; diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index d4766dc39..ed28b55be 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -167,6 +167,7 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send) { auto &recordData = record.data; + RW(record.quantity, send); RW(record.baseId, send, true); RW(recordData.mId, send, true); RW(recordData.mName, send, true);