1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-30 16:45:33 +00:00

[General] Include last gold restock time in ObjectMiscellaneous packets

This commit is contained in:
David Cernat 2020-05-16 19:10:11 +03:00
parent 7833ae9a3f
commit 3c51f1c23a
8 changed files with 106 additions and 5 deletions

View file

@ -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;

View file

@ -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.

View file

@ -10,6 +10,18 @@
#include <components/widgets/list.hpp>
#include <components/translation/translation.hpp>
/*
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)
*/
}
}

View file

@ -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)

View file

@ -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);
}

View file

@ -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);

View file

@ -46,6 +46,9 @@ namespace mwmp
float pitch;
unsigned int goldPool;
float lastGoldRestockHour;
int lastGoldRestockDay;
int doorState;
bool teleportState;

View file

@ -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);
}