diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 850c3e5ad..805d7beff 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -236,6 +236,8 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) DEBUG_PRINTF("ID_GAME_SPELLBOOK\n"); myPacket->Read(player); + Script::Call(player->getId()); + break; } diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 0077052b0..1354b04d5 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -108,6 +108,7 @@ public: {"OnPlayerChangeLevel", Function()}, {"OnPlayerChangeEquipment", Function()}, {"OnPlayerChangeInventory", Function()}, + {"OnPlayerChangeSpellbook", Function()}, {"OnPlayerSendMessage", Function()}, {"OnPlayerEndCharGen", Function()}, {"OnGUIAction", Function()} diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index da242d083..49179edd5 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -845,6 +845,30 @@ void LocalPlayer::sendInventory() Main::get().getNetworking()->getPlayerPacket(ID_GAME_INVENTORY)->Send(this); } +void LocalPlayer::sendSpellAddition(std::string id) +{ + spellbook.spells.clear(); + + mwmp::Spell spell; + spell.id = id; + spellbook.spells.push_back(spell); + + spellbook.action = Spellbook::ADD; + Main::get().getNetworking()->getPlayerPacket(ID_GAME_SPELLBOOK)->Send(this); +} + +void LocalPlayer::sendSpellRemoval(std::string id) +{ + spellbook.spells.clear(); + + mwmp::Spell spell; + spell.id = id; + spellbook.spells.push_back(spell); + + spellbook.action = Spellbook::REMOVE; + Main::get().getNetworking()->getPlayerPacket(ID_GAME_SPELLBOOK)->Send(this); +} + void LocalPlayer::sendAttack(Attack::TYPE type) { MWMechanics::DrawState_ state = getPlayerPtr().getClass().getNpcStats(getPlayerPtr()).getDrawState(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 54eeb0a94..987b0f1b6 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -47,6 +47,8 @@ namespace mwmp void sendClass(); void sendInventory(); + void sendSpellAddition(std::string id); + void sendSpellRemoval(std::string id); void sendAttack(Attack::TYPE type); void prepareAttack(Attack::TYPE type, bool state); diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index d5b64b7d7..5df5fc929 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -3,6 +3,8 @@ #include #include +#include "../mwmp/Main.hpp" + #include #include "../mwworld/esmstore.hpp" @@ -442,6 +444,11 @@ namespace MWScript MWBase::Environment::get().getWorld()->getStore().get().find (id); ptr.getClass().getCreatureStats (ptr).getSpells().add (id); + + // Added by tes3mp + // + // LocalPlayer has gained a spell, so send a packet with it + mwmp::Main::get().getLocalPlayer()->sendSpellAddition(id); } }; @@ -466,6 +473,11 @@ namespace MWScript { wm->unsetSelectedSpell(); } + + // Added by tes3mp + // + // LocalPlayer has lost a spell, so send a packet with it + mwmp::Main::get().getLocalPlayer()->sendSpellRemoval(id); } }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 538cd68cb..311dd22eb 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -58,6 +58,24 @@ namespace mwmp int action; //0 - FullUpdate, 1 - AddItem, 2 - RemoveItem }; + struct Spell + { + std::string id; + }; + + struct Spellbook + { + std::vector spells; + unsigned int count; + enum ACTION_TYPE + { + UPDATE = 0, + ADD, + REMOVE + }; + int action; //0 - Update, 1 - Add, 2 - Remove + }; + class BasePlayer { public: @@ -89,6 +107,7 @@ namespace mwmp { inventory.action = 0; inventory.count = 0; + spellbook.action = 0; } BasePlayer() @@ -174,6 +193,7 @@ namespace mwmp int day; double hour; Inventory inventory; + Spellbook spellbook; bool consoleAllowed; bool ignorePosPacket; diff --git a/components/openmw-mp/Packets/Player/PacketInventory.cpp b/components/openmw-mp/Packets/Player/PacketInventory.cpp index 867e8e135..97bcbb865 100644 --- a/components/openmw-mp/Packets/Player/PacketInventory.cpp +++ b/components/openmw-mp/Packets/Player/PacketInventory.cpp @@ -18,14 +18,18 @@ void PacketInventory::Packet(RakNet::BitStream *bs, BasePlayer *player, bool sen PlayerPacket::Packet(bs, player, send); RW(player->inventory.action, send); + if (!send) player->inventory.items.clear(); else player->inventory.count = (unsigned int) (player->inventory.items.size()); + RW(player->inventory.count, send); + for (int i = 0; i < player->inventory.count; i++) { Item item; + if (send) { item = player->inventory.items[i]; diff --git a/components/openmw-mp/Packets/Player/PacketSpellbook.cpp b/components/openmw-mp/Packets/Player/PacketSpellbook.cpp index 54589553f..b725c253e 100644 --- a/components/openmw-mp/Packets/Player/PacketSpellbook.cpp +++ b/components/openmw-mp/Packets/Player/PacketSpellbook.cpp @@ -12,4 +12,30 @@ PacketSpellbook::PacketSpellbook(RakNet::RakPeerInterface *peer) : PlayerPacket( void PacketSpellbook::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) { PlayerPacket::Packet(bs, player, send); + + RW(player->spellbook.action, send); + + if (!send) + player->spellbook.spells.clear(); + else + player->spellbook.count = (unsigned int) (player->spellbook.spells.size()); + + RW(player->spellbook.count, send); + + for (int i = 0; i < player->spellbook.count; i++) + { + Spell spell; + + if (send) + { + spell = player->spellbook.spells[i]; + RW(spell.id, send); + } + else + { + RW(spell.id, send); + player->spellbook.spells.push_back(spell); + } + } + }