2016-12-03 15:38:14 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 03.12.16.
|
|
|
|
//
|
|
|
|
|
2017-02-05 07:01:33 +00:00
|
|
|
#include "PacketPlayerActiveSkills.hpp"
|
2016-12-03 15:38:14 +00:00
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
2017-02-05 07:01:33 +00:00
|
|
|
PacketPlayerActiveSkills::PacketPlayerActiveSkills(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)
|
2016-12-03 15:38:14 +00:00
|
|
|
{
|
2017-02-05 07:01:33 +00:00
|
|
|
packetID = ID_PLAYER_ACTIVESKILLS;
|
2016-12-03 15:38:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 09:44:08 +00:00
|
|
|
void PacketPlayerActiveSkills::Packet(RakNet::BitStream *bs, bool send)
|
2016-12-03 15:38:14 +00:00
|
|
|
{
|
2017-03-06 09:44:08 +00:00
|
|
|
PlayerPacket::Packet(bs, send);
|
2016-12-03 15:38:14 +00:00
|
|
|
|
2017-11-28 13:37:46 +00:00
|
|
|
uint32_t spellCount = 0;
|
2016-12-03 15:38:14 +00:00
|
|
|
|
|
|
|
if (send)
|
2017-11-28 13:37:46 +00:00
|
|
|
spellCount = static_cast<uint32_t>(player->activeSpells.mSpells.size());
|
2016-12-03 15:38:14 +00:00
|
|
|
|
2017-11-28 13:37:46 +00:00
|
|
|
RW(spellCount, send);
|
2016-12-03 15:38:14 +00:00
|
|
|
|
2017-11-28 13:37:46 +00:00
|
|
|
auto fnRWSpell = [this, &send](ESM::ActiveSpells::TContainer::value_type &spell) {
|
|
|
|
RW(spell.first, send);
|
|
|
|
RW(spell.second.mTimeStamp, send);
|
|
|
|
uint32_t effectsCount;
|
|
|
|
|
2017-11-29 11:00:22 +00:00
|
|
|
if (send)
|
2017-11-28 13:37:46 +00:00
|
|
|
effectsCount = static_cast<uint32_t>(spell.second.mEffects.size());
|
|
|
|
|
|
|
|
RW(effectsCount, send);
|
2016-12-03 15:38:14 +00:00
|
|
|
|
2017-11-29 11:00:22 +00:00
|
|
|
if (!send)
|
2017-11-28 13:37:46 +00:00
|
|
|
spell.second.mEffects.resize(effectsCount);
|
2016-12-03 15:38:14 +00:00
|
|
|
|
2017-11-28 13:37:46 +00:00
|
|
|
for (auto &&effect : spell.second.mEffects)
|
|
|
|
RW(effect, send);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (send)
|
|
|
|
for (auto && spell : player->activeSpells.mSpells)
|
|
|
|
{
|
|
|
|
fnRWSpell(spell);
|
2016-12-03 15:38:14 +00:00
|
|
|
}
|
|
|
|
else
|
2017-11-28 13:37:46 +00:00
|
|
|
for (unsigned int i = 0; i < spellCount; i++)
|
2016-12-03 15:38:14 +00:00
|
|
|
{
|
|
|
|
ESM::ActiveSpells::TContainer::value_type spell;
|
2017-11-28 13:37:46 +00:00
|
|
|
fnRWSpell(spell);
|
2016-12-03 15:38:14 +00:00
|
|
|
player->activeSpells.mSpells.insert(spell);
|
|
|
|
}
|
2017-01-26 04:17:29 +00:00
|
|
|
}
|