[Client] Simplify sending of world packets by adding WorldEvent methods

0.6.1
David Cernat 8 years ago
parent 1d23a48a42
commit 4abe295a80

@ -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
*/

@ -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

@ -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
*/

@ -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;

@ -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);

@ -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
*/

@ -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
*/

@ -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

Loading…
Cancel
Save