mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
[General] Implement ObjectState packet
This commit is contained in:
parent
083b46394d
commit
be93ec8ef6
10 changed files with 111 additions and 1 deletions
|
@ -79,6 +79,11 @@ double WorldFunctions::GetObjectScale(unsigned int i) noexcept
|
||||||
return readEvent->worldObjects.at(i).scale;
|
return readEvent->worldObjects.at(i).scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WorldFunctions::GetObjectState(unsigned int i) noexcept
|
||||||
|
{
|
||||||
|
return readEvent->worldObjects.at(i).objectState;
|
||||||
|
}
|
||||||
|
|
||||||
int WorldFunctions::GetObjectDoorState(unsigned int i) noexcept
|
int WorldFunctions::GetObjectDoorState(unsigned int i) noexcept
|
||||||
{
|
{
|
||||||
return readEvent->worldObjects.at(i).doorState;
|
return readEvent->worldObjects.at(i).doorState;
|
||||||
|
@ -193,6 +198,11 @@ void WorldFunctions::SetObjectScale(double scale) noexcept
|
||||||
tempWorldObject.scale = scale;
|
tempWorldObject.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldFunctions::SetObjectState(bool objectState) noexcept
|
||||||
|
{
|
||||||
|
tempWorldObject.objectState = objectState;
|
||||||
|
}
|
||||||
|
|
||||||
void WorldFunctions::SetObjectDoorState(int doorState) noexcept
|
void WorldFunctions::SetObjectDoorState(int doorState) noexcept
|
||||||
{
|
{
|
||||||
tempWorldObject.doorState = doorState;
|
tempWorldObject.doorState = doorState;
|
||||||
|
@ -292,6 +302,12 @@ void WorldFunctions::SendObjectScale() noexcept
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->Send(writeEvent.guid);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_SCALE)->Send(writeEvent.guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldFunctions::SendObjectState() noexcept
|
||||||
|
{
|
||||||
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_STATE)->setEvent(&writeEvent);
|
||||||
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_OBJECT_STATE)->Send(writeEvent.guid);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldFunctions::SendDoorState() noexcept
|
void WorldFunctions::SendDoorState() noexcept
|
||||||
{
|
{
|
||||||
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->setEvent(&writeEvent);
|
mwmp::Networking::get().getWorldPacketController()->GetPacket(ID_DOOR_STATE)->setEvent(&writeEvent);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
{"GetObjectCharge", WorldFunctions::GetObjectCharge},\
|
{"GetObjectCharge", WorldFunctions::GetObjectCharge},\
|
||||||
{"GetObjectGoldValue", WorldFunctions::GetObjectGoldValue},\
|
{"GetObjectGoldValue", WorldFunctions::GetObjectGoldValue},\
|
||||||
{"GetObjectScale", WorldFunctions::GetObjectScale},\
|
{"GetObjectScale", WorldFunctions::GetObjectScale},\
|
||||||
|
{"GetObjectState", WorldFunctions::GetObjectState},\
|
||||||
{"GetObjectDoorState", WorldFunctions::GetObjectDoorState},\
|
{"GetObjectDoorState", WorldFunctions::GetObjectDoorState},\
|
||||||
{"GetObjectLockLevel", WorldFunctions::GetObjectLockLevel},\
|
{"GetObjectLockLevel", WorldFunctions::GetObjectLockLevel},\
|
||||||
{"GetObjectPosX", WorldFunctions::GetObjectPosX},\
|
{"GetObjectPosX", WorldFunctions::GetObjectPosX},\
|
||||||
|
@ -40,6 +41,7 @@
|
||||||
{"SetObjectCharge", WorldFunctions::SetObjectCharge},\
|
{"SetObjectCharge", WorldFunctions::SetObjectCharge},\
|
||||||
{"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\
|
{"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\
|
||||||
{"SetObjectScale", WorldFunctions::SetObjectScale},\
|
{"SetObjectScale", WorldFunctions::SetObjectScale},\
|
||||||
|
{"SetObjectState", WorldFunctions::SetObjectState},\
|
||||||
{"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\
|
{"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\
|
||||||
{"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\
|
{"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\
|
||||||
{"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\
|
{"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\
|
||||||
|
@ -60,6 +62,7 @@
|
||||||
{"SendObjectLock", WorldFunctions::SendObjectLock},\
|
{"SendObjectLock", WorldFunctions::SendObjectLock},\
|
||||||
{"SendObjectTrap", WorldFunctions::SendObjectTrap},\
|
{"SendObjectTrap", WorldFunctions::SendObjectTrap},\
|
||||||
{"SendObjectScale", WorldFunctions::SendObjectScale},\
|
{"SendObjectScale", WorldFunctions::SendObjectScale},\
|
||||||
|
{"SendObjectState", WorldFunctions::SendObjectState},\
|
||||||
{"SendDoorState", WorldFunctions::SendDoorState},\
|
{"SendDoorState", WorldFunctions::SendDoorState},\
|
||||||
{"SendContainer", WorldFunctions::SendContainer},\
|
{"SendContainer", WorldFunctions::SendContainer},\
|
||||||
\
|
\
|
||||||
|
@ -84,6 +87,7 @@ public:
|
||||||
static int GetObjectCharge(unsigned int i) noexcept;
|
static int GetObjectCharge(unsigned int i) noexcept;
|
||||||
static int GetObjectGoldValue(unsigned int i) noexcept;
|
static int GetObjectGoldValue(unsigned int i) noexcept;
|
||||||
static double GetObjectScale(unsigned int i) noexcept;
|
static double GetObjectScale(unsigned int i) noexcept;
|
||||||
|
static bool GetObjectState(unsigned int i) noexcept;
|
||||||
static int GetObjectDoorState(unsigned int i) noexcept;
|
static int GetObjectDoorState(unsigned int i) noexcept;
|
||||||
static int GetObjectLockLevel(unsigned int i) noexcept;
|
static int GetObjectLockLevel(unsigned int i) noexcept;
|
||||||
static double GetObjectPosX(unsigned int i) noexcept;
|
static double GetObjectPosX(unsigned int i) noexcept;
|
||||||
|
@ -109,6 +113,7 @@ public:
|
||||||
static void SetObjectCharge(int charge) noexcept;
|
static void SetObjectCharge(int charge) noexcept;
|
||||||
static void SetObjectGoldValue(int goldValue) noexcept;
|
static void SetObjectGoldValue(int goldValue) noexcept;
|
||||||
static void SetObjectScale(double scale) noexcept;
|
static void SetObjectScale(double scale) noexcept;
|
||||||
|
static void SetObjectState(bool objectState) noexcept;
|
||||||
static void SetObjectDoorState(int doorState) noexcept;
|
static void SetObjectDoorState(int doorState) noexcept;
|
||||||
static void SetObjectLockLevel(int lockLevel) noexcept;
|
static void SetObjectLockLevel(int lockLevel) noexcept;
|
||||||
static void SetObjectDisarmState(bool disarmState) noexcept;
|
static void SetObjectDisarmState(bool disarmState) noexcept;
|
||||||
|
@ -129,6 +134,7 @@ public:
|
||||||
static void SendObjectLock() noexcept;
|
static void SendObjectLock() noexcept;
|
||||||
static void SendObjectTrap() noexcept;
|
static void SendObjectTrap() noexcept;
|
||||||
static void SendObjectScale() noexcept;
|
static void SendObjectScale() noexcept;
|
||||||
|
static void SendObjectState() noexcept;
|
||||||
static void SendDoorState() noexcept;
|
static void SendDoorState() noexcept;
|
||||||
static void SendContainer() noexcept;
|
static void SendContainer() noexcept;
|
||||||
|
|
||||||
|
|
|
@ -333,6 +333,28 @@ void WorldEvent::scaleObjects(MWWorld::CellStore* cellStore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldEvent::setObjectStates(MWWorld::CellStore* cellStore)
|
||||||
|
{
|
||||||
|
for (const auto &worldObject : worldObjects)
|
||||||
|
{
|
||||||
|
LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i, state: %s", worldObject.refId.c_str(), worldObject.refNumIndex,
|
||||||
|
worldObject.mpNum, worldObject.objectState ? "true" : "false");
|
||||||
|
|
||||||
|
MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refNumIndex, worldObject.mpNum);
|
||||||
|
|
||||||
|
if (ptrFound)
|
||||||
|
{
|
||||||
|
LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
|
||||||
|
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum());
|
||||||
|
|
||||||
|
if (worldObject.objectState)
|
||||||
|
MWBase::Environment::get().getWorld()->enable(ptrFound);
|
||||||
|
else
|
||||||
|
MWBase::Environment::get().getWorld()->disable(ptrFound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WorldEvent::moveObjects(MWWorld::CellStore* cellStore)
|
void WorldEvent::moveObjects(MWWorld::CellStore* cellStore)
|
||||||
{
|
{
|
||||||
for (const auto &worldObject : worldObjects)
|
for (const auto &worldObject : worldObjects)
|
||||||
|
@ -630,6 +652,18 @@ void WorldEvent::addObjectScale(const MWWorld::Ptr& ptr, float scale)
|
||||||
addObject(worldObject);
|
addObject(worldObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldEvent::addObjectState(const MWWorld::Ptr& ptr, bool objectState)
|
||||||
|
{
|
||||||
|
cell = *ptr.getCell()->getCell();
|
||||||
|
|
||||||
|
mwmp::WorldObject worldObject;
|
||||||
|
worldObject.refId = ptr.getCellRef().getRefId();
|
||||||
|
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
|
||||||
|
worldObject.mpNum = ptr.getCellRef().getMpNum();
|
||||||
|
worldObject.objectState = objectState;
|
||||||
|
addObject(worldObject);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldEvent::addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode)
|
void WorldEvent::addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode)
|
||||||
{
|
{
|
||||||
cell = *ptr.getCell()->getCell();
|
cell = *ptr.getCell()->getCell();
|
||||||
|
@ -759,6 +793,12 @@ void WorldEvent::sendObjectScale()
|
||||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send();
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldEvent::sendObjectState()
|
||||||
|
{
|
||||||
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_STATE)->setEvent(this);
|
||||||
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_STATE)->Send();
|
||||||
|
}
|
||||||
|
|
||||||
void WorldEvent::sendObjectAnimPlay()
|
void WorldEvent::sendObjectAnimPlay()
|
||||||
{
|
{
|
||||||
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->setEvent(this);
|
mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_ANIM_PLAY)->setEvent(this);
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace mwmp
|
||||||
void lockObjects(MWWorld::CellStore* cellStore);
|
void lockObjects(MWWorld::CellStore* cellStore);
|
||||||
void triggerTrapObjects(MWWorld::CellStore* cellStore);
|
void triggerTrapObjects(MWWorld::CellStore* cellStore);
|
||||||
void scaleObjects(MWWorld::CellStore* cellStore);
|
void scaleObjects(MWWorld::CellStore* cellStore);
|
||||||
|
void setObjectStates(MWWorld::CellStore* cellStore);
|
||||||
void moveObjects(MWWorld::CellStore* cellStore);
|
void moveObjects(MWWorld::CellStore* cellStore);
|
||||||
void rotateObjects(MWWorld::CellStore* cellStore);
|
void rotateObjects(MWWorld::CellStore* cellStore);
|
||||||
void animateObjects(MWWorld::CellStore* cellStore);
|
void animateObjects(MWWorld::CellStore* cellStore);
|
||||||
|
@ -46,6 +47,7 @@ namespace mwmp
|
||||||
void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel);
|
void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel);
|
||||||
void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed);
|
void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed);
|
||||||
void addObjectScale(const MWWorld::Ptr& ptr, float scale);
|
void addObjectScale(const MWWorld::Ptr& ptr, float scale);
|
||||||
|
void addObjectState(const MWWorld::Ptr& ptr, bool objectState);
|
||||||
void addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode);
|
void addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode);
|
||||||
void addDoorState(const MWWorld::Ptr& ptr, int state);
|
void addDoorState(const MWWorld::Ptr& ptr, int state);
|
||||||
void addMusicPlay(std::string filename);
|
void addMusicPlay(std::string filename);
|
||||||
|
@ -61,6 +63,7 @@ namespace mwmp
|
||||||
void sendObjectLock();
|
void sendObjectLock();
|
||||||
void sendObjectTrap();
|
void sendObjectTrap();
|
||||||
void sendObjectScale();
|
void sendObjectScale();
|
||||||
|
void sendObjectState();
|
||||||
void sendObjectAnimPlay();
|
void sendObjectAnimPlay();
|
||||||
void sendDoorState();
|
void sendDoorState();
|
||||||
void sendMusicPlay();
|
void sendMusicPlay();
|
||||||
|
|
|
@ -132,6 +132,7 @@ void ProcessorInitializer()
|
||||||
WorldProcessor::AddProcessor(new ProcessorObjectRotate());
|
WorldProcessor::AddProcessor(new ProcessorObjectRotate());
|
||||||
WorldProcessor::AddProcessor(new ProcessorObjectScale());
|
WorldProcessor::AddProcessor(new ProcessorObjectScale());
|
||||||
WorldProcessor::AddProcessor(new ProcessorObjectSpawn());
|
WorldProcessor::AddProcessor(new ProcessorObjectSpawn());
|
||||||
|
WorldProcessor::AddProcessor(new ProcessorObjectState());
|
||||||
WorldProcessor::AddProcessor(new ProcessorObjectTrap());
|
WorldProcessor::AddProcessor(new ProcessorObjectTrap());
|
||||||
WorldProcessor::AddProcessor(new ProcessorScriptLocalShort());
|
WorldProcessor::AddProcessor(new ProcessorScriptLocalShort());
|
||||||
WorldProcessor::AddProcessor(new ProcessorScriptLocalFloat());
|
WorldProcessor::AddProcessor(new ProcessorScriptLocalFloat());
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
BaseObjectProcessor::Do(packet, event);
|
BaseObjectProcessor::Do(packet, event);
|
||||||
|
|
||||||
//event.setObjectStates(ptrCellStore);
|
event.setObjectStates(ptrCellStore);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <components/openmw-mp/Log.hpp>
|
#include <components/openmw-mp/Log.hpp>
|
||||||
#include "../mwmp/Main.hpp"
|
#include "../mwmp/Main.hpp"
|
||||||
#include "../mwmp/Networking.hpp"
|
#include "../mwmp/Networking.hpp"
|
||||||
|
#include "../mwmp/LocalPlayer.hpp"
|
||||||
#include "../mwmp/WorldEvent.hpp"
|
#include "../mwmp/WorldEvent.hpp"
|
||||||
/*
|
/*
|
||||||
End of tes3mp addition
|
End of tes3mp addition
|
||||||
|
@ -582,12 +583,46 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ref = getReferenceImp (id, false);
|
MWWorld::Ptr ref = getReferenceImp (id, false);
|
||||||
MWBase::Environment::get().getWorld()->enable (ref);
|
MWBase::Environment::get().getWorld()->enable (ref);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Send an ID_OBJECT_STATE packet whenever an object is enabled, as long as
|
||||||
|
the player has finished character generation
|
||||||
|
*/
|
||||||
|
if (mwmp::Main::get().getLocalPlayer()->hasFinishedCharGen())
|
||||||
|
{
|
||||||
|
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||||
|
worldEvent->reset();
|
||||||
|
worldEvent->addObjectState(ref, true);
|
||||||
|
worldEvent->sendObjectState();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpreterContext::disable (const std::string& id)
|
void InterpreterContext::disable (const std::string& id)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ref = getReferenceImp (id, false);
|
MWWorld::Ptr ref = getReferenceImp (id, false);
|
||||||
MWBase::Environment::get().getWorld()->disable (ref);
|
MWBase::Environment::get().getWorld()->disable (ref);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Start of tes3mp addition
|
||||||
|
|
||||||
|
Send an ID_OBJECT_STATE packet whenever an object is disabled, as long as
|
||||||
|
the player has finished character generation
|
||||||
|
*/
|
||||||
|
if (mwmp::Main::get().getLocalPlayer()->hasFinishedCharGen())
|
||||||
|
{
|
||||||
|
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||||
|
worldEvent->reset();
|
||||||
|
worldEvent->addObjectState(ref, false);
|
||||||
|
worldEvent->sendObjectState();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
End of tes3mp addition
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int InterpreterContext::getMemberShort (const std::string& id, const std::string& name,
|
int InterpreterContext::getMemberShort (const std::string& id, const std::string& name,
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace mwmp
|
||||||
|
|
||||||
ESM::Position position;
|
ESM::Position position;
|
||||||
|
|
||||||
|
bool objectState;
|
||||||
int doorState;
|
int doorState;
|
||||||
int lockLevel;
|
int lockLevel;
|
||||||
float scale;
|
float scale;
|
||||||
|
|
|
@ -8,3 +8,9 @@ PacketObjectState::PacketObjectState(RakNet::RakPeerInterface *peer) : WorldPack
|
||||||
packetID = ID_OBJECT_STATE;
|
packetID = ID_OBJECT_STATE;
|
||||||
hasCellData = true;
|
hasCellData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PacketObjectState::Object(WorldObject &worldObject, bool send)
|
||||||
|
{
|
||||||
|
WorldPacket::Object(worldObject, send);
|
||||||
|
RW(worldObject.objectState, send);
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PacketObjectState(RakNet::RakPeerInterface *peer);
|
PacketObjectState(RakNet::RakPeerInterface *peer);
|
||||||
|
|
||||||
|
virtual void Object(WorldObject &worldObject, bool send);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue