mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-04-01 11:06:41 +00:00
[General] Implement ObjectRestock packet
Restocking object containers via trading now requires the server to send back an ObjectRestock packet before it can happen. The unused packet ID ID_SCRIPT_GLOBAL_FLOAT has been replaced with ID_OBJECT_RESTOCK.
This commit is contained in:
parent
59a38164ea
commit
975797c09b
18 changed files with 198 additions and 15 deletions
|
@ -118,12 +118,12 @@ set(PROCESSORS_OBJECT
|
|||
processors/object/ProcessorObjectActivate.hpp processors/object/ProcessorObjectAnimPlay.hpp
|
||||
processors/object/ProcessorObjectDelete.hpp processors/object/ProcessorObjectHit.hpp
|
||||
processors/object/ProcessorObjectLock.hpp processors/object/ProcessorObjectMove.hpp
|
||||
processors/object/ProcessorObjectPlace.hpp processors/object/ProcessorObjectRotate.hpp
|
||||
processors/object/ProcessorObjectScale.hpp processors/object/ProcessorObjectSpawn.hpp
|
||||
processors/object/ProcessorObjectState.hpp processors/object/ProcessorObjectTrap.hpp
|
||||
processors/object/ProcessorScriptLocalShort.hpp processors/object/ProcessorScriptLocalFloat.hpp
|
||||
processors/object/ProcessorScriptMemberShort.hpp processors/object/ProcessorScriptMemberFloat.hpp
|
||||
processors/object/ProcessorVideoPlay.hpp
|
||||
processors/object/ProcessorObjectPlace.hpp processors/object/ProcessorObjectRestock.hpp
|
||||
processors/object/ProcessorObjectRotate.hpp processors/object/ProcessorObjectScale.hpp
|
||||
processors/object/ProcessorObjectSpawn.hpp processors/object/ProcessorObjectState.hpp
|
||||
processors/object/ProcessorObjectTrap.hpp processors/object/ProcessorScriptLocalShort.hpp
|
||||
processors/object/ProcessorScriptLocalFloat.hpp processors/object/ProcessorScriptMemberShort.hpp
|
||||
processors/object/ProcessorScriptMemberFloat.hpp processors/object/ProcessorVideoPlay.hpp
|
||||
)
|
||||
|
||||
source_group(tes3mp-server\\processors\\object FILES ${PROCESSORS_OBJECT})
|
||||
|
|
|
@ -666,6 +666,17 @@ void ObjectFunctions::SendObjectLock(bool sendToOtherPlayers, bool skipAttachedP
|
|||
packet->Send(true);
|
||||
}
|
||||
|
||||
void ObjectFunctions::SendObjectRestock(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
|
||||
{
|
||||
mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_RESTOCK);
|
||||
packet->setObjectList(&writeObjectList);
|
||||
|
||||
if (!skipAttachedPlayer)
|
||||
packet->Send(false);
|
||||
if (sendToOtherPlayers)
|
||||
packet->Send(true);
|
||||
}
|
||||
|
||||
void ObjectFunctions::SendObjectTrap(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
|
||||
{
|
||||
mwmp::ObjectPacket *packet = mwmp::Networking::get().getObjectPacketController()->GetPacket(ID_OBJECT_TRAP);
|
||||
|
|
|
@ -137,6 +137,7 @@
|
|||
{"SendObjectSpawn", ObjectFunctions::SendObjectSpawn},\
|
||||
{"SendObjectDelete", ObjectFunctions::SendObjectDelete},\
|
||||
{"SendObjectLock", ObjectFunctions::SendObjectLock},\
|
||||
{"SendObjectRestock", ObjectFunctions::SendObjectRestock},\
|
||||
{"SendObjectTrap", ObjectFunctions::SendObjectTrap},\
|
||||
{"SendObjectScale", ObjectFunctions::SendObjectScale},\
|
||||
{"SendObjectState", ObjectFunctions::SendObjectState},\
|
||||
|
@ -1167,6 +1168,17 @@ public:
|
|||
*/
|
||||
static void SendObjectLock(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Send an ObjectRestock packet.
|
||||
*
|
||||
* \param sendToOtherPlayers Whether this packet should be sent to players other than the
|
||||
* player attached to the packet (false by default).
|
||||
* \param skipAttachedPlayer Whether the packet should skip being sent to the player attached
|
||||
* to the packet (false by default).
|
||||
* \return void
|
||||
*/
|
||||
static void SendObjectRestock(bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Send an ObjectTrap packet.
|
||||
*
|
||||
|
|
|
@ -195,6 +195,7 @@ public:
|
|||
{"OnObjectSpawn", Callback<unsigned short, const char*>()},
|
||||
{"OnObjectDelete", Callback<unsigned short, const char*>()},
|
||||
{"OnObjectLock", Callback<unsigned short, const char*>()},
|
||||
{"OnObjectRestock", Callback<unsigned short, const char*>()},
|
||||
{"OnObjectScale", Callback<unsigned short, const char*>()},
|
||||
{"OnObjectTrap", Callback<unsigned short, const char*>()},
|
||||
{"OnVideoPlay", Callback<unsigned short, const char*>()},
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include "object/ProcessorObjectPlace.hpp"
|
||||
#include "object/ProcessorObjectLock.hpp"
|
||||
#include "object/ProcessorObjectMove.hpp"
|
||||
#include "object/ProcessorObjectRestock.hpp"
|
||||
#include "object/ProcessorObjectRotate.hpp"
|
||||
#include "object/ProcessorObjectScale.hpp"
|
||||
#include "object/ProcessorObjectSpawn.hpp"
|
||||
|
@ -147,6 +148,7 @@ void ProcessorInitializer()
|
|||
ObjectProcessor::AddProcessor(new ProcessorObjectLock());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectMove());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectPlace());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectRestock());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectRotate());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectScale());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectSpawn());
|
||||
|
|
25
apps/openmw-mp/processors/object/ProcessorObjectRestock.hpp
Normal file
25
apps/openmw-mp/processors/object/ProcessorObjectRestock.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef OPENMW_PROCESSOROBJECTRESTOCK_HPP
|
||||
#define OPENMW_PROCESSOROBJECTRESTOCK_HPP
|
||||
|
||||
#include "../ObjectProcessor.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProcessorObjectRestock : public ObjectProcessor
|
||||
{
|
||||
public:
|
||||
ProcessorObjectRestock()
|
||||
{
|
||||
BPP_INIT(ID_OBJECT_RESTOCK)
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
Script::Call<Script::CallbackIdentity("OnObjectRestock")>(player.getId(), objectList.cell.getDescription().c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PROCESSOROBJECTRESTOCK_HPP
|
|
@ -131,9 +131,9 @@ add_openmw_dir (mwmp/processors/object BaseObjectProcessor
|
|||
ProcessorVideoPlay
|
||||
|
||||
ProcessorObjectActivate ProcessorObjectAnimPlay ProcessorObjectAttach ProcessorObjectCollision ProcessorObjectDelete
|
||||
ProcessorObjectHit ProcessorObjectLock ProcessorObjectMove ProcessorObjectPlace ProcessorObjectRotate
|
||||
ProcessorObjectScale ProcessorObjectSpawn ProcessorObjectState ProcessorObjectTrap ProcessorScriptLocalShort
|
||||
ProcessorScriptLocalFloat ProcessorScriptMemberShort ProcessorScriptMemberFloat
|
||||
ProcessorObjectHit ProcessorObjectLock ProcessorObjectMove ProcessorObjectPlace ProcessorObjectRestock
|
||||
ProcessorObjectRotate ProcessorObjectScale ProcessorObjectSpawn ProcessorObjectState ProcessorObjectTrap
|
||||
ProcessorScriptLocalShort ProcessorScriptLocalFloat ProcessorScriptMemberShort ProcessorScriptMemberFloat
|
||||
)
|
||||
|
||||
add_openmw_dir (mwmp/processors/worldstate ProcessorCellReset ProcessorClientScriptGlobal ProcessorClientScriptSettings
|
||||
|
|
|
@ -7,6 +7,18 @@
|
|||
|
||||
#include <components/widgets/numericeditbox.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/world.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
@ -99,14 +111,44 @@ namespace MWGui
|
|||
void TradeWindow::restock()
|
||||
{
|
||||
// Restock items on the actor inventory
|
||||
mPtr.getClass().restock(mPtr);
|
||||
/*
|
||||
Start of tes3mp change (major)
|
||||
|
||||
Don't restock here and instead send an ID_OBJECT_RESTOCK packet to the
|
||||
server requesting permission for a restock
|
||||
*/
|
||||
//mPtr.getClass().restock(mPtr);
|
||||
|
||||
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
||||
objectList->reset();
|
||||
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
|
||||
objectList->addObjectGeneric(mPtr);
|
||||
objectList->sendObjectRestock();
|
||||
/*
|
||||
End of tes3mp change (major)
|
||||
*/
|
||||
|
||||
// Also restock any containers owned by this merchant, which are also available to buy in the trade window
|
||||
std::vector<MWWorld::Ptr> itemSources;
|
||||
MWBase::Environment::get().getWorld()->getContainersOwnedBy(mPtr, itemSources);
|
||||
for (MWWorld::Ptr& source : itemSources)
|
||||
{
|
||||
source.getClass().restock(source);
|
||||
/*
|
||||
Start of tes3mp change (major)
|
||||
|
||||
Don't restock here and instead send an ID_OBJECT_RESTOCK packet to the
|
||||
server requesting permission for a restock
|
||||
*/
|
||||
//source.getClass().restock(source);
|
||||
|
||||
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
|
||||
objectList->reset();
|
||||
objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY;
|
||||
objectList->addObjectGeneric(source);
|
||||
objectList->sendObjectRestock();
|
||||
/*
|
||||
End of tes3mp change (major)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -672,6 +672,33 @@ void ObjectList::moveObjects(MWWorld::CellStore* cellStore)
|
|||
}
|
||||
}
|
||||
|
||||
void ObjectList::restockObjects(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());
|
||||
|
||||
ptrFound.getClass().restock(ptrFound);
|
||||
|
||||
reset();
|
||||
packetOrigin = mwmp::PACKET_ORIGIN::CLIENT_GAMEPLAY;
|
||||
cell = *ptrFound.getCell()->getCell();
|
||||
action = mwmp::BaseObjectList::SET;
|
||||
containerSubAction = mwmp::BaseObjectList::RESTOCK_RESULT;
|
||||
mwmp::BaseObject baseObject = getBaseObject(ptrFound);
|
||||
addEntireContainer(ptrFound);
|
||||
sendContainer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectList::rotateObjects(MWWorld::CellStore* cellStore)
|
||||
{
|
||||
for (const auto &baseObject : baseObjects)
|
||||
|
@ -1292,6 +1319,12 @@ void ObjectList::sendObjectLock()
|
|||
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_LOCK)->Send();
|
||||
}
|
||||
|
||||
void ObjectList::sendObjectRestock()
|
||||
{
|
||||
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_RESTOCK)->setObjectList(this);
|
||||
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_RESTOCK)->Send();
|
||||
}
|
||||
|
||||
void ObjectList::sendObjectTrap()
|
||||
{
|
||||
mwmp::Main::get().getNetworking()->getObjectPacket(ID_OBJECT_TRAP)->setObjectList(this);
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace mwmp
|
|||
void scaleObjects(MWWorld::CellStore* cellStore);
|
||||
void setObjectStates(MWWorld::CellStore* cellStore);
|
||||
void moveObjects(MWWorld::CellStore* cellStore);
|
||||
void restockObjects(MWWorld::CellStore* cellStore);
|
||||
void rotateObjects(MWWorld::CellStore* cellStore);
|
||||
void animateObjects(MWWorld::CellStore* cellStore);
|
||||
void activateDoors(MWWorld::CellStore* cellStore);
|
||||
|
@ -79,6 +80,7 @@ namespace mwmp
|
|||
void sendObjectSpawn();
|
||||
void sendObjectDelete();
|
||||
void sendObjectLock();
|
||||
void sendObjectRestock();
|
||||
void sendObjectTrap();
|
||||
void sendObjectScale();
|
||||
void sendObjectState();
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include "object/ProcessorObjectLock.hpp"
|
||||
#include "object/ProcessorObjectMove.hpp"
|
||||
#include "object/ProcessorObjectPlace.hpp"
|
||||
#include "object/ProcessorObjectRestock.hpp"
|
||||
#include "object/ProcessorObjectRotate.hpp"
|
||||
#include "object/ProcessorObjectScale.hpp"
|
||||
#include "object/ProcessorObjectSpawn.hpp"
|
||||
|
@ -163,6 +164,7 @@ void ProcessorInitializer()
|
|||
ObjectProcessor::AddProcessor(new ProcessorObjectLock());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectMove());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectPlace());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectRestock());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectRotate());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectScale());
|
||||
ObjectProcessor::AddProcessor(new ProcessorObjectSpawn());
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef OPENMW_PROCESSOROBJECTRESTOCK_HPP
|
||||
#define OPENMW_PROCESSOROBJECTRESTOCK_HPP
|
||||
|
||||
#include "BaseObjectProcessor.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class ProcessorObjectRestock final: public BaseObjectProcessor
|
||||
{
|
||||
public:
|
||||
ProcessorObjectRestock()
|
||||
{
|
||||
BPP_INIT(ID_OBJECT_RESTOCK)
|
||||
}
|
||||
|
||||
virtual void Do(ObjectPacket &packet, ObjectList &objectList)
|
||||
{
|
||||
BaseObjectProcessor::Do(packet, objectList);
|
||||
|
||||
objectList.restockObjects(ptrCellStore);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PROCESSOROBJECTRESTOCK_HPP
|
|
@ -206,8 +206,9 @@ add_component_dir (openmw-mp/Packets/Object
|
|||
|
||||
PacketConsoleCommand PacketContainer PacketObjectActivate PacketObjectAnimPlay PacketObjectAttach
|
||||
PacketObjectCollision PacketObjectDelete PacketObjectHit PacketObjectLock PacketObjectMove PacketObjectPlace
|
||||
PacketObjectRotate PacketObjectScale PacketObjectSpawn PacketObjectState PacketObjectTrap PacketMusicPlay
|
||||
PacketVideoPlay PacketScriptLocalShort PacketScriptLocalFloat PacketScriptMemberShort PacketScriptMemberFloat
|
||||
PacketObjectRestock PacketObjectRotate PacketObjectScale PacketObjectSpawn PacketObjectState PacketObjectTrap
|
||||
PacketMusicPlay PacketVideoPlay PacketScriptLocalShort PacketScriptLocalFloat PacketScriptMemberShort
|
||||
PacketScriptMemberFloat
|
||||
)
|
||||
|
||||
add_component_dir (openmw-mp/Packets/Worldstate
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace mwmp
|
|||
DROP = 2,
|
||||
TAKE_ALL = 3,
|
||||
REPLY_TO_REQUEST = 4,
|
||||
RESTOCK = 5
|
||||
RESTOCK_RESULT = 5
|
||||
};
|
||||
|
||||
RakNet::RakNetGUID guid;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "../Packets/Object/PacketObjectLock.hpp"
|
||||
#include "../Packets/Object/PacketObjectMove.hpp"
|
||||
#include "../Packets/Object/PacketObjectPlace.hpp"
|
||||
#include "../Packets/Object/PacketObjectRestock.hpp"
|
||||
#include "../Packets/Object/PacketObjectRotate.hpp"
|
||||
#include "../Packets/Object/PacketObjectScale.hpp"
|
||||
#include "../Packets/Object/PacketObjectSpawn.hpp"
|
||||
|
@ -46,6 +47,7 @@ mwmp::ObjectPacketController::ObjectPacketController(RakNet::RakPeerInterface *p
|
|||
AddPacket<PacketObjectLock>(&packets, peer);
|
||||
AddPacket<PacketObjectMove>(&packets, peer);
|
||||
AddPacket<PacketObjectPlace>(&packets, peer);
|
||||
AddPacket<PacketObjectRestock>(&packets, peer);
|
||||
AddPacket<PacketObjectRotate>(&packets, peer);
|
||||
AddPacket<PacketObjectScale>(&packets, peer);
|
||||
AddPacket<PacketObjectSpawn>(&packets, peer);
|
||||
|
|
|
@ -94,7 +94,7 @@ enum GameMessages
|
|||
ID_SCRIPT_MEMBER_SHORT,
|
||||
ID_SCRIPT_MEMBER_FLOAT,
|
||||
ID_CLIENT_SCRIPT_GLOBAL,
|
||||
ID_SCRIPT_GLOBAL_FLOAT,
|
||||
ID_OBJECT_RESTOCK,
|
||||
|
||||
ID_GAME_SETTINGS,
|
||||
ID_GAME_PREINIT,
|
||||
|
|
10
components/openmw-mp/Packets/Object/PacketObjectRestock.cpp
Normal file
10
components/openmw-mp/Packets/Object/PacketObjectRestock.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include "PacketObjectRestock.hpp"
|
||||
|
||||
using namespace mwmp;
|
||||
|
||||
PacketObjectRestock::PacketObjectRestock(RakNet::RakPeerInterface *peer) : ObjectPacket(peer)
|
||||
{
|
||||
packetID = ID_OBJECT_RESTOCK;
|
||||
hasCellData = true;
|
||||
}
|
15
components/openmw-mp/Packets/Object/PacketObjectRestock.hpp
Normal file
15
components/openmw-mp/Packets/Object/PacketObjectRestock.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef OPENMW_PACKETOBJECTRESTOCK_HPP
|
||||
#define OPENMW_PACKETOBJECTRESTOCK_HPP
|
||||
|
||||
#include <components/openmw-mp/Packets/Object/ObjectPacket.hpp>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class PacketObjectRestock : public ObjectPacket
|
||||
{
|
||||
public:
|
||||
PacketObjectRestock(RakNet::RakPeerInterface *peer);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PACKETOBJECTRESTOCK_HPP
|
Loading…
Reference in a new issue