diff --git a/apps/openmw-mp/Script/Functions/Spells.cpp b/apps/openmw-mp/Script/Functions/Spells.cpp index b9f29f899..78f0e33c1 100644 --- a/apps/openmw-mp/Script/Functions/Spells.cpp +++ b/apps/openmw-mp/Script/Functions/Spells.cpp @@ -21,7 +21,7 @@ unsigned int SpellFunctions::GetSpellbookChangesSize(unsigned short pid) noexcep Player *player; GET_PLAYER(pid, player, 0); - return player->spellbookChanges.count; + return player->spellbookChanges.spells.size(); } 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; GET_PLAYER(pid, player, ""); - if (index >= player->spellbookChanges.count) + if (index >= player->spellbookChanges.spells.size()) return "invalid"; return player->spellbookChanges.spells.at(index).mId.c_str(); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 49ae5c98e..5fd30627e 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -119,7 +119,6 @@ namespace mwmp struct SpellbookChanges { std::vector spells; - unsigned int count; enum ACTION_TYPE { SET = 0, @@ -176,7 +175,6 @@ namespace mwmp inventoryChanges.action = 0; inventoryChanges.count = 0; spellbookChanges.action = 0; - spellbookChanges.count = 0; exchangeFullInfo = false; displayCreatureName = false; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp b/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp index 9f3224a04..67c30fda5 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerSpellbook.cpp @@ -15,24 +15,21 @@ void PacketPlayerSpellbook::Packet(RakNet::BitStream *bs, bool send) RW(player->spellbookChanges.action, send); + uint32_t count; + if (send) - player->spellbookChanges.count = (unsigned int) (player->spellbookChanges.spells.size()); - else - player->spellbookChanges.spells.clear(); + count = static_cast(player->spellbookChanges.spells.size()); - RW(player->spellbookChanges.count, send); + RW(count, send); - for (unsigned int i = 0; i < player->spellbookChanges.count; i++) + if (!send) { - ESM::Spell spell; - - if (send) - spell = player->spellbookChanges.spells.at(i); - - RW(spell.mId, send, true); - - if (!send) - player->spellbookChanges.spells.push_back(spell); + player->spellbookChanges.spells.clear(); + player->spellbookChanges.spells.resize(count); } + for (auto &&spell : player->spellbookChanges.spells) + { + RW(spell.mId, send, true); + } }