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

36 lines
836 B
C++
Raw Normal View History

#include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerSpellbook.hpp"
using namespace std;
using namespace mwmp;
PacketPlayerSpellbook::PacketPlayerSpellbook(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
{
packetID = ID_PLAYER_SPELLBOOK;
}
void PacketPlayerSpellbook::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->spellbookChanges.action, send);
2017-11-28 13:37:46 +00:00
uint32_t changesCount;
if (send)
2017-11-28 13:37:46 +00:00
changesCount = static_cast<uint32_t>(player->spellbookChanges.spells.size());
2016-11-21 21:40:50 +00:00
2017-11-28 13:37:46 +00:00
RW(changesCount, send);
2017-11-29 11:00:22 +00:00
if (!send)
{
2017-11-28 13:37:46 +00:00
player->spellbookChanges.spells.clear();
player->spellbookChanges.spells.resize(changesCount);
}
2017-11-28 13:37:46 +00:00
for (auto &&spell : player->spellbookChanges.spells)
{
RW(spell.mId, send, true);
}
}