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

[General] Synchronize gold pools for traders via ObjectMiscellaneous

This commit is contained in:
David Cernat 2020-05-16 02:51:11 +03:00
parent 297a254210
commit 23ff7b9610
7 changed files with 81 additions and 5 deletions

View file

@ -12,6 +12,14 @@ namespace mwmp
{
BPP_INIT(ID_OBJECT_MISCELLANEOUS)
}
void Do(ObjectPacket& packet, Player& player, BaseObjectList& objectList) override
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received %s from %s", strPacketID.c_str(), player.npc.mName.c_str());
packet.Send(false);
packet.Send(true);
}
};
}

View file

@ -396,8 +396,23 @@ namespace MWGui
if (mCurrentBalance != 0)
{
addOrRemoveGold(mCurrentBalance, player);
mPtr.getClass().getCreatureStats(mPtr).setGoldPool(
mPtr.getClass().getCreatureStats(mPtr).getGoldPool() - mCurrentBalance );
/*
Start of tes3mp change (major)
Don't unilaterally change the merchant's gold pool on our client and instead let the server do it
*/
//mPtr.getClass().getCreatureStats(mPtr).setGoldPool(
// mPtr.getClass().getCreatureStats(mPtr).getGoldPool() - mCurrentBalance);
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset();
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
objectList->addObjectMiscellaneous(mPtr, mPtr.getClass().getCreatureStats(mPtr).getGoldPool() - mCurrentBalance);
objectList->sendObjectMiscellaneous();
/*
End of tes3mp change (major)
*/
}
eventTradeDone();

View file

@ -813,6 +813,33 @@ void ObjectList::playObjectSounds(MWWorld::CellStore* cellStore)
}
}
void ObjectList::setGoldPoolsForObjects(MWWorld::CellStore* cellStore)
{
for (const auto& baseObject : baseObjects)
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
if (ptrFound)
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Found %s %i-%i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
if (ptrFound.getClass().isActor())
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Setting gold pool to %u", baseObject.goldPool);
ptrFound.getClass().getCreatureStats(ptrFound).setGoldPool(baseObject.goldPool);
}
else
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_WARN, "Failed to set gold pool on %s %i-%i because it is not an actor!",
ptrFound.getCellRef().getRefId().c_str(), ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
}
}
}
}
void ObjectList::activateDoors(MWWorld::CellStore* cellStore)
{
for (const auto &baseObject : baseObjects)
@ -1166,6 +1193,15 @@ void ObjectList::addObjectLock(const MWWorld::Ptr& ptr, int lockLevel)
addBaseObject(baseObject);
}
void ObjectList::addObjectMiscellaneous(const MWWorld::Ptr& ptr, unsigned int goldPool)
{
cell = *ptr.getCell()->getCell();
mwmp::BaseObject baseObject = getBaseObjectFromPtr(ptr);
baseObject.goldPool = goldPool;
addBaseObject(baseObject);
}
void ObjectList::addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed)
{
cell = *ptr.getCell()->getCell();
@ -1322,6 +1358,12 @@ void ObjectList::sendObjectLock()
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_LOCK)->Send();
}
void ObjectList::sendObjectMiscellaneous()
{
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_MISCELLANEOUS)->setObjectList(this);
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_MISCELLANEOUS)->Send();
}
void ObjectList::sendObjectRestock()
{
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_RESTOCK)->setObjectList(this);

View file

@ -38,6 +38,7 @@ namespace mwmp
void rotateObjects(MWWorld::CellStore* cellStore);
void animateObjects(MWWorld::CellStore* cellStore);
void playObjectSounds(MWWorld::CellStore* cellStore);
void setGoldPoolsForObjects(MWWorld::CellStore* cellStore);
void activateDoors(MWWorld::CellStore* cellStore);
void setDoorDestinations(MWWorld::CellStore* cellStore);
void runConsoleCommands(MWWorld::CellStore* cellStore);
@ -59,6 +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 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);
@ -78,6 +80,7 @@ namespace mwmp
void sendObjectSpawn();
void sendObjectDelete();
void sendObjectLock();
void sendObjectMiscellaneous();
void sendObjectRestock();
void sendObjectTrap();
void sendObjectScale();

View file

@ -1,11 +1,11 @@
#ifndef OPENMW_PROCESSOROBJECTMISCELLANEOUS_HPP
#define OPENMW_PROCESSOROBJECTMISCELLANEOUS_HPP
#include "../ObjectProcessor.hpp"
#include "BaseObjectProcessor.hpp"
namespace mwmp
{
class ProcessorObjectMiscellaneous final: public ObjectProcessor
class ProcessorObjectMiscellaneous final: public BaseObjectProcessor
{
public:
ProcessorObjectMiscellaneous()
@ -16,6 +16,10 @@ namespace mwmp
virtual void Do(ObjectPacket &packet, ObjectList &objectList)
{
LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Received %s", strPacketID.c_str());
BaseObjectProcessor::Do(packet, objectList);
objectList.setGoldPoolsForObjects(ptrCellStore);
}
};
}

View file

@ -45,6 +45,8 @@ namespace mwmp
float volume;
float pitch;
unsigned int goldPool;
int doorState;
bool teleportState;
ESM::Cell destinationCell;

View file

@ -6,9 +6,11 @@ using namespace mwmp;
PacketObjectMiscellaneous::PacketObjectMiscellaneous(RakNet::RakPeerInterface *peer) : ObjectPacket(peer)
{
packetID = ID_OBJECT_MISCELLANEOUS;
hasCellData = true;
}
void PacketObjectMiscellaneous::Object(BaseObject &baseObject, bool send)
{
ObjectPacket::Object(baseObject, send);
RW(baseObject.goldPool, send);
}