diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index 92593e208..5e116ceb1 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -303,6 +303,8 @@ unsigned int RecordsDynamicFunctions::GetRecordQuantity(unsigned int index) noex if (readRecordsType == mwmp::RECORD_TYPE::POTION) return WorldstateFunctions::readWorldstate->potionRecords.at(index).quantity; + else if (readRecordsType == mwmp::RECORD_TYPE::WEAPON) + return WorldstateFunctions::readWorldstate->weaponRecords.at(index).quantity; return 1; } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index c2740c2f7..ee59950b6 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -8,6 +8,7 @@ #include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" +#include "../mwmp/LocalPlayer.hpp" /* End of tes3mp addition */ @@ -320,7 +321,9 @@ namespace MWClass Send the newly created record to the server and expect it to be returned with a server-set id */ - mwmp::Main::get().getNetworking()->getWorldstate()->sendWeaponRecord(&newItem, ref->mBase->mId); + unsigned int quantity = mwmp::Main::get().getLocalPlayer()->lastEnchantmentQuantity; + + mwmp::Main::get().getNetworking()->getWorldstate()->sendWeaponRecord(&newItem, ref->mBase->mId, quantity); /* End of tes3mp addition */ diff --git a/apps/openmw/mwmechanics/enchanting.cpp b/apps/openmw/mwmechanics/enchanting.cpp index 4350a4c3b..16d3e11f0 100644 --- a/apps/openmw/mwmechanics/enchanting.cpp +++ b/apps/openmw/mwmechanics/enchanting.cpp @@ -11,6 +11,7 @@ #include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" +#include "../mwmp/LocalPlayer.hpp" #include "../mwmp/Worldstate.hpp" /* End of tes3mp addition @@ -117,8 +118,11 @@ namespace MWMechanics Don't add the new item to the player's inventory and instead expect the server to add it + + Store the quantity used for the enchantment so it can be retrieved in applyEnchantment() + when applicable - The applyEnchantment() method is where the record of the newly enchanted will be sent + The applyEnchantment() method is where the record of the newly enchanted item will be sent to the server, causing the server to send back the player's inventory with the new item included */ @@ -129,6 +133,8 @@ namespace MWMechanics if(!mSelfEnchanting) payForEnchantment(); + mwmp::Main::get().getLocalPlayer()->storeLastEnchantmentQuantity(count); + std::string newItemId = mOldItemPtr.getClass().applyEnchantment(mOldItemPtr, enchantmentPtr->mId, getGemCharge(), mNewItemName); /* End of tes3mp change (major) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index d26d54191..6e47b42de 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1749,6 +1749,11 @@ void LocalPlayer::storeItemRemoval(const std::string& refId, int count) storedItemRemovals[refId] = storedItemRemovals[refId] + count; } +void LocalPlayer::storeLastEnchantmentQuantity(unsigned int quantity) +{ + lastEnchantmentQuantity = quantity; +} + void LocalPlayer::playAnimation() { MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(getPlayerPtr(), diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index ce500f680..5fe5097c1 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -23,6 +23,7 @@ namespace mwmp bool isReceivingQuickKeys; bool isPlayingAnimation; bool diedSinceArrestAttempt; + unsigned int lastEnchantmentQuantity; void update(); @@ -105,6 +106,7 @@ namespace mwmp void storeCellState(const ESM::Cell& cell, int stateType); void storeCurrentContainer(const MWWorld::Ptr& container); void storeItemRemoval(const std::string& refId, int count); + void storeLastEnchantmentQuantity(unsigned int quantity); void playAnimation(); void playSpeech(); diff --git a/apps/openmw/mwmp/Worldstate.cpp b/apps/openmw/mwmp/Worldstate.cpp index 0c5752edd..d974ca3e2 100644 --- a/apps/openmw/mwmp/Worldstate.cpp +++ b/apps/openmw/mwmp/Worldstate.cpp @@ -627,7 +627,7 @@ void Worldstate::sendClothingRecord(const ESM::Clothing* clothing, std::string b getNetworking()->getWorldstatePacket(ID_RECORD_DYNAMIC)->Send(); } -void Worldstate::sendWeaponRecord(const ESM::Weapon* weapon, std::string baseId) +void Worldstate::sendWeaponRecord(const ESM::Weapon* weapon, std::string baseId, unsigned int quantity) { weaponRecords.clear(); @@ -637,6 +637,7 @@ void Worldstate::sendWeaponRecord(const ESM::Weapon* weapon, std::string baseId) mwmp::WeaponRecord record; record.data = *weapon; + record.quantity = quantity; record.baseId = baseId; record.baseOverrides.hasName = true; record.baseOverrides.hasEnchantmentId = true; diff --git a/apps/openmw/mwmp/Worldstate.hpp b/apps/openmw/mwmp/Worldstate.hpp index 8551815be..c5cfaf1ee 100644 --- a/apps/openmw/mwmp/Worldstate.hpp +++ b/apps/openmw/mwmp/Worldstate.hpp @@ -35,7 +35,7 @@ namespace mwmp void sendArmorRecord(const ESM::Armor* armor, std::string baseRefId = ""); void sendBookRecord(const ESM::Book* book, std::string baseRefId = ""); void sendClothingRecord(const ESM::Clothing* clothing, std::string baseRefId = ""); - void sendWeaponRecord(const ESM::Weapon* weapon, std::string baseRefId = ""); + void sendWeaponRecord(const ESM::Weapon* weapon, std::string baseRefId = "", unsigned int quantity = 1); private: diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index 4c80339d5..6ffd7c3a7 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -309,6 +309,7 @@ namespace mwmp struct WeaponRecord { ESM::Weapon 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 99c3e548f..1a7db405c 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -368,6 +368,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);