diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index f63aea38b..e91a87ba6 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -237,22 +237,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) DEBUG_PRINTF("ID_GAME_SPELLBOOK\n"); myPacket->Read(player); - string str; - for (auto spell : player->packetSpells.spells) - { - str += spell.mId; - if (spell.mId != player->packetSpells.spells.back().mId) - str += ";"; - if (player->packetSpells.action == PacketSpells::ADD) - player->spellbook.push_back(spell); - else if (player->packetSpells.action == PacketSpells::REMOVE) - { - player->spellbook.erase(remove_if(player->spellbook.begin(), player->spellbook.end(), [&spell](ESM::Spell s)->bool - {return spell.mId == s.mId; }), player->spellbook.end()); - } - } - - Script::Call(player->getId(), player->packetSpells.action, str.c_str()); + Script::Call(player->getId(), player->packetSpells.action); break; } diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index cc8087fbf..bbef2dcac 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -70,7 +70,6 @@ public: public: mwmp::PacketItems packetItemsBuffer; mwmp::PacketSpells packetSpellsBuffer; - std::vector spellbook; private: bool handshakeState; diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index ec69bef36..046e5a1b8 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -153,6 +153,7 @@ void ItemFunctions::SendItems(unsigned short pid) noexcept { Player *player; GET_PLAYER(pid, player, ); + std::swap(player->packetItems, player->packetItemsBuffer); mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_INVENTORY)->Send(player, false); player->packetItems = std::move(player->packetItemsBuffer); diff --git a/apps/openmw-mp/Script/Functions/Spells.cpp b/apps/openmw-mp/Script/Functions/Spells.cpp index df68c66a4..caae16767 100644 --- a/apps/openmw-mp/Script/Functions/Spells.cpp +++ b/apps/openmw-mp/Script/Functions/Spells.cpp @@ -11,7 +11,7 @@ unsigned int SpellFunctions::GetSpellbookSize(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, 0); - return player->spellbook.size(); + return player->packetSpells.count; } void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept @@ -47,26 +47,15 @@ void SpellFunctions::ClearSpellbook(unsigned short pid) noexcept player->packetSpellsBuffer.action = PacketSpells::UPDATE; } -bool SpellFunctions::HasSpell(unsigned short pid, const char* spellId) -{ - Player *player; - GET_PLAYER(pid, player, false); - - for (unsigned int i = 0; i < player->spellbook.size(); i++) - if (Misc::StringUtils::ciEqual(player->spellbook.at(i).mId, spellId)) - return true; - return false; -} - const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept { Player *player; GET_PLAYER(pid, player, ""); - if (i >= player->spellbook.size()) + if (i >= player->packetSpells.count) return "invalid"; - return player->spellbook.at(i).mId.c_str(); + return player->packetSpells.spells.at(i).mId.c_str(); } void SpellFunctions::SendSpells(unsigned short pid) noexcept @@ -74,15 +63,6 @@ void SpellFunctions::SendSpells(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, ); - for (auto spell : player->packetSpellsBuffer.spells) - { - if (player->packetSpellsBuffer.action == PacketSpells::ADD) - player->spellbook.push_back(spell); - else if (player->packetSpells.action == PacketSpells::REMOVE) - player->spellbook.erase(remove_if(player->spellbook.begin(), player->spellbook.end(), [&spell](ESM::Spell s)->bool - {return spell.mId == s.mId; }), player->spellbook.end()); - } - std::swap(player->packetSpells, player->packetSpellsBuffer); mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_SPELLBOOK)->Send(player, false); player->packetSpells = std::move(player->packetSpellsBuffer); diff --git a/apps/openmw-mp/Script/Functions/Spells.hpp b/apps/openmw-mp/Script/Functions/Spells.hpp index 022074d1f..841bd31dd 100644 --- a/apps/openmw-mp/Script/Functions/Spells.hpp +++ b/apps/openmw-mp/Script/Functions/Spells.hpp @@ -8,7 +8,6 @@ {"RemoveSpell", SpellFunctions::RemoveSpell},\ {"ClearSpellbook", SpellFunctions::ClearSpellbook},\ \ - {"HasSpell", SpellFunctions::HasSpell},\ {"GetSpellId", SpellFunctions::GetSpellId},\ \ {"SendSpells", SpellFunctions::SendSpells} @@ -23,7 +22,6 @@ public: static void RemoveSpell(unsigned short pid, const char* spellId) noexcept; static void ClearSpellbook(unsigned short pid) noexcept; - static bool HasSpell(unsigned short pid, const char* itemName); static const char *GetSpellId(unsigned short pid, unsigned int i) noexcept; static void SendSpells(unsigned short pid) noexcept; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index f1cc5f407..3021d18b7 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -110,7 +110,7 @@ public: {"OnPlayerChangeLevel", Function()}, {"OnPlayerChangeEquipment", Function()}, {"OnPlayerChangeInventory", Function()}, - {"OnPlayerChangeSpellbook", Function()}, + {"OnPlayerChangeSpellbook", Function()}, {"OnPlayerSendMessage", Function()}, {"OnPlayerEndCharGen", Function()}, {"OnGUIAction", Function()}