mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-21 05:44:06 +00:00
[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.
This commit is contained in:
parent
678a308269
commit
e78503d5f3
8 changed files with 61 additions and 6 deletions
|
@ -295,6 +295,16 @@ double RecordsDynamicFunctions::GetRecordWeight(unsigned int index) noexcept
|
||||||
return -1;
|
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
|
unsigned int RecordsDynamicFunctions::GetRecordEffectId(unsigned int recordIndex, unsigned int effectIndex) noexcept
|
||||||
{
|
{
|
||||||
return GetRecordEffects(recordIndex).mList.at(effectIndex).mEffectID;
|
return GetRecordEffects(recordIndex).mList.at(effectIndex).mEffectID;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
{"GetRecordFlags", RecordsDynamicFunctions::GetRecordFlags},\
|
{"GetRecordFlags", RecordsDynamicFunctions::GetRecordFlags},\
|
||||||
{"GetRecordValue", RecordsDynamicFunctions::GetRecordValue},\
|
{"GetRecordValue", RecordsDynamicFunctions::GetRecordValue},\
|
||||||
{"GetRecordWeight", RecordsDynamicFunctions::GetRecordWeight},\
|
{"GetRecordWeight", RecordsDynamicFunctions::GetRecordWeight},\
|
||||||
|
{"GetRecordQuantity", RecordsDynamicFunctions::GetRecordQuantity},\
|
||||||
\
|
\
|
||||||
{"GetRecordEffectId", RecordsDynamicFunctions::GetRecordEffectId},\
|
{"GetRecordEffectId", RecordsDynamicFunctions::GetRecordEffectId},\
|
||||||
{"GetRecordEffectAttribute", RecordsDynamicFunctions::GetRecordEffectAttribute},\
|
{"GetRecordEffectAttribute", RecordsDynamicFunctions::GetRecordEffectAttribute},\
|
||||||
|
@ -300,6 +301,15 @@ public:
|
||||||
*/
|
*/
|
||||||
static double GetRecordWeight(unsigned int index) noexcept;
|
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
|
* \brief Get the ID of the effect at a certain index in the read worldstate's
|
||||||
* current records.
|
* current records.
|
||||||
|
|
|
@ -317,8 +317,8 @@ void MWMechanics::Alchemy::addPotion (const std::string& name)
|
||||||
Start of tes3mp change (major)
|
Start of tes3mp change (major)
|
||||||
|
|
||||||
Don't create a record and don't add the potion to the player's inventory;
|
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
|
instead just store its record in preparation for sending it to the server
|
||||||
to the player's inventory
|
and expect the server to add it to the player's inventory
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
const ESM::Potion* record = getRecord(newRecord);
|
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);
|
mAlchemist.getClass().getContainerStore (mAlchemist).add (record->mId, 1, mAlchemist);
|
||||||
*/
|
*/
|
||||||
|
mStoredPotion = newRecord;
|
||||||
mwmp::Main::get().getNetworking()->getWorldstate()->sendPotionRecord(&newRecord);
|
|
||||||
/*
|
/*
|
||||||
End of tes3mp change (major)
|
End of tes3mp change (major)
|
||||||
*/
|
*/
|
||||||
|
@ -546,6 +545,18 @@ MWMechanics::Alchemy::Result MWMechanics::Alchemy::create (const std::string& na
|
||||||
}
|
}
|
||||||
|
|
||||||
count = brewedCount;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,16 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#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 <components/esm/effectlist.hpp>
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
@ -53,6 +63,17 @@ namespace MWMechanics
|
||||||
int mValue;
|
int mValue;
|
||||||
std::string mPotionName;
|
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 applyTools (int flags, float& value) const;
|
||||||
|
|
||||||
void updateEffects();
|
void updateEffects();
|
||||||
|
|
|
@ -522,7 +522,7 @@ void Worldstate::sendEnchantmentRecord(const ESM::Enchantment* enchantment)
|
||||||
getNetworking()->getWorldstatePacket(ID_RECORD_DYNAMIC)->Send();
|
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();
|
potionRecords.clear();
|
||||||
|
|
||||||
|
@ -532,6 +532,7 @@ void Worldstate::sendPotionRecord(const ESM::Potion* potion)
|
||||||
|
|
||||||
mwmp::PotionRecord record;
|
mwmp::PotionRecord record;
|
||||||
record.data = *potion;
|
record.data = *potion;
|
||||||
|
record.quantity = quantity;
|
||||||
potionRecords.push_back(record);
|
potionRecords.push_back(record);
|
||||||
|
|
||||||
getNetworking()->getWorldstatePacket(ID_RECORD_DYNAMIC)->setWorldstate(this);
|
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 sendWeather(std::string region, int currentWeather, int nextWeather, int queuedWeather, float transitionFactor);
|
||||||
|
|
||||||
void sendEnchantmentRecord(const ESM::Enchantment* enchantment);
|
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 sendSpellRecord(const ESM::Spell* spell);
|
||||||
|
|
||||||
void sendArmorRecord(const ESM::Armor* armor, std::string baseRefId = "");
|
void sendArmorRecord(const ESM::Armor* armor, std::string baseRefId = "");
|
||||||
|
|
|
@ -260,6 +260,7 @@ namespace mwmp
|
||||||
struct PotionRecord
|
struct PotionRecord
|
||||||
{
|
{
|
||||||
ESM::Potion data;
|
ESM::Potion data;
|
||||||
|
unsigned int quantity = 1;
|
||||||
std::string baseId;
|
std::string baseId;
|
||||||
BaseOverrides baseOverrides;
|
BaseOverrides baseOverrides;
|
||||||
};
|
};
|
||||||
|
|
|
@ -167,6 +167,7 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *newBitstream, bool send)
|
||||||
{
|
{
|
||||||
auto &recordData = record.data;
|
auto &recordData = record.data;
|
||||||
|
|
||||||
|
RW(record.quantity, send);
|
||||||
RW(record.baseId, send, true);
|
RW(record.baseId, send, true);
|
||||||
RW(recordData.mId, send, true);
|
RW(recordData.mId, send, true);
|
||||||
RW(recordData.mName, send, true);
|
RW(recordData.mName, send, true);
|
||||||
|
|
Loading…
Reference in a new issue