From 83277a1512e38b9e4a474571fb626296814efbfb Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 20 Jan 2017 09:07:07 +0200 Subject: [PATCH] Send spellbook in LocalPlayer CharGen & change UPDATE action name to SET --- apps/openmw-mp/Script/Functions/Items.cpp | 2 +- apps/openmw-mp/Script/Functions/Spells.cpp | 2 +- .../mwmechanics/mechanicsmanagerimp.cpp | 10 ----- apps/openmw/mwmp/LocalPlayer.cpp | 37 +++++++++++++++---- apps/openmw/mwmp/LocalPlayer.hpp | 1 + apps/openmw/mwmp/Networking.cpp | 4 +- components/openmw-mp/Base/BasePlayer.hpp | 8 ++-- 7 files changed, 39 insertions(+), 25 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 046e5a1b8..f6377ea4a 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -75,7 +75,7 @@ void ItemFunctions::ClearInventory(unsigned short pid) noexcept GET_PLAYER(pid, player, ); player->packetItemsBuffer.items.clear(); - player->packetItemsBuffer.action = PacketItems::UPDATE; + player->packetItemsBuffer.action = PacketItems::SET; } bool ItemFunctions::HasItemEquipped(unsigned short pid, const char* itemId) diff --git a/apps/openmw-mp/Script/Functions/Spells.cpp b/apps/openmw-mp/Script/Functions/Spells.cpp index caae16767..8515efc1b 100644 --- a/apps/openmw-mp/Script/Functions/Spells.cpp +++ b/apps/openmw-mp/Script/Functions/Spells.cpp @@ -44,7 +44,7 @@ void SpellFunctions::ClearSpellbook(unsigned short pid) noexcept GET_PLAYER(pid, player, ); player->packetSpellsBuffer.spells.clear(); - player->packetSpellsBuffer.action = PacketSpells::UPDATE; + player->packetSpellsBuffer.action = PacketSpells::SET; } const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 9575d5a48..3d1485fb2 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -27,9 +27,6 @@ #include "actorutil.hpp" #include "combat.hpp" -#include "../mwmp/Main.hpp" -#include "../mwmp/LocalPlayer.hpp" - namespace { @@ -216,15 +213,8 @@ namespace MWMechanics std::vector selectedSpells = autoCalcPlayerSpells(skills, attributes, race); for (std::vector::iterator it = selectedSpells.begin(); it != selectedSpells.end(); ++it) - { creatureStats.getSpells().add(*it); - // Added by tes3mp - // - // LocalPlayer has gained a spell, so send a packet with it - mwmp::Main::get().getLocalPlayer()->sendSpellAddition(*it); - } - // forced update and current value adjustments mActors.updateActor (ptr, 0); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index c81e3b8c6..2dc379417 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -133,6 +133,7 @@ bool LocalPlayer::charGenThread() updateSkills(true); updateLevel(true); sendClass(); + sendSpellbook(); getNetworking()->getPlayerPacket(ID_GAME_CHARGEN)->Send(this); } @@ -620,7 +621,7 @@ void LocalPlayer::updateDrawStateAndFlags(bool forceUpdate) void LocalPlayer::addItems() { - MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); for (unsigned int i = 0; i < packetItems.count; i++) @@ -634,7 +635,7 @@ void LocalPlayer::addItems() void LocalPlayer::addSpells() { - MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells(); for (vector::const_iterator spell = packetSpells.spells.begin(); spell != packetSpells.spells.end(); spell++) @@ -644,7 +645,7 @@ void LocalPlayer::addSpells() void LocalPlayer::removeItems() { - MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); for (unsigned int i = 0; i < packetItems.count; i++) @@ -656,7 +657,7 @@ void LocalPlayer::removeItems() void LocalPlayer::removeSpells() { - MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells(); for (vector::const_iterator spell = packetSpells.spells.begin(); spell != packetSpells.spells.end(); spell++) @@ -855,7 +856,7 @@ void LocalPlayer::setEquipment() void LocalPlayer::setInventory() { - MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); // Clear items in inventory @@ -873,7 +874,7 @@ void LocalPlayer::setInventory() void LocalPlayer::setSpellbook() { - MWWorld::Ptr ptrPlayer = MWBase::Environment::get().getWorld()->getPlayerPtr(); + MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells(); // Clear spells in spellbook, while ignoring abilities, powers, etc. @@ -931,10 +932,32 @@ void LocalPlayer::sendInventory() } packetItems.count = (unsigned int) packetItems.items.size(); - packetItems.action = PacketItems::UPDATE; + packetItems.action = PacketItems::SET; Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->Send(this); } +void LocalPlayer::sendSpellbook() +{ + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + MWMechanics::Spells &ptrSpells = ptrPlayer.getClass().getCreatureStats(ptrPlayer).getSpells(); + + packetSpells.spells.clear(); + + // Send spells in spellbook, while ignoring abilities, powers, etc. + for (MWMechanics::Spells::TIterator iter = ptrSpells.begin(); iter != ptrSpells.end(); ++iter) + { + const ESM::Spell *spell = iter->first; + + if (spell->mData.mType == ESM::Spell::ST_Spell) + { + packetSpells.spells.push_back(*spell); + } + } + + packetSpells.action = PacketSpells::SET; + Main::get().getNetworking()->getPlayerPacket(ID_GAME_SPELLBOOK)->Send(this); +} + void LocalPlayer::sendSpellAddition(std::string id) { if (id.find("$dynamic") != string::npos) // skip custom spells diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 7668f679a..155d37819 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -55,6 +55,7 @@ namespace mwmp void sendClass(); void sendInventory(); + void sendSpellbook(); void sendSpellAddition(std::string id); void sendSpellAddition(const ESM::Spell &spell); void sendSpellRemoval(std::string id); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 876b01bc8..4f2bb1085 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -309,7 +309,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) { getLocalPlayer()->removeItems(); } - else // PacketItems::UPDATE + else // PacketItems::SET { getLocalPlayer()->setInventory(); } @@ -338,7 +338,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) { getLocalPlayer()->removeSpells(); } - else // PacketSpells::UPDATE + else // PacketSpells::SET { getLocalPlayer()->setSpellbook(); } diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 4ce052b7b..04abac476 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -52,11 +52,11 @@ namespace mwmp unsigned int count; enum ACTION_TYPE { - UPDATE = 0, + SET = 0, ADD, REMOVE }; - int action; //0 - Full update, 1 - Add item, 2 - Remove item + int action; //0 - Clear and set in entirety, 1 - Add item, 2 - Remove item }; struct PacketSpells @@ -65,11 +65,11 @@ namespace mwmp unsigned int count; enum ACTION_TYPE { - UPDATE = 0, + SET = 0, ADD, REMOVE }; - int action; //0 - Full update, 1 - Add spell, 2 - Remove spell + int action; //0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell }; class BasePlayer