[General] Generate mpNums on the server when forwarding ID_OBJECT_PLACE

0.6.1
David Cernat 8 years ago
parent 31cd836558
commit 8cc61b6048

@ -27,6 +27,8 @@ using namespace std;
Networking *Networking::sThis = 0;
static int currentMpNum = 0;
Networking::Networking(RakNet::RakPeerInterface *peer)
{
sThis = this;
@ -288,6 +290,22 @@ BaseEvent *Networking::getLastEvent()
return &baseEvent;
}
int Networking::getCurrentMpNum()
{
return currentMpNum;
}
void Networking::setCurrentMpNum(int value)
{
currentMpNum = value;
}
int Networking::getNextMpNum()
{
currentMpNum++;
return currentMpNum;
}
const Networking &Networking::get()
{
return *sThis;

@ -38,6 +38,10 @@ namespace mwmp
WorldPacketController *getWorldController() const;
BaseEvent *getLastEvent();
int getCurrentMpNum();
void setCurrentMpNum(int value);
int getNextMpNum();
MasterClient *getMasterClient();
void InitQuery(std::string queryAddr, unsigned short queryPort, std::string serverAddr, unsigned short serverPort);
void setServerPassword(std::string passw) noexcept;

@ -6,6 +6,7 @@
#define OPENMW_PROCESSOROBJECTPLACE_HPP
#include "apps/openmw-mp/WorldProcessor.hpp"
#include <apps/openmw-mp/Networking.hpp>
namespace mwmp
{
@ -19,6 +20,11 @@ namespace mwmp
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);
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);
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i\n- charge: %i\n- count: %i", worldObject.refId.c_str(),
worldObject.refNumIndex, worldObject.charge, worldObject.count);
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i\n- charge: %i\n- count: %i", worldObject.refId.c_str(),
worldObject.refNumIndex, worldObject.mpNum, worldObject.charge, worldObject.count);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1);
MWWorld::Ptr newPtr = ref.getPtr();
@ -174,6 +174,8 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore)
if (worldObject.count > 1)
newPtr.getRefData().setCount(worldObject.count);
newPtr.getCellRef().setMpNum(worldObject.mpNum);
newPtr.getCellRef().setGoldValue(worldObject.goldValue);
newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, cellStore, worldObject.pos);
}

@ -31,6 +31,7 @@ namespace mwmp
{
std::string refId;
int refNumIndex;
int mpNum;
int count;
int charge;
int goldValue;

@ -35,6 +35,7 @@ void PacketObjectPlace::Packet(RakNet::BitStream *bs, bool send)
RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send);
RW(worldObject.count, send);
RW(worldObject.charge, send);
RW(worldObject.goldValue, send);

Loading…
Cancel
Save