mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-03 18:15:33 +00:00
[General] Modernize packet style for PlayerInventory
This commit is contained in:
parent
cbe58b1c24
commit
b97322b4b1
3 changed files with 13 additions and 17 deletions
|
@ -27,7 +27,7 @@ unsigned int ItemFunctions::GetInventoryChangesSize(unsigned short pid) noexcept
|
|||
Player *player;
|
||||
GET_PLAYER(pid, player, 0);
|
||||
|
||||
return player->inventoryChanges.count;
|
||||
return player->inventoryChanges.items.size();
|
||||
}
|
||||
|
||||
unsigned int ItemFunctions::GetInventoryChangesAction(unsigned short pid) noexcept
|
||||
|
@ -133,7 +133,7 @@ const char *ItemFunctions::GetInventoryItemRefId(unsigned short pid, unsigned in
|
|||
Player *player;
|
||||
GET_PLAYER(pid, player, "");
|
||||
|
||||
if (index >= player->inventoryChanges.count)
|
||||
if (index >= player->inventoryChanges.items.size())
|
||||
return "invalid";
|
||||
|
||||
return player->inventoryChanges.items.at(index).refId.c_str();
|
||||
|
@ -168,7 +168,7 @@ const char *ItemFunctions::GetInventoryItemSoul(unsigned short pid, unsigned int
|
|||
Player *player;
|
||||
GET_PLAYER(pid, player, "");
|
||||
|
||||
if (index >= player->inventoryChanges.count)
|
||||
if (index >= player->inventoryChanges.items.size())
|
||||
return "invalid";
|
||||
|
||||
return player->inventoryChanges.items.at(index).soul.c_str();
|
||||
|
|
|
@ -105,7 +105,6 @@ namespace mwmp
|
|||
struct InventoryChanges
|
||||
{
|
||||
std::vector<Item> items;
|
||||
unsigned int count;
|
||||
enum ACTION_TYPE
|
||||
{
|
||||
SET = 0,
|
||||
|
@ -172,7 +171,6 @@ namespace mwmp
|
|||
BasePlayer(RakNet::RakNetGUID guid) : guid(guid)
|
||||
{
|
||||
inventoryChanges.action = 0;
|
||||
inventoryChanges.count = 0;
|
||||
spellbookChanges.action = 0;
|
||||
|
||||
exchangeFullInfo = false;
|
||||
|
|
|
@ -15,27 +15,25 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
|
|||
|
||||
RW(player->inventoryChanges.action, send);
|
||||
|
||||
uint32_t count;
|
||||
|
||||
if (send)
|
||||
player->inventoryChanges.count = (unsigned int) (player->inventoryChanges.items.size());
|
||||
else
|
||||
player->inventoryChanges.items.clear();
|
||||
count = static_cast<uint32_t>(player->inventoryChanges.items.size());
|
||||
|
||||
RW(player->inventoryChanges.count, send);
|
||||
RW(count, send);
|
||||
|
||||
for (unsigned int i = 0; i < player->inventoryChanges.count; i++)
|
||||
if (!send)
|
||||
{
|
||||
Item item;
|
||||
|
||||
if (send)
|
||||
item = player->inventoryChanges.items.at(i);
|
||||
player->inventoryChanges.items.clear();
|
||||
player->inventoryChanges.items.resize(count);
|
||||
}
|
||||
|
||||
for (auto &&item : player->inventoryChanges.items)
|
||||
{
|
||||
RW(item.refId, send, true);
|
||||
RW(item.count, send);
|
||||
RW(item.charge, send);
|
||||
RW(item.enchantmentCharge, send);
|
||||
RW(item.soul, send, true);
|
||||
|
||||
if (!send)
|
||||
player->inventoryChanges.items.push_back(item);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue