diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 3e28b66a0..b353bc8be 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -65,32 +65,7 @@ namespace MWGui the inventory screen */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *dropped.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = dropped.getCellRef().getRefId(); - worldObject.refNumIndex = dropped.getCellRef().getRefNum().mIndex; - worldObject.mpNum = 0; - worldObject.charge = dropped.getCellRef().getCharge(); - - // Make sure we send the RefData position instead of the CellRef one, because that's what - // we actually see on this client - worldObject.pos = dropped.getRefData().getPosition(); - - // We have to get the count from the dropped object because it gets changed - // automatically for stacks of gold - worldObject.count = dropped.getRefData().getCount(); - - // Get the real count of gold in a stack - worldObject.goldValue = dropped.getCellRef().getGoldValue(); - - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i", - worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.count); + worldEvent->sendObjectPlace(dropped); /* End of tes3mp addition */ diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index bbbc0ee26..0b9ffa95d 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -645,16 +645,7 @@ namespace MWGui by the player */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *object.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = object.getCellRef().getRefId(); - worldObject.refNumIndex = object.getCellRef().getRefNum().mIndex; - worldObject.mpNum = object.getCellRef().getMpNum(); - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(); + worldEvent->sendObjectDelete(object); mwmp::Main::get().getLocalPlayer()->sendInventory(); /* End of tes3mp addition diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 808109907..6d0048c47 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -64,16 +64,7 @@ namespace MWMechanics Send an ID_OBJECT_UNLOCK packet every time an object is unlocked */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *lock.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = lock.getCellRef().getRefId(); - worldObject.refNumIndex = lock.getCellRef().getRefNum().mIndex; - worldObject.mpNum = lock.getCellRef().getMpNum(); - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(); + worldEvent->sendObjectUnlock(lock); /* End of tes3mp addition */ diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index a7f24d40f..762eca3f2 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -119,6 +119,95 @@ void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) mwmp::Main::get().getNetworking()->getWorldPacket(ID_CONTAINER)->Send(); } + +void WorldEvent::sendObjectPlace(MWWorld::Ptr ptr) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = 0; + worldObject.charge = ptr.getCellRef().getCharge(); + + // Make sure we send the RefData position instead of the CellRef one, because that's what + // we actually see on this client + worldObject.pos = ptr.getRefData().getPosition(); + + // We have to get the count from the dropped object because it gets changed + // automatically for stacks of gold + worldObject.count = ptr.getRefData().getCount(); + + // Get the real count of gold in a stack + worldObject.goldValue = ptr.getCellRef().getGoldValue(); + + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(); + + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i", + worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.count); +} + +void WorldEvent::sendObjectDelete(MWWorld::Ptr ptr) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(); +} + +void WorldEvent::sendObjectLock(MWWorld::Ptr ptr, int lockLevel) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.lockLevel = lockLevel; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->Send(); +} + +void WorldEvent::sendObjectUnlock(MWWorld::Ptr ptr) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(); +} + +void WorldEvent::sendObjectScale(MWWorld::Ptr ptr, int scale) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.scale = scale; + addObject(worldObject); + + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send(); +} + void WorldEvent::editContainers(MWWorld::CellStore* cellStore) { WorldObject worldObject; diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index 0195689cd..4ee53cc49 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -19,8 +19,14 @@ namespace mwmp void sendActors(MWWorld::CellStore* cellStore); void sendContainers(MWWorld::CellStore* cellStore); + void sendObjectPlace(MWWorld::Ptr ptr); + void sendObjectDelete(MWWorld::Ptr ptr); + void sendObjectLock(MWWorld::Ptr ptr, int lockLevel); + void sendObjectUnlock(MWWorld::Ptr ptr); + void sendObjectScale(MWWorld::Ptr ptr, int scale); void editContainers(MWWorld::CellStore* cellStore); + void placeObjects(MWWorld::CellStore* cellStore); void deleteObjects(MWWorld::CellStore* cellStore); void lockObjects(MWWorld::CellStore* cellStore); diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 9446d7aa4..604bc023c 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -213,17 +213,7 @@ namespace MWScript through a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *ptr.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = ptr.getCellRef().getRefId(); - worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; - worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldObject.lockLevel = lockLevel; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->Send(); + worldEvent->sendObjectLock(ptr, lockLevel); /* End of tes3mp addition */ @@ -261,16 +251,7 @@ namespace MWScript through a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *ptr.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = ptr.getCellRef().getRefId(); - worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; - worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_UNLOCK)->Send(); + worldEvent->sendObjectUnlock(ptr); /* End of tes3mp addition */ @@ -742,16 +723,7 @@ namespace MWScript through a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *ptr.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = ptr.getCellRef().getRefId(); - worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; - worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(); + worldEvent->sendObjectDelete(ptr); /* End of tes3mp addition */ diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index f54bbeaef..dd49883df 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -53,17 +53,7 @@ namespace MWScript through a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *ptr.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = ptr.getCellRef().getRefId(); - worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; - worldObject.mpNum = ptr.getCellRef().getMpNum(); - worldObject.scale = scale; - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->Send(); + worldEvent->sendObjectScale(ptr, scale); /* End of tes3mp addition */ @@ -558,26 +548,7 @@ namespace MWScript through a script */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *ptr.getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = ptr.getCellRef().getRefId(); - worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; - worldObject.mpNum = 0; - worldObject.charge = ptr.getCellRef().getCharge(); - worldObject.count = 1; - - // Make sure we send the RefData position instead of the CellRef one, because that's what - // we actually see on this client - worldObject.pos = ptr.getRefData().getPosition(); - - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_PLACE)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_PLACE\n- cellRef: %s, %i\n- count: %i", - worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.count); + worldEvent->sendObjectPlace(ptr); /* End of tes3mp addition */ diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index 845d1a363..3be492c89 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -35,20 +35,7 @@ namespace MWWorld by the player */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent(); - worldEvent->cell = *getTarget().getCell()->getCell(); - - mwmp::WorldObject worldObject; - worldObject.refId = getTarget().getCellRef().getRefId(); - worldObject.refNumIndex = getTarget().getCellRef().getRefNum().mIndex; - worldObject.mpNum = getTarget().getCellRef().getMpNum(); - worldEvent->addObject(worldObject); - - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->setEvent(worldEvent); - mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_DELETE)->Send(); - - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Sending ID_OBJECT_DELETE about\n- cellRef: %s, %i\n- cell: %s", - worldObject.refId.c_str(), worldObject.refNumIndex, worldEvent->cell.getDescription().c_str()); - + worldEvent->sendObjectDelete(getTarget()); mwmp::Main::get().getLocalPlayer()->sendInventory(); /* End of tes3mp addition