1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-10-15 07:56:44 +00:00

[General] Modernize packet style for PlayerSpellbook

This commit is contained in:
David Cernat 2019-10-24 19:27:37 +03:00
parent be0690b024
commit 904f804ea2
3 changed files with 13 additions and 18 deletions

View file

@ -21,7 +21,7 @@ unsigned int SpellFunctions::GetSpellbookChangesSize(unsigned short pid) noexcep
Player *player; Player *player;
GET_PLAYER(pid, player, 0); GET_PLAYER(pid, player, 0);
return player->spellbookChanges.count; return player->spellbookChanges.spells.size();
} }
unsigned int SpellFunctions::GetSpellbookChangesAction(unsigned short pid) noexcept unsigned int SpellFunctions::GetSpellbookChangesAction(unsigned short pid) noexcept
@ -56,7 +56,7 @@ const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int index) n
Player *player; Player *player;
GET_PLAYER(pid, player, ""); GET_PLAYER(pid, player, "");
if (index >= player->spellbookChanges.count) if (index >= player->spellbookChanges.spells.size())
return "invalid"; return "invalid";
return player->spellbookChanges.spells.at(index).mId.c_str(); return player->spellbookChanges.spells.at(index).mId.c_str();

View file

@ -119,7 +119,6 @@ namespace mwmp
struct SpellbookChanges struct SpellbookChanges
{ {
std::vector<ESM::Spell> spells; std::vector<ESM::Spell> spells;
unsigned int count;
enum ACTION_TYPE enum ACTION_TYPE
{ {
SET = 0, SET = 0,
@ -176,7 +175,6 @@ namespace mwmp
inventoryChanges.action = 0; inventoryChanges.action = 0;
inventoryChanges.count = 0; inventoryChanges.count = 0;
spellbookChanges.action = 0; spellbookChanges.action = 0;
spellbookChanges.count = 0;
exchangeFullInfo = false; exchangeFullInfo = false;
displayCreatureName = false; displayCreatureName = false;

View file

@ -15,24 +15,21 @@ void PacketPlayerSpellbook::Packet(RakNet::BitStream *bs, bool send)
RW(player->spellbookChanges.action, send); RW(player->spellbookChanges.action, send);
uint32_t count;
if (send) if (send)
player->spellbookChanges.count = (unsigned int) (player->spellbookChanges.spells.size()); count = static_cast<uint32_t>(player->spellbookChanges.spells.size());
else
player->spellbookChanges.spells.clear();
RW(player->spellbookChanges.count, send); RW(count, send);
for (unsigned int i = 0; i < player->spellbookChanges.count; i++) if (!send)
{ {
ESM::Spell spell; player->spellbookChanges.spells.clear();
player->spellbookChanges.spells.resize(count);
if (send)
spell = player->spellbookChanges.spells.at(i);
RW(spell.mId, send, true);
if (!send)
player->spellbookChanges.spells.push_back(spell);
} }
for (auto &&spell : player->spellbookChanges.spells)
{
RW(spell.mId, send, true);
}
} }