From 989f6e6b517ef0ff550ac457f97a9401c0b9cff0 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 30 Jan 2018 22:55:29 +0200 Subject: [PATCH] [General] Implement PlayerReputation packet --- apps/openmw-mp/Script/Functions/Quests.cpp | 25 ++++++++++++++ apps/openmw-mp/Script/Functions/Quests.hpp | 34 ++++++++++++++++++- apps/openmw/mwmp/LocalPlayer.cpp | 23 +++++++++++++ apps/openmw/mwmp/LocalPlayer.hpp | 2 ++ .../player/ProcessorPlayerReputation.hpp | 12 ++----- .../Packets/Player/PacketPlayerReputation.cpp | 2 +- 6 files changed, 87 insertions(+), 11 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Quests.cpp b/apps/openmw-mp/Script/Functions/Quests.cpp index 7c85ec956..d9d3606f9 100644 --- a/apps/openmw-mp/Script/Functions/Quests.cpp +++ b/apps/openmw-mp/Script/Functions/Quests.cpp @@ -79,6 +79,14 @@ void QuestFunctions::AddKill(unsigned short pid, const char* refId, int number) player->killChanges.kills.push_back(kill); } +void QuestFunctions::SetReputation(unsigned short pid, int value) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->npcStats.mReputation = value; +} + const char *QuestFunctions::GetJournalItemQuest(unsigned short pid, unsigned int i) noexcept { Player *player; @@ -133,6 +141,14 @@ int QuestFunctions::GetKillNumber(unsigned short pid, unsigned int i) noexcept return player->killChanges.kills.at(i).number; } +int QuestFunctions::GetReputation(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->npcStats.mReputation; +} + void QuestFunctions::SendJournalChanges(unsigned short pid, bool toOthers) noexcept { Player *player; @@ -150,3 +166,12 @@ void QuestFunctions::SendKillChanges(unsigned short pid, bool toOthers) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->Send(toOthers); } + +void QuestFunctions::SendReputation(unsigned short pid, bool toOthers) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION)->Send(toOthers); +} diff --git a/apps/openmw-mp/Script/Functions/Quests.hpp b/apps/openmw-mp/Script/Functions/Quests.hpp index 3ce431dda..d140137de 100644 --- a/apps/openmw-mp/Script/Functions/Quests.hpp +++ b/apps/openmw-mp/Script/Functions/Quests.hpp @@ -12,6 +12,8 @@ {"AddJournalIndex", QuestFunctions::AddJournalIndex},\ {"AddKill", QuestFunctions::AddKill},\ \ + {"SetReputation", QuestFunctions::SetReputation},\ + \ {"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\ {"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\ {"GetJournalItemType", QuestFunctions::GetJournalItemType},\ @@ -19,8 +21,11 @@ {"GetKillRefId", QuestFunctions::GetKillRefId},\ {"GetKillNumber", QuestFunctions::GetKillNumber},\ \ + {"GetReputation", QuestFunctions::GetReputation},\ + \ {"SendJournalChanges", QuestFunctions::SendJournalChanges},\ - {"SendKillChanges", QuestFunctions::SendKillChanges} + {"SendKillChanges", QuestFunctions::SendKillChanges},\ + {"SendReputation", QuestFunctions::SendReputation} class QuestFunctions { @@ -93,6 +98,15 @@ public: */ static void AddKill(unsigned short pid, const char* refId, int number) noexcept; + /** + * \brief Set the reputation of a certain player. + * + * \param pid The player ID. + * \param value The reputation. + * \return void + */ + static void SetReputation(unsigned short pid, int value) noexcept; + /** * \brief Get the quest at a certain index in a player's latest journal changes. * @@ -149,6 +163,14 @@ public: */ static int GetKillNumber(unsigned short pid, unsigned int i) noexcept; + /** + * \brief Get the a certain player's reputation. + * + * \param pid The player ID. + * \return The reputation. + */ + static int GetReputation(unsigned short pid) noexcept; + /** * \brief Send a PlayerJournal packet with a player's recorded journal changes. * @@ -169,6 +191,16 @@ public: */ static void SendKillChanges(unsigned short pid, bool toOthers = false) noexcept; + /** + * \brief Send a PlayerReputation packet with a player's recorded reputation. + * + * \param pid The player ID whose reputation should be used. + * \param toOthers Whether this packet should be sent only to other players or + * only to the player it is about. + * \return void + */ + static void SendReputation(unsigned short pid, bool toOthers) noexcept; + private: }; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 56a426807..a6528c8ec 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -105,6 +105,7 @@ void LocalPlayer::update() updateSkills(); updateLevel(); updateBounty(); + updateReputation(); } } @@ -328,6 +329,19 @@ void LocalPlayer::updateBounty(bool forceUpdate) } } +void LocalPlayer::updateReputation(bool forceUpdate) +{ + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + const MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer); + + if (ptrNpcStats.getReputation() != npcStats.mReputation || forceUpdate) + { + npcStats.mReputation = ptrNpcStats.getReputation(); + getNetworking()->getPlayerPacket(ID_PLAYER_REPUTATION)->setPlayer(this); + getNetworking()->getPlayerPacket(ID_PLAYER_REPUTATION)->Send(); + } +} + void LocalPlayer::updatePosition(bool forceUpdate) { MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -928,6 +942,15 @@ void LocalPlayer::setBounty() ptrNpcStats->setBounty(npcStats.mBounty); } +void LocalPlayer::setReputation() +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWWorld::Ptr ptrPlayer = world->getPlayerPtr(); + + MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); + ptrNpcStats->setReputation(npcStats.mReputation); +} + void LocalPlayer::setPosition() { MWBase::World *world = MWBase::Environment::get().getWorld(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 1900b07b4..3f3da26ef 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -30,6 +30,7 @@ namespace mwmp void updateSkills(bool forceUpdate = false); void updateLevel(bool forceUpdate = false); void updateBounty(bool forceUpdate = false); + void updateReputation(bool forceUpdate = false); void updatePosition(bool forceUpdate = false); void updateCell(bool forceUpdate = false); void updateChar(); @@ -56,6 +57,7 @@ namespace mwmp void setSkills(); void setLevel(); void setBounty(); + void setReputation(); void setPosition(); void setCell(); void setClass(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerReputation.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerReputation.hpp index 4bdf7ee8b..ae932fa5c 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerReputation.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerReputation.hpp @@ -16,19 +16,13 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { - if (isLocal()) + if (isRequest()) { - //if (isRequest()) - // static_cast(player)->updateReputation(true); - //else - // static_cast(player)->setReputation(); + static_cast(player)->updateReputation(true); } else if (player != 0) { - MWWorld::Ptr ptrPlayer = static_cast(player)->getPtr(); - MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer); - - ptrNpcStats->setReputation(player->npcStats.mReputation); + static_cast(player)->setReputation(); } } }; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerReputation.cpp b/components/openmw-mp/Packets/Player/PacketPlayerReputation.cpp index 291846ef9..25f058a98 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerReputation.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerReputation.cpp @@ -12,5 +12,5 @@ void PacketPlayerReputation::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - // Placeholder + RW(player->npcStats.mReputation, send); }