[General] Read and use weapon quantity in RecordDynamic packets

pull/593/head
David Cernat 5 years ago
parent 001d63b59b
commit f8c557fbc0

@ -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;
}

@ -8,6 +8,7 @@
#include <components/openmw-mp/Utils.hpp>
#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
*/

@ -11,6 +11,7 @@
#include <components/openmw-mp/TimedLog.hpp>
#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)

@ -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(),

@ -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();

@ -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;

@ -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:

@ -309,6 +309,7 @@ namespace mwmp
struct WeaponRecord
{
ESM::Weapon data;
unsigned int quantity = 1;
std::string baseId;
BaseOverrides baseOverrides;
};

@ -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);

Loading…
Cancel
Save