1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-22 09:23:52 +00:00
openmw-tes3mp/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp

71 lines
1.8 KiB
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)
{
2017-11-28 13:37:46 +00:00
RW(spell.mId, send, true);
2017-11-29 11:00:22 +00:00
if (spell.mId.find("$dynamic") != string::npos)
{
2017-11-28 13:37:46 +00:00
RW(spell.mName, send, true);
2017-11-28 13:37:46 +00:00
RW(spell.mData.mType, send, true);
RW(spell.mData.mCost, send, true);
RW(spell.mData.mFlags, send, true);
2017-11-28 13:37:46 +00:00
uint32_t effectCount;
if (send)
2017-11-28 13:37:46 +00:00
effectCount = static_cast<uint32_t>(spell.mEffects.mList.size());
2017-11-28 13:37:46 +00:00
RW(effectCount, send, true);
if (!send)
{
spell.mEffects.mList.resize(effectCount);
}
2017-11-28 13:37:46 +00:00
for (auto &&effect : spell.mEffects.mList)
{
2017-11-28 13:37:46 +00:00
RW(effect.mEffectID, send, true);
RW(effect.mSkill, send, true);
RW(effect.mAttribute, send, true);
RW(effect.mRange, send, true);
RW(effect.mArea, send, true);
RW(effect.mDuration, send, true);
RW(effect.mMagnMin, send, true);
RW(effect.mMagnMax, send, true);
}
}
}
}