mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
[General] Sketch out most of functionality for journal saving/loading
This commit is contained in:
parent
c3c3c57a98
commit
35e453dec3
10 changed files with 222 additions and 4 deletions
|
@ -73,8 +73,9 @@ set(SERVER
|
||||||
Script/ScriptFunctions.cpp
|
Script/ScriptFunctions.cpp
|
||||||
|
|
||||||
Script/Functions/CharClass.cpp Script/Functions/Chat.cpp Script/Functions/GUI.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/Items.cpp Script/Functions/Quests.cpp Script/Functions/Stats.cpp
|
||||||
Script/Functions/Timer.cpp Script/Functions/Translocations.cpp Script/Functions/World.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
|
Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp
|
||||||
${PawnScript_Sources}
|
${PawnScript_Sources}
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
public:
|
public:
|
||||||
mwmp::InventoryChanges inventoryChangesBuffer;
|
mwmp::InventoryChanges inventoryChangesBuffer;
|
||||||
mwmp::SpellbookChanges spellbookChangesBuffer;
|
mwmp::SpellbookChanges spellbookChangesBuffer;
|
||||||
|
mwmp::JournalChanges journalChangesBuffer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool handshakeState;
|
bool handshakeState;
|
||||||
|
|
79
apps/openmw-mp/Script/Functions/Quests.cpp
Normal file
79
apps/openmw-mp/Script/Functions/Quests.cpp
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#include "Quests.hpp"
|
||||||
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
||||||
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
|
#include <apps/openmw-mp/Networking.hpp>
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
33
apps/openmw-mp/Script/Functions/Quests.hpp
Normal file
33
apps/openmw-mp/Script/Functions/Quests.hpp
Normal file
|
@ -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
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Script/Functions/GUI.hpp>
|
#include <Script/Functions/GUI.hpp>
|
||||||
#include <Script/Functions/Stats.hpp>
|
#include <Script/Functions/Stats.hpp>
|
||||||
#include <Script/Functions/Items.hpp>
|
#include <Script/Functions/Items.hpp>
|
||||||
|
#include <Script/Functions/Quests.hpp>
|
||||||
#include <Script/Functions/Spells.hpp>
|
#include <Script/Functions/Spells.hpp>
|
||||||
#include <Script/Functions/World.hpp>
|
#include <Script/Functions/World.hpp>
|
||||||
#include <RakNetTypes.h>
|
#include <RakNetTypes.h>
|
||||||
|
@ -90,6 +91,7 @@ public:
|
||||||
TRANSLOCATIONFUNCTIONS,
|
TRANSLOCATIONFUNCTIONS,
|
||||||
STATSFUNCTIONS,
|
STATSFUNCTIONS,
|
||||||
ITEMAPI,
|
ITEMAPI,
|
||||||
|
QUESTAPI,
|
||||||
SPELLAPI,
|
SPELLAPI,
|
||||||
GUIFUNCTIONS,
|
GUIFUNCTIONS,
|
||||||
CHARCLASSFUNCTIONS,
|
CHARCLASSFUNCTIONS,
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../mwmechanics/aitravel.hpp"
|
#include "../mwmechanics/aitravel.hpp"
|
||||||
#include <components/esm/esmwriter.hpp>
|
#include <components/esm/esmwriter.hpp>
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/journal.hpp"
|
||||||
#include "../mwstate/statemanagerimp.hpp"
|
#include "../mwstate/statemanagerimp.hpp"
|
||||||
#include "../mwinput/inputmanagerimp.hpp"
|
#include "../mwinput/inputmanagerimp.hpp"
|
||||||
#include "../mwscript/scriptmanagerimp.hpp"
|
#include "../mwscript/scriptmanagerimp.hpp"
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
|
|
||||||
#include "LocalPlayer.hpp"
|
#include "LocalPlayer.hpp"
|
||||||
#include "Networking.hpp"
|
#include "Networking.hpp"
|
||||||
|
#include "WorldController.hpp"
|
||||||
#include "Main.hpp"
|
#include "Main.hpp"
|
||||||
|
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
|
@ -643,6 +645,34 @@ void LocalPlayer::addSpells()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalPlayer::addJournalItems()
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < journalChanges.count; i++)
|
||||||
|
{
|
||||||
|
mwmp::JournalItem journalItem = journalChanges.journalItems[i];
|
||||||
|
|
||||||
|
if (journalItem.type == JournalItem::ENTRY)
|
||||||
|
{
|
||||||
|
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(journalItem.actorCell);
|
||||||
|
|
||||||
|
if (!ptrCellStore) continue;
|
||||||
|
|
||||||
|
MWWorld::Ptr ptrFound = ptrCellStore->searchExact(journalItem.actorCellRef.mRefID, journalItem.actorCellRef.mRefNum.mIndex);
|
||||||
|
|
||||||
|
if (!ptrFound)
|
||||||
|
{
|
||||||
|
ptrFound = getPlayerPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
MWBase::Environment::get().getJournal()->addEntry(journalItem.quest, journalItem.index, ptrFound);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getJournal()->setJournalIndex(journalItem.quest, journalItem.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LocalPlayer::removeItems()
|
void LocalPlayer::removeItems()
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
||||||
|
@ -998,13 +1028,35 @@ void LocalPlayer::sendSpellRemoval(const ESM::Spell &spell)
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Not implemented.");
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::sendJournalEntry(const std::string& id, int index, const MWWorld::Ptr& actor)
|
void LocalPlayer::sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor)
|
||||||
{
|
{
|
||||||
|
journalChanges.journalItems.clear();
|
||||||
|
|
||||||
|
mwmp::JournalItem journalItem;
|
||||||
|
journalItem.type = JournalItem::ENTRY;
|
||||||
|
journalItem.quest = quest;
|
||||||
|
journalItem.index = index;
|
||||||
|
|
||||||
|
journalItem.actorCell = *actor.getCell()->getCell();
|
||||||
|
journalItem.actorCellRef.mRefID = actor.getCellRef().getRefId();
|
||||||
|
journalItem.actorCellRef.mRefNum = actor.getCellRef().getRefNum();
|
||||||
|
|
||||||
|
journalChanges.journalItems.push_back(journalItem);
|
||||||
|
|
||||||
Main::get().getNetworking()->getPlayerPacket(ID_GAME_JOURNAL)->Send(this);
|
Main::get().getNetworking()->getPlayerPacket(ID_GAME_JOURNAL)->Send(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::sendJournalIndex(const std::string& id, int index)
|
void LocalPlayer::sendJournalIndex(const std::string& quest, int index)
|
||||||
{
|
{
|
||||||
|
journalChanges.journalItems.clear();
|
||||||
|
|
||||||
|
mwmp::JournalItem journalItem;
|
||||||
|
journalItem.type = JournalItem::INDEX;
|
||||||
|
journalItem.quest = quest;
|
||||||
|
journalItem.index = index;
|
||||||
|
|
||||||
|
journalChanges.journalItems.push_back(journalItem);
|
||||||
|
|
||||||
Main::get().getNetworking()->getPlayerPacket(ID_GAME_JOURNAL)->Send(this);
|
Main::get().getNetworking()->getPlayerPacket(ID_GAME_JOURNAL)->Send(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace mwmp
|
||||||
|
|
||||||
void addItems();
|
void addItems();
|
||||||
void addSpells();
|
void addSpells();
|
||||||
|
void addJournalItems();
|
||||||
|
|
||||||
void removeItems();
|
void removeItems();
|
||||||
void removeSpells();
|
void removeSpells();
|
||||||
|
|
|
@ -348,6 +348,18 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
|
||||||
}
|
}
|
||||||
case ID_GAME_JOURNAL:
|
case ID_GAME_JOURNAL:
|
||||||
{
|
{
|
||||||
|
if (guid == myGuid)
|
||||||
|
{
|
||||||
|
if (packet->length == myPacket->headerSize())
|
||||||
|
{
|
||||||
|
// Entire journal cannot currently be requested from players
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myPacket->Packet(&bsIn, getLocalPlayer(), false);
|
||||||
|
getLocalPlayer()->addJournalItems();
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ID_GAME_ATTACK:
|
case ID_GAME_ATTACK:
|
||||||
|
|
|
@ -55,6 +55,10 @@ namespace mwmp
|
||||||
ENTRY = 0,
|
ENTRY = 0,
|
||||||
INDEX = 1
|
INDEX = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ESM::Cell actorCell;
|
||||||
|
ESM::CellRef actorCellRef;
|
||||||
|
|
||||||
int type; // 0 - An entire entry, 1 - An index
|
int type; // 0 - An entire entry, 1 - An index
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,6 +213,7 @@ namespace mwmp
|
||||||
double hour;
|
double hour;
|
||||||
InventoryChanges inventoryChanges;
|
InventoryChanges inventoryChanges;
|
||||||
SpellbookChanges spellbookChanges;
|
SpellbookChanges spellbookChanges;
|
||||||
|
JournalChanges journalChanges;
|
||||||
bool consoleAllowed;
|
bool consoleAllowed;
|
||||||
bool ignorePosPacket;
|
bool ignorePosPacket;
|
||||||
ESM::ActiveSpells activeSpells;
|
ESM::ActiveSpells activeSpells;
|
||||||
|
|
|
@ -12,4 +12,36 @@ PacketJournal::PacketJournal(RakNet::RakPeerInterface *peer) : PlayerPacket(peer
|
||||||
void PacketJournal::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
void PacketJournal::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
||||||
{
|
{
|
||||||
PlayerPacket::Packet(bs, player, send);
|
PlayerPacket::Packet(bs, player, send);
|
||||||
|
|
||||||
|
if (!send)
|
||||||
|
player->journalChanges.journalItems.clear();
|
||||||
|
else
|
||||||
|
player->journalChanges.count = (unsigned int)(player->journalChanges.journalItems.size());
|
||||||
|
|
||||||
|
RW(player->journalChanges.count, send);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < player->journalChanges.count; i++)
|
||||||
|
{
|
||||||
|
JournalItem journalItem;
|
||||||
|
|
||||||
|
if (send)
|
||||||
|
journalItem = player->journalChanges.journalItems[i];
|
||||||
|
|
||||||
|
RW(journalItem.type, send);
|
||||||
|
RW(journalItem.quest, send);
|
||||||
|
RW(journalItem.index, send);
|
||||||
|
|
||||||
|
if (journalItem.type == JournalItem::ENTRY)
|
||||||
|
{
|
||||||
|
RW(journalItem.actorCellRef.mRefID, send);
|
||||||
|
RW(journalItem.actorCellRef.mRefNum.mIndex, send);
|
||||||
|
RW(journalItem.actorCell.mData.mFlags, send);
|
||||||
|
RW(journalItem.actorCell.mData.mX, send);
|
||||||
|
RW(journalItem.actorCell.mData.mY, send);
|
||||||
|
RW(journalItem.actorCell.mName, send);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!send)
|
||||||
|
player->journalChanges.journalItems.push_back(journalItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue