From c01ab632391aaaf606d5f0d863bc025b5580ba5d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 17 Feb 2017 23:11:38 +0200 Subject: [PATCH] [Server] Add script functions for setting container item info --- apps/openmw-mp/Script/Functions/World.cpp | 73 ++++++++++++++++------- apps/openmw-mp/Script/Functions/World.hpp | 22 +++++-- 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index 4197f8a57..3d07dd041 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -11,6 +11,7 @@ using namespace mwmp; static BaseEvent *baseEvent = nullptr; static WorldObject tempWorldObject; +static ContainerItem tempContainerItem; std::regex exteriorCellPattern("^(-?\\d+), (-?\\d+)$"); @@ -143,22 +144,6 @@ const char *WorldFunctions::GetContainerItemOwner(unsigned int objectIndex, unsi .containerChanges.items.at(itemIndex).owner.c_str(); } -void WorldFunctions::AddWorldObject() noexcept -{ - WorldObject worldObject; - worldObject.refId = tempWorldObject.refId; - worldObject.refNumIndex = tempWorldObject.refNumIndex; - worldObject.charge = tempWorldObject.charge; - worldObject.count = tempWorldObject.count; - worldObject.goldValue = tempWorldObject.goldValue; - worldObject.scale = tempWorldObject.scale; - worldObject.doorState = tempWorldObject.doorState; - worldObject.lockLevel = tempWorldObject.lockLevel; - worldObject.pos = tempWorldObject.pos; - - baseEvent->objectChanges.objects.push_back(worldObject); -} - void WorldFunctions::SetBaseEventCell(const char* cellDescription) noexcept { std::string description = cellDescription; @@ -197,14 +182,14 @@ void WorldFunctions::SetObjectRefNumIndex(int refNumIndex) noexcept tempWorldObject.refNumIndex = refNumIndex; } -void WorldFunctions::SetObjectCharge(int charge) noexcept +void WorldFunctions::SetObjectCount(int count) noexcept { - tempWorldObject.charge = charge; + tempWorldObject.count = count; } -void WorldFunctions::SetObjectCount(int count) noexcept +void WorldFunctions::SetObjectCharge(int charge) noexcept { - tempWorldObject.count = count; + tempWorldObject.charge = charge; } void WorldFunctions::SetObjectGoldValue(int goldValue) noexcept @@ -241,9 +226,48 @@ void WorldFunctions::SetObjectRotation(double x, double y, double z) noexcept tempWorldObject.pos.rot[2] = z; } -void WorldFunctions::SendContainer() noexcept +void WorldFunctions::SetContainerItemRefId(const char* refId) noexcept { - mwmp::Networking::get().getWorldController()->GetPacket(ID_CONTAINER)->Send(baseEvent, baseEvent->guid); + tempContainerItem.refId = refId; +} + +void WorldFunctions::SetContainerItemCount(int count) noexcept +{ + tempContainerItem.count = count; +} + +void WorldFunctions::SetContainerItemCharge(int charge) noexcept +{ + tempContainerItem.charge = charge; +} + +void WorldFunctions::AddWorldObject() noexcept +{ + WorldObject worldObject; + worldObject.refId = tempWorldObject.refId; + worldObject.refNumIndex = tempWorldObject.refNumIndex; + worldObject.count = tempWorldObject.count; + worldObject.charge = tempWorldObject.charge; + worldObject.goldValue = tempWorldObject.goldValue; + worldObject.scale = tempWorldObject.scale; + worldObject.doorState = tempWorldObject.doorState; + worldObject.lockLevel = tempWorldObject.lockLevel; + worldObject.pos = tempWorldObject.pos; + worldObject.containerChanges.items = tempWorldObject.containerChanges.items; + + baseEvent->objectChanges.objects.push_back(worldObject); + + tempWorldObject.containerChanges.items.clear(); +} + +void WorldFunctions::AddContainerItem() noexcept +{ + ContainerItem containerItem; + containerItem.refId = tempContainerItem.refId; + containerItem.count = tempContainerItem.count; + containerItem.charge = tempContainerItem.charge; + + tempWorldObject.containerChanges.items.push_back(containerItem); } void WorldFunctions::SendObjectDelete() noexcept @@ -276,6 +300,11 @@ void WorldFunctions::SendDoorState() noexcept mwmp::Networking::get().getWorldController()->GetPacket(ID_DOOR_STATE)->Send(baseEvent, baseEvent->guid); } +void WorldFunctions::SendContainer() noexcept +{ + mwmp::Networking::get().getWorldController()->GetPacket(ID_CONTAINER)->Send(baseEvent, baseEvent->guid); +} + void WorldFunctions::SetHour(unsigned short pid, double hour) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index a568e875b..c05cb310a 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -29,14 +29,13 @@ {"GetContainerItemGoldValue", WorldFunctions::GetContainerItemGoldValue},\ {"GetContainerItemOwner", WorldFunctions::GetContainerItemOwner},\ \ - {"AddWorldObject", WorldFunctions::AddWorldObject},\ {"SetBaseEventCell", WorldFunctions::SetBaseEventCell},\ {"SetBaseEventAction", WorldFunctions::SetBaseEventAction},\ \ {"SetObjectRefId", WorldFunctions::SetObjectRefId},\ {"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\ - {"SetObjectCharge", WorldFunctions::SetObjectCharge},\ {"SetObjectCount", WorldFunctions::SetObjectCount},\ + {"SetObjectCharge", WorldFunctions::SetObjectCharge},\ {"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\ {"SetObjectScale", WorldFunctions::SetObjectScale},\ {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ @@ -44,7 +43,12 @@ {"SetObjectPosition", WorldFunctions::SetObjectPosition},\ {"SetObjectRotation", WorldFunctions::SetObjectRotation},\ \ - {"SendContainer", WorldFunctions::SendContainer},\ + {"SetContainerItemRefId", WorldFunctions::SetContainerItemRefId},\ + {"SetContainerItemCount", WorldFunctions::SetContainerItemCount},\ + {"SetContainerItemCharge", WorldFunctions::SetContainerItemCharge},\ + \ + {"AddWorldObject", WorldFunctions::AddWorldObject},\ + {"AddContainerItem", WorldFunctions::AddContainerItem},\ \ {"SendObjectDelete", WorldFunctions::SendObjectDelete},\ {"SendObjectPlace", WorldFunctions::SendObjectPlace},\ @@ -52,6 +56,7 @@ {"SendObjectLock", WorldFunctions::SendObjectLock},\ {"SendObjectUnlock", WorldFunctions::SendObjectUnlock},\ {"SendDoorState", WorldFunctions::SendDoorState},\ + {"SendContainer", WorldFunctions::SendContainer},\ \ {"SetHour", WorldFunctions::SetHour},\ {"SetMonth", WorldFunctions::SetMonth},\ @@ -88,14 +93,13 @@ public: static int GetContainerItemGoldValue(unsigned int objectIndex, unsigned int itemIndex) noexcept; static const char *GetContainerItemOwner(unsigned int objectIndex, unsigned int itemIndex) noexcept; - static void AddWorldObject() noexcept; static void SetBaseEventCell(const char* cellDescription) noexcept; static void SetBaseEventAction(int action) noexcept; static void SetObjectRefId(const char* refId) noexcept; static void SetObjectRefNumIndex(int refNumIndex) noexcept; - static void SetObjectCharge(int charge) noexcept; static void SetObjectCount(int count) noexcept; + static void SetObjectCharge(int charge) noexcept; static void SetObjectGoldValue(int goldValue) noexcept; static void SetObjectScale(double scale) noexcept; static void SetObjectDoorState(int doorState) noexcept; @@ -103,7 +107,12 @@ public: static void SetObjectPosition(double x, double y, double z) noexcept; static void SetObjectRotation(double x, double y, double z) noexcept; - static void SendContainer() noexcept; + static void SetContainerItemRefId(const char* refId) noexcept; + static void SetContainerItemCount(int count) noexcept; + static void SetContainerItemCharge(int charge) noexcept; + + static void AddWorldObject() noexcept; + static void AddContainerItem() noexcept; static void SendObjectDelete() noexcept; static void SendObjectPlace() noexcept; @@ -111,6 +120,7 @@ public: static void SendObjectLock() noexcept; static void SendObjectUnlock() noexcept; static void SendDoorState() noexcept; + static void SendContainer() noexcept; static void SetHour(unsigned short pid, double hour) noexcept; static void SetMonth(unsigned short pid, int month) noexcept;