forked from teamnwah/openmw-tes3coop
[General] Generate mpNums on the server when forwarding ID_OBJECT_PLACE
This commit is contained in:
parent
31cd836558
commit
8cc61b6048
6 changed files with 34 additions and 2 deletions
|
@ -27,6 +27,8 @@ using namespace std;
|
||||||
|
|
||||||
Networking *Networking::sThis = 0;
|
Networking *Networking::sThis = 0;
|
||||||
|
|
||||||
|
static int currentMpNum = 0;
|
||||||
|
|
||||||
Networking::Networking(RakNet::RakPeerInterface *peer)
|
Networking::Networking(RakNet::RakPeerInterface *peer)
|
||||||
{
|
{
|
||||||
sThis = this;
|
sThis = this;
|
||||||
|
@ -288,6 +290,22 @@ BaseEvent *Networking::getLastEvent()
|
||||||
return &baseEvent;
|
return &baseEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Networking::getCurrentMpNum()
|
||||||
|
{
|
||||||
|
return currentMpNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Networking::setCurrentMpNum(int value)
|
||||||
|
{
|
||||||
|
currentMpNum = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Networking::getNextMpNum()
|
||||||
|
{
|
||||||
|
currentMpNum++;
|
||||||
|
return currentMpNum;
|
||||||
|
}
|
||||||
|
|
||||||
const Networking &Networking::get()
|
const Networking &Networking::get()
|
||||||
{
|
{
|
||||||
return *sThis;
|
return *sThis;
|
||||||
|
|
|
@ -38,6 +38,10 @@ namespace mwmp
|
||||||
WorldPacketController *getWorldController() const;
|
WorldPacketController *getWorldController() const;
|
||||||
BaseEvent *getLastEvent();
|
BaseEvent *getLastEvent();
|
||||||
|
|
||||||
|
int getCurrentMpNum();
|
||||||
|
void setCurrentMpNum(int value);
|
||||||
|
int getNextMpNum();
|
||||||
|
|
||||||
MasterClient *getMasterClient();
|
MasterClient *getMasterClient();
|
||||||
void InitQuery(std::string queryAddr, unsigned short queryPort, std::string serverAddr, unsigned short serverPort);
|
void InitQuery(std::string queryAddr, unsigned short queryPort, std::string serverAddr, unsigned short serverPort);
|
||||||
void setServerPassword(std::string passw) noexcept;
|
void setServerPassword(std::string passw) noexcept;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define OPENMW_PROCESSOROBJECTPLACE_HPP
|
#define OPENMW_PROCESSOROBJECTPLACE_HPP
|
||||||
|
|
||||||
#include "apps/openmw-mp/WorldProcessor.hpp"
|
#include "apps/openmw-mp/WorldProcessor.hpp"
|
||||||
|
#include <apps/openmw-mp/Networking.hpp>
|
||||||
|
|
||||||
namespace mwmp
|
namespace mwmp
|
||||||
{
|
{
|
||||||
|
@ -19,6 +20,11 @@ namespace mwmp
|
||||||
|
|
||||||
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
|
void Do(WorldPacket &packet, Player &player, BaseEvent &event) override
|
||||||
{
|
{
|
||||||
|
for (unsigned int i = 0; i < event.objectChanges.count; i++)
|
||||||
|
{
|
||||||
|
event.objectChanges.objects.at(i).mpNum = mwmp::Networking::getPtr()->getNextMpNum();
|
||||||
|
}
|
||||||
|
|
||||||
packet.Send(true);
|
packet.Send(true);
|
||||||
|
|
||||||
Script::Call<Script::CallbackIdentity("OnObjectPlace")>(player.getId(), event.cell.getDescription().c_str());
|
Script::Call<Script::CallbackIdentity("OnObjectPlace")>(player.getId(), event.cell.getDescription().c_str());
|
||||||
|
|
|
@ -162,8 +162,8 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore)
|
||||||
{
|
{
|
||||||
worldObject = objectChanges.objects.at(i);
|
worldObject = objectChanges.objects.at(i);
|
||||||
|
|
||||||
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i\n- charge: %i\n- count: %i", worldObject.refId.c_str(),
|
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i\n- charge: %i\n- count: %i", worldObject.refId.c_str(),
|
||||||
worldObject.refNumIndex, worldObject.charge, worldObject.count);
|
worldObject.refNumIndex, worldObject.mpNum, worldObject.charge, worldObject.count);
|
||||||
|
|
||||||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1);
|
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1);
|
||||||
MWWorld::Ptr newPtr = ref.getPtr();
|
MWWorld::Ptr newPtr = ref.getPtr();
|
||||||
|
@ -174,6 +174,8 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore)
|
||||||
if (worldObject.count > 1)
|
if (worldObject.count > 1)
|
||||||
newPtr.getRefData().setCount(worldObject.count);
|
newPtr.getRefData().setCount(worldObject.count);
|
||||||
|
|
||||||
|
newPtr.getCellRef().setMpNum(worldObject.mpNum);
|
||||||
|
|
||||||
newPtr.getCellRef().setGoldValue(worldObject.goldValue);
|
newPtr.getCellRef().setGoldValue(worldObject.goldValue);
|
||||||
newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, cellStore, worldObject.pos);
|
newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, cellStore, worldObject.pos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
std::string refId;
|
std::string refId;
|
||||||
int refNumIndex;
|
int refNumIndex;
|
||||||
|
int mpNum;
|
||||||
int count;
|
int count;
|
||||||
int charge;
|
int charge;
|
||||||
int goldValue;
|
int goldValue;
|
||||||
|
|
|
@ -35,6 +35,7 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, bool send)
|
||||||
|
|
||||||
RW(worldObject.refId, send);
|
RW(worldObject.refId, send);
|
||||||
RW(worldObject.refNumIndex, send);
|
RW(worldObject.refNumIndex, send);
|
||||||
|
RW(worldObject.mpNum, send);
|
||||||
RW(worldObject.count, send);
|
RW(worldObject.count, send);
|
||||||
RW(worldObject.charge, send);
|
RW(worldObject.charge, send);
|
||||||
RW(worldObject.goldValue, send);
|
RW(worldObject.goldValue, send);
|
||||||
|
|
Loading…
Reference in a new issue