[General] Include potion quantity in RecordDynamic packets

Don't spam the server with one RecordDynamic packet per potion created when brewing multiple potions at once. Instead, send a single RecordDynamic packet with the potion quantity included in it.

Add serverside script functions for getting the potion quantity.
pull/558/head
David Cernat 5 years ago
parent 678a308269
commit e78503d5f3

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

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

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

@ -4,6 +4,16 @@
#include <vector>
#include <set>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include <components/esm/loadalch.hpp>
/*
End of tes3mp addition
*/
#include <components/esm/effectlist.hpp>
#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();

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

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

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

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

Loading…
Cancel
Save