From 3c51f1c23ab2db123223d353152e0816b53c5d34 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 16 May 2020 19:10:11 +0300 Subject: [PATCH] [General] Include last gold restock time in ObjectMiscellaneous packets --- apps/openmw-mp/Script/Functions/Objects.cpp | 22 +++++++++- apps/openmw-mp/Script/Functions/Objects.hpp | 40 ++++++++++++++++++- apps/openmw/mwgui/dialogue.cpp | 28 +++++++++++++ apps/openmw/mwgui/tradewindow.cpp | 4 +- apps/openmw/mwmp/ObjectList.cpp | 10 ++++- apps/openmw/mwmp/ObjectList.hpp | 2 +- components/openmw-mp/Base/BaseObject.hpp | 3 ++ .../Object/PacketObjectMiscellaneous.cpp | 2 + 8 files changed, 106 insertions(+), 5 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index 89a0ab1e3..b28633f0d 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -159,6 +159,16 @@ unsigned int ObjectFunctions::GetObjectGoldPool(unsigned int index) noexcept return readObjectList->baseObjects.at(index).goldPool; } +double ObjectFunctions::GetObjectLastGoldRestockHour(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).lastGoldRestockHour; +} + +int ObjectFunctions::GetObjectLastGoldRestockDay(unsigned int index) noexcept +{ + return readObjectList->baseObjects.at(index).lastGoldRestockDay; +} + bool ObjectFunctions::DoesObjectHavePlayerActivating(unsigned int index) noexcept { return readObjectList->baseObjects.at(index).activatingActor.isPlayer; @@ -465,11 +475,21 @@ void ObjectFunctions::SetObjectLockLevel(int lockLevel) noexcept tempObject.lockLevel = lockLevel; } -void ObjectFunctions::SetObjectGoldPool(int goldPool) noexcept +void ObjectFunctions::SetObjectGoldPool(unsigned int goldPool) noexcept { tempObject.goldPool = goldPool; } +void ObjectFunctions::SetObjectLastGoldRestockHour(double lastGoldRestockHour) noexcept +{ + tempObject.lastGoldRestockHour = lastGoldRestockHour; +} + +void ObjectFunctions::SetObjectLastGoldRestockDay(int lastGoldRestockDay) noexcept +{ + tempObject.lastGoldRestockDay = lastGoldRestockDay; +} + void ObjectFunctions::SetObjectDisarmState(bool disarmState) noexcept { tempObject.isDisarmed = disarmState; diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index ba0d17937..f0afc34e9 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -32,6 +32,8 @@ {"GetObjectDoorState", ObjectFunctions::GetObjectDoorState},\ {"GetObjectLockLevel", ObjectFunctions::GetObjectLockLevel},\ {"GetObjectGoldPool", ObjectFunctions::GetObjectGoldPool},\ + {"GetObjectLastGoldRestockHour", ObjectFunctions::GetObjectLastGoldRestockHour},\ + {"GetObjectLastGoldRestockDay", ObjectFunctions::GetObjectLastGoldRestockDay},\ \ {"DoesObjectHavePlayerActivating", ObjectFunctions::DoesObjectHavePlayerActivating},\ {"GetObjectActivatingPid", ObjectFunctions::GetObjectActivatingPid},\ @@ -100,6 +102,8 @@ {"SetObjectState", ObjectFunctions::SetObjectState},\ {"SetObjectLockLevel", ObjectFunctions::SetObjectLockLevel},\ {"SetObjectGoldPool", ObjectFunctions::SetObjectGoldPool},\ + {"SetObjectLastGoldRestockHour", ObjectFunctions::SetObjectLastGoldRestockHour},\ + {"SetObjectLastGoldRestockDay", ObjectFunctions::SetObjectLastGoldRestockDay},\ {"SetObjectDisarmState", ObjectFunctions::SetObjectDisarmState},\ {"SetObjectDroppedByPlayerState", ObjectFunctions::SetObjectDroppedByPlayerState},\ {"SetObjectPosition", ObjectFunctions::SetObjectPosition},\ @@ -392,6 +396,24 @@ public: */ static unsigned int GetObjectGoldPool(unsigned int index) noexcept; + /** + * \brief Get the hour of the last gold restock of the object at a certain index in the + * read object list. + * + * \param index The index of the object. + * \return The hour of the last gold restock. + */ + static double GetObjectLastGoldRestockHour(unsigned int index) noexcept; + + /** + * \brief Get the day of the last gold restock of the object at a certain index in the + * read object list. + * + * \param index The index of the object. + * \return The day of the last gold restock. + */ + static int GetObjectLastGoldRestockDay(unsigned int index) noexcept; + /** * \brief Check whether the object at a certain index in the read object list has been * activated by a player. @@ -916,7 +938,23 @@ public: * \param goldPool The gold pool. * \return void */ - static void SetObjectGoldPool(int goldPool) noexcept; + static void SetObjectGoldPool(unsigned int goldPool) noexcept; + + /** + * \brief Set the hour of the last gold restock of the temporary object stored on the server. + * + * \param hour The hour of the last gold restock. + * \return void + */ + static void SetObjectLastGoldRestockHour(double hour) noexcept; + + /** + * \brief Set the day of the last gold restock of the temporary object stored on the server. + * + * \param day The day of the last gold restock. + * \return void + */ + static void SetObjectLastGoldRestockDay(int day) noexcept; /** * \brief Set the disarm state of the temporary object stored on the server. diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 76b219009..a004458de 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -10,6 +10,18 @@ #include #include +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include "../mwmp/Main.hpp" +#include "../mwmp/Networking.hpp" +#include "../mwmp/ObjectList.hpp" +/* + End of tes3mp addition +*/ + #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -462,9 +474,25 @@ namespace MWGui // Gold is restocked every 24h if (MWBase::Environment::get().getWorld()->getTimeStamp() >= sellerStats.getLastRestockTime() + delay) { + /* + Start of tes3mp change (major) + + Instead of restocking the NPC's gold pool or last restock time here, send a packet about them to the server + */ + /* sellerStats.setGoldPool(mPtr.getClass().getBaseGold(mPtr)); sellerStats.setLastRestockTime(MWBase::Environment::get().getWorld()->getTimeStamp()); + */ + mwmp::ObjectList* objectList = mwmp::Main::get().getNetworking()->getObjectList(); + objectList->reset(); + objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY; + objectList->addObjectMiscellaneous(mPtr, mPtr.getClass().getBaseGold(mPtr), MWBase::Environment::get().getWorld()->getTimeStamp().getHour(), + MWBase::Environment::get().getWorld()->getTimeStamp().getDay()); + objectList->sendObjectMiscellaneous(); + /* + End of tes3mp change (major) + */ } } diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index ad2278f29..bb20135c0 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -408,7 +408,9 @@ namespace MWGui mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); objectList->reset(); objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY; - objectList->addObjectMiscellaneous(mPtr, mPtr.getClass().getCreatureStats(mPtr).getGoldPool() - mCurrentBalance); + MWMechanics::CreatureStats& merchantCreatureStats = mPtr.getClass().getCreatureStats(mPtr); + objectList->addObjectMiscellaneous(mPtr, merchantCreatureStats.getGoldPool() - mCurrentBalance, merchantCreatureStats.getLastRestockTime().getHour(), + merchantCreatureStats.getLastRestockTime().getDay()); objectList->sendObjectMiscellaneous(); /* End of tes3mp change (major) diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp index 67071b89a..501fd5822 100644 --- a/apps/openmw/mwmp/ObjectList.cpp +++ b/apps/openmw/mwmp/ObjectList.cpp @@ -35,6 +35,7 @@ #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwworld/manualref.hpp" +#include "../mwworld/timestamp.hpp" using namespace mwmp; using namespace std; @@ -830,6 +831,11 @@ void ObjectList::setGoldPoolsForObjects(MWWorld::CellStore* cellStore) { LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Setting gold pool to %u", baseObject.goldPool); ptrFound.getClass().getCreatureStats(ptrFound).setGoldPool(baseObject.goldPool); + + LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Setting last gold restock time to %f hours and %i days passed", + baseObject.lastGoldRestockHour, baseObject.lastGoldRestockDay); + ptrFound.getClass().getCreatureStats(ptrFound).setLastRestockTime(MWWorld::TimeStamp::TimeStamp(baseObject.lastGoldRestockHour, + baseObject.lastGoldRestockDay)); } else { @@ -1193,12 +1199,14 @@ void ObjectList::addObjectLock(const MWWorld::Ptr& ptr, int lockLevel) addBaseObject(baseObject); } -void ObjectList::addObjectMiscellaneous(const MWWorld::Ptr& ptr, unsigned int goldPool) +void ObjectList::addObjectMiscellaneous(const MWWorld::Ptr& ptr, unsigned int goldPool, float lastGoldRestockHour, int lastGoldRestockDay) { cell = *ptr.getCell()->getCell(); mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr); baseObject.goldPool = goldPool; + baseObject.lastGoldRestockHour = lastGoldRestockHour; + baseObject.lastGoldRestockDay = lastGoldRestockDay; addBaseObject(baseObject); } diff --git a/apps/openmw/mwmp/ObjectList.hpp b/apps/openmw/mwmp/ObjectList.hpp index eab2eed74..cf6ba9100 100644 --- a/apps/openmw/mwmp/ObjectList.hpp +++ b/apps/openmw/mwmp/ObjectList.hpp @@ -60,7 +60,7 @@ namespace mwmp void addObjectSpawn(const MWWorld::Ptr& ptr); void addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& master, std::string spellId, int effectId, float duration); void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel); - void addObjectMiscellaneous(const MWWorld::Ptr& ptr, unsigned int goldPool); + void addObjectMiscellaneous(const MWWorld::Ptr& ptr, unsigned int goldPool, float lastGoldRestockHour, int lastGoldRestockDay); void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed); void addObjectScale(const MWWorld::Ptr& ptr, float scale); void addObjectSound(const MWWorld::Ptr& ptr, std::string soundId, float volume, float pitch); diff --git a/components/openmw-mp/Base/BaseObject.hpp b/components/openmw-mp/Base/BaseObject.hpp index 89c498c89..eaa4d92b2 100644 --- a/components/openmw-mp/Base/BaseObject.hpp +++ b/components/openmw-mp/Base/BaseObject.hpp @@ -46,6 +46,9 @@ namespace mwmp float pitch; unsigned int goldPool; + float lastGoldRestockHour; + int lastGoldRestockDay; + int doorState; bool teleportState; diff --git a/components/openmw-mp/Packets/Object/PacketObjectMiscellaneous.cpp b/components/openmw-mp/Packets/Object/PacketObjectMiscellaneous.cpp index 80c97cc90..7f618e000 100644 --- a/components/openmw-mp/Packets/Object/PacketObjectMiscellaneous.cpp +++ b/components/openmw-mp/Packets/Object/PacketObjectMiscellaneous.cpp @@ -13,4 +13,6 @@ void PacketObjectMiscellaneous::Object(BaseObject &baseObject, bool send) { ObjectPacket::Object(baseObject, send); RW(baseObject.goldPool, send); + RW(baseObject.lastGoldRestockHour, send); + RW(baseObject.lastGoldRestockDay, send); }