openmw-tes3coop/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp

42 lines
984 B
C++
Raw Normal View History

//
// Created by koncord on 22.10.16.
//
#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerInventory.hpp"
using namespace std;
using namespace mwmp;
PacketPlayerInventory::PacketPlayerInventory(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
{
packetID = ID_PLAYER_INVENTORY;
}
void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
2017-11-28 13:37:46 +00:00
uint32_t count;
if (send)
2017-11-28 13:37:46 +00:00
count = static_cast<uint32_t>(player->inventoryChanges.items.size());
2016-11-21 21:40:50 +00:00
2017-11-28 13:37:46 +00:00
RW(count, send);
2016-11-21 21:40:50 +00:00
2017-11-29 11:00:22 +00:00
if (!send)
{
2017-11-28 13:37:46 +00:00
player->inventoryChanges.items.clear();
player->inventoryChanges.items.resize(count);
}
2017-11-28 13:37:46 +00:00
for (auto &&item : player->inventoryChanges.items)
{
RW(item.first.refId, send, true);
RW(item.first.count, send);
RW(item.first.charge, send);
RW(item.first.enchantmentCharge, send);
RW(item.second, send, true); // compress byte to bits
}
}