1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 04:19:55 +00:00
openmw-tes3mp/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp
Koncord 690211ad99 [General] Extract BaseEvent & BasePlayer from packets to functions
Move Send and Read functions to BasePacket
2017-03-06 18:40:07 +08:00

47 lines
1.1 KiB
C++

//
// 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);
RW(player->inventoryChanges.action, send);
if (!send)
player->inventoryChanges.items.clear();
else
player->inventoryChanges.count = (unsigned int) (player->inventoryChanges.items.size());
RW(player->inventoryChanges.count, send);
for (unsigned int i = 0; i < player->inventoryChanges.count; i++)
{
Item item;
if (send)
{
item = player->inventoryChanges.items.at(i);
}
RW(item.refId, send);
RW(item.count, send);
RW(item.charge, send);
if (!send)
{
player->inventoryChanges.items.push_back(item);
}
}
}