From 35e453dec3a9044bb2087c97a051453eb84f9f8e Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 24 Jan 2017 19:32:25 +0200 Subject: [PATCH] [General] Sketch out most of functionality for journal saving/loading --- apps/openmw-mp/CMakeLists.txt | 5 +- apps/openmw-mp/Player.hpp | 1 + apps/openmw-mp/Script/Functions/Quests.cpp | 79 +++++++++++++++++++ apps/openmw-mp/Script/Functions/Quests.hpp | 33 ++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 2 + apps/openmw/mwmp/LocalPlayer.cpp | 56 ++++++++++++- apps/openmw/mwmp/LocalPlayer.hpp | 1 + apps/openmw/mwmp/Networking.cpp | 12 +++ components/openmw-mp/Base/BasePlayer.hpp | 5 ++ .../Packets/Player/PacketJournal.cpp | 32 ++++++++ 10 files changed, 222 insertions(+), 4 deletions(-) create mode 100644 apps/openmw-mp/Script/Functions/Quests.cpp create mode 100644 apps/openmw-mp/Script/Functions/Quests.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 9dace0cba..12bab0186 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -73,8 +73,9 @@ set(SERVER Script/ScriptFunctions.cpp Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp - Script/Functions/Items.cpp Script/Functions/Stats.cpp Script/Functions/Spells.cpp - Script/Functions/Timer.cpp Script/Functions/Translocations.cpp Script/Functions/World.cpp + Script/Functions/Items.cpp Script/Functions/Quests.cpp Script/Functions/Stats.cpp + Script/Functions/Spells.cpp Script/Functions/Timer.cpp Script/Functions/Translocations.cpp + Script/Functions/World.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index 6d30f1b2e..3fdc0b2e3 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -70,6 +70,7 @@ public: public: mwmp::InventoryChanges inventoryChangesBuffer; mwmp::SpellbookChanges spellbookChangesBuffer; + mwmp::JournalChanges journalChangesBuffer; private: bool handshakeState; diff --git a/apps/openmw-mp/Script/Functions/Quests.cpp b/apps/openmw-mp/Script/Functions/Quests.cpp new file mode 100644 index 000000000..18e829b12 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Quests.cpp @@ -0,0 +1,79 @@ +#include "Quests.hpp" +#include +#include +#include +#include + +using namespace mwmp; + +unsigned int QuestFunctions::GetJournalChangesSize(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->journalChanges.count; +} + +void QuestFunctions::AddJournalEntry(unsigned short pid, const char* quest, unsigned int index) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::JournalItem journalItem; + journalItem.type = JournalItem::ENTRY; + journalItem.quest = quest; + journalItem.index = index; + + player->journalChangesBuffer.journalItems.push_back(journalItem); +} + +void QuestFunctions::AddJournalIndex(unsigned short pid, const char* quest, unsigned int index) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::JournalItem journalItem; + journalItem.type = JournalItem::INDEX; + journalItem.quest = quest; + journalItem.index = index; + + player->journalChangesBuffer.journalItems.push_back(journalItem); +} + +const char *QuestFunctions::GetJournalItemQuest(unsigned short pid, unsigned int i) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ""); + + if (i >= player->journalChanges.count) + return "invalid"; + + return player->journalChanges.journalItems.at(i).quest.c_str(); +} + +int QuestFunctions::GetJournalItemIndex(unsigned short pid, unsigned int i) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->journalChanges.journalItems.at(i).index; +} + +int QuestFunctions::GetJournalItemType(unsigned short pid, unsigned int i) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->journalChanges.journalItems.at(i).type; +} + +void QuestFunctions::SendJournalChanges(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + std::swap(player->journalChanges, player->journalChangesBuffer); + mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_JOURNAL)->Send(player, false); + player->journalChanges = std::move(player->journalChangesBuffer); + player->journalChangesBuffer.journalItems.clear(); +} diff --git a/apps/openmw-mp/Script/Functions/Quests.hpp b/apps/openmw-mp/Script/Functions/Quests.hpp new file mode 100644 index 000000000..656bfb83d --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Quests.hpp @@ -0,0 +1,33 @@ +#ifndef OPENMW_QUESTS_HPP +#define OPENMW_QUESTS_HPP + +#define QUESTAPI \ + {"GetJournalChangesSize", QuestFunctions::GetJournalChangesSize},\ + \ + {"AddJournalIndex", QuestFunctions::AddJournalIndex},\ + \ + {"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\ + {"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\ + {"GetJournalItemType", QuestFunctions::GetJournalItemType},\ + \ + {"SendJournalChanges", QuestFunctions::SendJournalChanges} + +class QuestFunctions +{ +public: + + static unsigned int GetJournalChangesSize(unsigned short pid) noexcept; + + static void AddJournalEntry(unsigned short pid, const char* quest, unsigned int index) noexcept; + static void AddJournalIndex(unsigned short pid, const char* quest, unsigned int index) noexcept; + + static const char *GetJournalItemQuest(unsigned short pid, unsigned int i) noexcept; + static int GetJournalItemIndex(unsigned short pid, unsigned int i) noexcept; + static int GetJournalItemType(unsigned short pid, unsigned int i) noexcept; + + static void SendJournalChanges(unsigned short pid) noexcept; +private: + +}; + +#endif //OPENMW_QUESTS_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index c3428e7f4..17a26d24c 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -10,6 +10,7 @@ #include