1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-31 06:36:41 +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
apps/openmw-mp/Script/Functions
components/openmw-mp

View file

@ -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();

View file

@ -119,7 +119,6 @@ namespace mwmp
struct SpellbookChanges
{
std::vector<ESM::Spell> 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;

View file

@ -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<uint32_t>(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);
}
}