diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 796ca098e..bdf426a71 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -77,11 +77,11 @@ set(SERVER Script/Functions/Actors.cpp Script/Functions/World.cpp Script/Functions/Miscellaneous.cpp - Script/Functions/Cells.cpp Script/Functions/CharClass.cpp Script/Functions/Chat.cpp - Script/Functions/Death.cpp Script/Functions/Dialogue.cpp Script/Functions/Factions.cpp - Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Positions.cpp - Script/Functions/Quests.cpp Script/Functions/Settings.cpp Script/Functions/Spells.cpp - Script/Functions/Stats.cpp Script/Functions/Timer.cpp + Script/Functions/Books.cpp Script/Functions/Cells.cpp Script/Functions/CharClass.cpp + Script/Functions/Chat.cpp Script/Functions/Death.cpp Script/Functions/Dialogue.cpp + Script/Functions/Factions.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp + Script/Functions/Positions.cpp Script/Functions/Quests.cpp Script/Functions/Settings.cpp + Script/Functions/Spells.cpp Script/Functions/Stats.cpp Script/Functions/Timer.cpp ProcessorInitializer.cpp PlayerProcessor.cpp ActorProcessor.cpp WorldProcessor.cpp diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index b1dc900ae..edbc223e5 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -77,6 +77,7 @@ public: mwmp::FactionChanges factionChangesBuffer; mwmp::TopicChanges topicChangesBuffer; mwmp::KillChanges killChangesBuffer; + mwmp::BookChanges bookChangesBuffer; private: CellController::TContainer cells; diff --git a/apps/openmw-mp/Script/Functions/Books.cpp b/apps/openmw-mp/Script/Functions/Books.cpp new file mode 100644 index 000000000..2d0f7adcc --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Books.cpp @@ -0,0 +1,48 @@ +#include "Books.hpp" +#include +#include +#include + +using namespace mwmp; + +unsigned int BookFunctions::GetBookChangesSize(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->bookChanges.count; +} + +void BookFunctions::AddBook(unsigned short pid, const char* bookId) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::Book book; + book.bookId = bookId; + + player->bookChangesBuffer.books.push_back(book); +} + +const char *BookFunctions::GetBookId(unsigned short pid, unsigned int i) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ""); + + if (i >= player->bookChanges.count) + return "invalid"; + + return player->bookChanges.books.at(i).bookId.c_str(); +} + +void BookFunctions::SendBookChanges(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + std::swap(player->bookChanges, player->bookChangesBuffer); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK)->Send(false); + player->bookChanges = std::move(player->bookChangesBuffer); + player->bookChangesBuffer.books.clear(); +} diff --git a/apps/openmw-mp/Script/Functions/Books.hpp b/apps/openmw-mp/Script/Functions/Books.hpp new file mode 100644 index 000000000..a12903af5 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Books.hpp @@ -0,0 +1,28 @@ +#ifndef OPENMW_BOOKAPI_HPP +#define OPENMW_BOOKAPI_HPP + +#define BOOKAPI \ + {"GetBookChangesSize", BookFunctions::GetBookChangesSize},\ + \ + {"AddBook", BookFunctions::AddBook},\ + \ + {"GetBookId", BookFunctions::GetBookId},\ + \ + {"SendBookChanges", BookFunctions::SendBookChanges} + +class BookFunctions +{ +public: + + static unsigned int GetBookChangesSize(unsigned short pid) noexcept; + + static void AddBook(unsigned short pid, const char* bookId) noexcept; + + static const char *GetBookId(unsigned short pid, unsigned int i) noexcept; + + static void SendBookChanges(unsigned short pid) noexcept; +private: + +}; + +#endif //OPENMW_BOOKAPI_HPP diff --git a/apps/openmw-mp/Script/Functions/Dialogue.cpp b/apps/openmw-mp/Script/Functions/Dialogue.cpp index cda37a025..e7a5c3a96 100644 --- a/apps/openmw-mp/Script/Functions/Dialogue.cpp +++ b/apps/openmw-mp/Script/Functions/Dialogue.cpp @@ -2,7 +2,6 @@ #include #include #include -#include using namespace mwmp; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 10d2da2cb..8330be59b 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -6,6 +6,7 @@ #define SCRIPTFUNCTIONS_HPP #include