[General] Implement sending and reading of PlayerTopic packets

This commit is contained in:
David Cernat 2017-05-24 21:43:34 +03:00
parent 08de349133
commit 11369f6513
8 changed files with 85 additions and 5 deletions

View file

@ -28,6 +28,7 @@
*/ */
#include "../mwmp/Main.hpp" #include "../mwmp/Main.hpp"
#include "../mwmp/CellController.hpp" #include "../mwmp/CellController.hpp"
#include "../mwmp/LocalPlayer.hpp"
#include "../mwmp/LocalActor.hpp" #include "../mwmp/LocalActor.hpp"
/* /*
End of tes3mp addition End of tes3mp addition
@ -117,6 +118,17 @@ namespace MWDialogue
if (tok->isImplicitKeyword() && mTranslationDataStorage.hasTranslation()) if (tok->isImplicitKeyword() && mTranslationDataStorage.hasTranslation())
continue; continue;
/*
Start of tes3mp addition
Send an ID_PLAYER_TOPIC packet every time a new topic becomes known
*/
if (mActorKnownTopics.count(topicId) && !mKnownTopics.count(topicId))
mwmp::Main::get().getLocalPlayer()->sendTopic(topicId);
/*
End of tes3mp addition
*/
if (mActorKnownTopics.count( topicId )) if (mActorKnownTopics.count( topicId ))
mKnownTopics.insert( topicId ); mKnownTopics.insert( topicId );
} }

View file

@ -687,6 +687,16 @@ void LocalPlayer::addJournalItems()
} }
} }
void LocalPlayer::addTopics()
{
for (unsigned int i = 0; i < topicChanges.count; i++)
{
mwmp::Topic topic = topicChanges.topics.at(i);
MWBase::Environment::get().getDialogueManager()->addTopic(topic.topicId);
}
}
void LocalPlayer::removeItems() void LocalPlayer::removeItems()
{ {
MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::Ptr ptrPlayer = getPlayerPtr();
@ -1166,6 +1176,19 @@ void LocalPlayer::sendFaction(const std::string& factionId, int rank, bool isExp
getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_FACTION)->Send();
} }
void LocalPlayer::sendTopic(const std::string& topicId)
{
topicChanges.topics.clear();
mwmp::Topic topic;
topic.topicId = topicId;
topicChanges.topics.push_back(topic);
getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_TOPIC)->Send();
}
void LocalPlayer::clearCellStates() void LocalPlayer::clearCellStates()
{ {
cellStateChanges.cellStates.clear(); cellStateChanges.cellStates.clear();

View file

@ -42,6 +42,7 @@ namespace mwmp
void addItems(); void addItems();
void addSpells(); void addSpells();
void addJournalItems(); void addJournalItems();
void addTopics();
void removeItems(); void removeItems();
void removeSpells(); void removeSpells();
@ -70,6 +71,7 @@ namespace mwmp
void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor); void sendJournalEntry(const std::string& quest, int index, const MWWorld::Ptr& actor);
void sendJournalIndex(const std::string& quest, int index); void sendJournalIndex(const std::string& quest, int index);
void sendFaction(const std::string& factionId, int rank, bool isExpelled); void sendFaction(const std::string& factionId, int rank, bool isExpelled);
void sendTopic(const std::string& topic);
void clearCellStates(); void clearCellStates();
void clearCurrentContainer(); void clearCurrentContainer();

View file

@ -20,8 +20,8 @@ namespace mwmp
{ {
// Entire list of topics cannot currently be requested from players // Entire list of topics cannot currently be requested from players
} }
//else else
//static_cast<LocalPlayer*>(player)->addTopics(); static_cast<LocalPlayer*>(player)->addTopics();
} }
}; };
} }

View file

@ -127,6 +127,17 @@ namespace MWScript
runtime.pop(); runtime.pop();
MWBase::Environment::get().getDialogueManager()->addTopic(topic); MWBase::Environment::get().getDialogueManager()->addTopic(topic);
/*
Start of tes3mp addition
Send an ID_PLAYER_TOPIC packet every time a topic is added
through a script
*/
mwmp::Main::get().getLocalPlayer()->sendTopic(topic);
/*
End of tes3mp addition
*/
} }
}; };

View file

@ -63,6 +63,11 @@ namespace mwmp
bool isExpelled; bool isExpelled;
}; };
struct Topic
{
std::string topicId;
};
struct CellState struct CellState
{ {
ESM::Cell cell; ESM::Cell cell;
@ -88,6 +93,12 @@ namespace mwmp
unsigned int count; unsigned int count;
}; };
struct TopicChanges
{
std::vector<Topic> topics;
unsigned int count;
};
struct InventoryChanges struct InventoryChanges
{ {
std::vector<Item> items; std::vector<Item> items;
@ -171,6 +182,7 @@ namespace mwmp
SpellbookChanges spellbookChanges; SpellbookChanges spellbookChanges;
JournalChanges journalChanges; JournalChanges journalChanges;
FactionChanges factionChanges; FactionChanges factionChanges;
TopicChanges topicChanges;
CellStateChanges cellStateChanges; CellStateChanges cellStateChanges;
ESM::ActiveSpells activeSpells; ESM::ActiveSpells activeSpells;
CurrentContainer currentContainer; CurrentContainer currentContainer;

View file

@ -13,10 +13,10 @@ void PacketPlayerFaction::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
if (!send) if (send)
player->factionChanges.factions.clear();
else
player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size()); player->factionChanges.count = (unsigned int)(player->factionChanges.factions.size());
else
player->factionChanges.factions.clear();
RW(player->factionChanges.count, send); RW(player->factionChanges.count, send);

View file

@ -12,4 +12,24 @@ PacketPlayerTopic::PacketPlayerTopic(RakNet::RakPeerInterface *peer) : PlayerPac
void PacketPlayerTopic::Packet(RakNet::BitStream *bs, bool send) void PacketPlayerTopic::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
if (send)
player->topicChanges.count = (unsigned int)(player->topicChanges.topics.size());
else
player->topicChanges.topics.clear();
RW(player->topicChanges.count, send);
for (unsigned int i = 0; i < player->topicChanges.count; i++)
{
Topic topic;
if (send)
topic = player->topicChanges.topics.at(i);
RW(topic.topicId, send);
if (!send)
player->topicChanges.topics.push_back(topic);
}
} }