From 993081ba1e980a033d2ee9c1e57117c8bb16322a Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 23 Dec 2017 13:16:38 +0200 Subject: [PATCH] [General] Add enchantmentCharge to worldObjects and items --- apps/openmw-mp/Script/Functions/Actors.cpp | 10 +- apps/openmw-mp/Script/Functions/Actors.hpp | 128 +++++++------- apps/openmw-mp/Script/Functions/Items.cpp | 24 ++- apps/openmw-mp/Script/Functions/Items.hpp | 40 +++-- apps/openmw-mp/Script/Functions/World.cpp | 21 +++ apps/openmw-mp/Script/Functions/World.hpp | 164 +++++++++++------- apps/openmw/mwmp/LocalPlayer.cpp | 10 +- apps/openmw/mwmp/WorldEvent.cpp | 21 ++- components/openmw-mp/Base/BaseEvent.hpp | 4 +- components/openmw-mp/Base/BaseStructs.hpp | 3 +- .../Packets/Actor/PacketActorEquipment.cpp | 1 + .../Packets/Player/PacketPlayerInventory.cpp | 1 + .../Packets/World/PacketContainer.cpp | 1 + .../Packets/World/PacketObjectPlace.cpp | 1 + 14 files changed, 277 insertions(+), 152 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index baa71faf9..1f50cbf55 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -163,6 +163,11 @@ int ActorFunctions::GetActorEquipmentItemCharge(unsigned int i, unsigned short s return readActorList->baseActors.at(i).equipedItems[slot].charge; } +int ActorFunctions::GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept +{ + return readActorList->baseActors.at(i).equipedItems[slot].enchantmentCharge; +} + bool ActorFunctions::DoesActorHavePosition(unsigned int i) noexcept { return readActorList->baseActors.at(i).hasPositionData; @@ -262,16 +267,17 @@ void ActorFunctions::SetActorFatigueModified(double value) noexcept tempActor.creatureStats.mDynamic[2].mMod = value; } -void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge) noexcept +void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, int enchantmentCharge) noexcept { tempActor.equipedItems[slot].refId = refId; tempActor.equipedItems[slot].count = count; tempActor.equipedItems[slot].charge = charge; + tempActor.equipedItems[slot].enchantmentCharge = enchantmentCharge; } void ActorFunctions::UnequipActorItem(unsigned short slot) noexcept { - ActorFunctions::EquipActorItem(slot, "", 0, -1); + ActorFunctions::EquipActorItem(slot, "", 0, -1, -1); } void ActorFunctions::AddActor() noexcept diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index e95d006f4..c1ae6bce2 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -2,76 +2,77 @@ #define OPENMW_ACTORAPI_HPP #define ACTORAPI \ - {"ReadLastActorList", ActorFunctions::ReadLastActorList},\ - {"ReadCellActorList", ActorFunctions::ReadCellActorList},\ - {"InitializeActorList", ActorFunctions::InitializeActorList},\ + {"ReadLastActorList", ActorFunctions::ReadLastActorList},\ + {"ReadCellActorList", ActorFunctions::ReadCellActorList},\ + {"InitializeActorList", ActorFunctions::InitializeActorList},\ \ - {"GetActorListSize", ActorFunctions::GetActorListSize},\ - {"GetActorListAction", ActorFunctions::GetActorListAction},\ + {"GetActorListSize", ActorFunctions::GetActorListSize},\ + {"GetActorListAction", ActorFunctions::GetActorListAction},\ \ - {"GetActorCell", ActorFunctions::GetActorCell},\ - {"GetActorRefId", ActorFunctions::GetActorRefId},\ - {"GetActorRefNumIndex", ActorFunctions::GetActorRefNumIndex},\ - {"GetActorMpNum", ActorFunctions::GetActorMpNum},\ + {"GetActorCell", ActorFunctions::GetActorCell},\ + {"GetActorRefId", ActorFunctions::GetActorRefId},\ + {"GetActorRefNumIndex", ActorFunctions::GetActorRefNumIndex},\ + {"GetActorMpNum", ActorFunctions::GetActorMpNum},\ \ - {"GetActorPosX", ActorFunctions::GetActorPosX},\ - {"GetActorPosY", ActorFunctions::GetActorPosY},\ - {"GetActorPosZ", ActorFunctions::GetActorPosZ},\ - {"GetActorRotX", ActorFunctions::GetActorRotX},\ - {"GetActorRotY", ActorFunctions::GetActorRotY},\ - {"GetActorRotZ", ActorFunctions::GetActorRotZ},\ + {"GetActorPosX", ActorFunctions::GetActorPosX},\ + {"GetActorPosY", ActorFunctions::GetActorPosY},\ + {"GetActorPosZ", ActorFunctions::GetActorPosZ},\ + {"GetActorRotX", ActorFunctions::GetActorRotX},\ + {"GetActorRotY", ActorFunctions::GetActorRotY},\ + {"GetActorRotZ", ActorFunctions::GetActorRotZ},\ \ - {"GetActorHealthBase", ActorFunctions::GetActorHealthBase},\ - {"GetActorHealthCurrent", ActorFunctions::GetActorHealthCurrent},\ - {"GetActorHealthModified", ActorFunctions::GetActorHealthModified},\ - {"GetActorMagickaBase", ActorFunctions::GetActorMagickaBase},\ - {"GetActorMagickaCurrent", ActorFunctions::GetActorMagickaCurrent},\ - {"GetActorMagickaModified", ActorFunctions::GetActorMagickaModified},\ - {"GetActorFatigueBase", ActorFunctions::GetActorFatigueBase},\ - {"GetActorFatigueCurrent", ActorFunctions::GetActorFatigueCurrent},\ - {"GetActorFatigueModified", ActorFunctions::GetActorFatigueModified},\ + {"GetActorHealthBase", ActorFunctions::GetActorHealthBase},\ + {"GetActorHealthCurrent", ActorFunctions::GetActorHealthCurrent},\ + {"GetActorHealthModified", ActorFunctions::GetActorHealthModified},\ + {"GetActorMagickaBase", ActorFunctions::GetActorMagickaBase},\ + {"GetActorMagickaCurrent", ActorFunctions::GetActorMagickaCurrent},\ + {"GetActorMagickaModified", ActorFunctions::GetActorMagickaModified},\ + {"GetActorFatigueBase", ActorFunctions::GetActorFatigueBase},\ + {"GetActorFatigueCurrent", ActorFunctions::GetActorFatigueCurrent},\ + {"GetActorFatigueModified", ActorFunctions::GetActorFatigueModified},\ \ - {"GetActorEquipmentItemRefId", ActorFunctions::GetActorEquipmentItemRefId},\ - {"GetActorEquipmentItemCount", ActorFunctions::GetActorEquipmentItemCount},\ - {"GetActorEquipmentItemCharge", ActorFunctions::GetActorEquipmentItemCharge},\ + {"GetActorEquipmentItemRefId", ActorFunctions::GetActorEquipmentItemRefId},\ + {"GetActorEquipmentItemCount", ActorFunctions::GetActorEquipmentItemCount},\ + {"GetActorEquipmentItemCharge", ActorFunctions::GetActorEquipmentItemCharge},\ + {"GetActorEquipmentItemEnchantmentCharge", ActorFunctions::GetActorEquipmentItemEnchantmentCharge},\ \ - {"DoesActorHavePosition", ActorFunctions::DoesActorHavePosition},\ - {"DoesActorHaveStatsDynamic", ActorFunctions::DoesActorHaveStatsDynamic},\ + {"DoesActorHavePosition", ActorFunctions::DoesActorHavePosition},\ + {"DoesActorHaveStatsDynamic", ActorFunctions::DoesActorHaveStatsDynamic},\ \ - {"SetActorListCell", ActorFunctions::SetActorListCell},\ - {"SetActorListAction", ActorFunctions::SetActorListAction},\ + {"SetActorListCell", ActorFunctions::SetActorListCell},\ + {"SetActorListAction", ActorFunctions::SetActorListAction},\ \ - {"SetActorCell", ActorFunctions::SetActorCell},\ - {"SetActorRefId", ActorFunctions::SetActorRefId},\ - {"SetActorRefNumIndex", ActorFunctions::SetActorRefNumIndex},\ - {"SetActorMpNum", ActorFunctions::SetActorMpNum},\ + {"SetActorCell", ActorFunctions::SetActorCell},\ + {"SetActorRefId", ActorFunctions::SetActorRefId},\ + {"SetActorRefNumIndex", ActorFunctions::SetActorRefNumIndex},\ + {"SetActorMpNum", ActorFunctions::SetActorMpNum},\ \ - {"SetActorPosition", ActorFunctions::SetActorPosition},\ - {"SetActorRotation", ActorFunctions::SetActorRotation},\ + {"SetActorPosition", ActorFunctions::SetActorPosition},\ + {"SetActorRotation", ActorFunctions::SetActorRotation},\ \ - {"SetActorHealthBase", ActorFunctions::SetActorHealthBase},\ - {"SetActorHealthCurrent", ActorFunctions::SetActorHealthCurrent},\ - {"SetActorHealthModified", ActorFunctions::SetActorHealthModified},\ - {"SetActorMagickaBase", ActorFunctions::SetActorMagickaBase},\ - {"SetActorMagickaCurrent", ActorFunctions::SetActorMagickaCurrent},\ - {"SetActorMagickaModified", ActorFunctions::SetActorMagickaModified},\ - {"SetActorFatigueBase", ActorFunctions::SetActorFatigueBase},\ - {"SetActorFatigueCurrent", ActorFunctions::SetActorFatigueCurrent},\ - {"SetActorFatigueModified", ActorFunctions::SetActorFatigueModified},\ + {"SetActorHealthBase", ActorFunctions::SetActorHealthBase},\ + {"SetActorHealthCurrent", ActorFunctions::SetActorHealthCurrent},\ + {"SetActorHealthModified", ActorFunctions::SetActorHealthModified},\ + {"SetActorMagickaBase", ActorFunctions::SetActorMagickaBase},\ + {"SetActorMagickaCurrent", ActorFunctions::SetActorMagickaCurrent},\ + {"SetActorMagickaModified", ActorFunctions::SetActorMagickaModified},\ + {"SetActorFatigueBase", ActorFunctions::SetActorFatigueBase},\ + {"SetActorFatigueCurrent", ActorFunctions::SetActorFatigueCurrent},\ + {"SetActorFatigueModified", ActorFunctions::SetActorFatigueModified},\ \ - {"EquipActorItem", ActorFunctions::EquipActorItem},\ - {"UnequipActorItem", ActorFunctions::UnequipActorItem},\ + {"EquipActorItem", ActorFunctions::EquipActorItem},\ + {"UnequipActorItem", ActorFunctions::UnequipActorItem},\ \ - {"AddActor", ActorFunctions::AddActor},\ + {"AddActor", ActorFunctions::AddActor},\ \ - {"SendActorList", ActorFunctions::SendActorList},\ - {"SendActorAuthority", ActorFunctions::SendActorAuthority},\ - {"SendActorPosition", ActorFunctions::SendActorPosition},\ - {"SendActorStatsDynamic", ActorFunctions::SendActorStatsDynamic},\ - {"SendActorEquipment", ActorFunctions::SendActorEquipment},\ - {"SendActorCellChange", ActorFunctions::SendActorCellChange} - -class ActorFunctions + {"SendActorList", ActorFunctions::SendActorList},\ + {"SendActorAuthority", ActorFunctions::SendActorAuthority},\ + {"SendActorPosition", ActorFunctions::SendActorPosition},\ + {"SendActorStatsDynamic", ActorFunctions::SendActorStatsDynamic},\ + {"SendActorEquipment", ActorFunctions::SendActorEquipment},\ + {"SendActorCellChange", ActorFunctions::SendActorCellChange} + +class ActorFunctions { public: @@ -299,6 +300,16 @@ public: */ static int GetActorEquipmentItemCharge(unsigned int i, unsigned short slot) noexcept; + /** + * \brief Get the enchantment charge of the item in a certain slot of the equipment of the actor at a + * certain index in the read actor list. + * + * \param i The index of the actor. + * \param slot The slot of the equipment item. + * \return The enchantment charge. + */ + static int GetActorEquipmentItemEnchantmentCharge(unsigned int i, unsigned short slot) noexcept; + /** * \brief Check whether there is any positional data for the actor at a certain index in * the read actor list. @@ -478,9 +489,10 @@ public: * \param refId The refId of the item. * \param count The count of the item. * \param charge The charge of the item. + * \param enchantmentCharge The enchantment charge of the item. * \return void */ - static void EquipActorItem(unsigned short slot, const char* refId, unsigned int count, int charge) noexcept; + static void EquipActorItem(unsigned short slot, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; /** * \brief Unequip the item in a certain slot of the equipment of the temporary actor stored diff --git a/apps/openmw-mp/Script/Functions/Items.cpp b/apps/openmw-mp/Script/Functions/Items.cpp index 44d957ef5..7ff6fc8e7 100644 --- a/apps/openmw-mp/Script/Functions/Items.cpp +++ b/apps/openmw-mp/Script/Functions/Items.cpp @@ -35,7 +35,7 @@ unsigned int ItemFunctions::GetInventoryChangesSize(unsigned short pid) noexcept return player->inventoryChanges.count; } -void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count, int charge) noexcept +void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const char *refId, unsigned int count, int charge, int enchantmentCharge) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -43,6 +43,7 @@ void ItemFunctions::EquipItem(unsigned short pid, unsigned short slot, const cha player->equipedItems[slot].refId = refId; player->equipedItems[slot].count = count; player->equipedItems[slot].charge = charge; + player->equipedItems[slot].enchantmentCharge = enchantmentCharge; } void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcept @@ -50,10 +51,10 @@ void ItemFunctions::UnequipItem(unsigned short pid, unsigned short slot) noexcep Player *player; GET_PLAYER(pid, player, ); - ItemFunctions::EquipItem(pid, slot, "", 0, -1); + ItemFunctions::EquipItem(pid, slot, "", 0, -1, -1); } -void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge) noexcept +void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, int enchantmentCharge) noexcept { Player *player; GET_PLAYER(pid, player, ); @@ -62,6 +63,7 @@ void ItemFunctions::AddItem(unsigned short pid, const char* refId, unsigned int item.refId = refId; item.count = count; item.charge = charge; + item.enchantmentCharge = enchantmentCharge; player->inventoryChanges.items.push_back(item); player->inventoryChanges.action = InventoryChanges::ADD; @@ -115,6 +117,14 @@ int ItemFunctions::GetEquipmentItemCharge(unsigned short pid, unsigned short slo return player->equipedItems[slot].charge; } +int ItemFunctions::GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->equipedItems[slot].enchantmentCharge; +} + const char *ItemFunctions::GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept { Player *player; @@ -142,6 +152,14 @@ int ItemFunctions::GetInventoryItemCharge(unsigned short pid, unsigned int i) no return player->inventoryChanges.items.at(i).charge; } +int ItemFunctions::GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->inventoryChanges.items.at(i).enchantmentCharge; +} + void ItemFunctions::SendEquipment(unsigned short pid) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Items.hpp b/apps/openmw-mp/Script/Functions/Items.hpp index 6bc87a981..9350be896 100644 --- a/apps/openmw-mp/Script/Functions/Items.hpp +++ b/apps/openmw-mp/Script/Functions/Items.hpp @@ -6,29 +6,31 @@ #define OPENMW_ITEMAPI_HPP #define ITEMAPI \ - {"InitializeInventoryChanges", ItemFunctions::InitializeInventoryChanges},\ + {"InitializeInventoryChanges", ItemFunctions::InitializeInventoryChanges},\ \ - {"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\ - {"GetInventoryChangesSize", ItemFunctions::GetInventoryChangesSize},\ + {"GetEquipmentSize", ItemFunctions::GetEquipmentSize},\ + {"GetInventoryChangesSize", ItemFunctions::GetInventoryChangesSize},\ \ - {"EquipItem", ItemFunctions::EquipItem},\ - {"UnequipItem", ItemFunctions::UnequipItem},\ + {"EquipItem", ItemFunctions::EquipItem},\ + {"UnequipItem", ItemFunctions::UnequipItem},\ \ - {"AddItem", ItemFunctions::AddItem},\ - {"RemoveItem", ItemFunctions::RemoveItem},\ + {"AddItem", ItemFunctions::AddItem},\ + {"RemoveItem", ItemFunctions::RemoveItem},\ \ - {"HasItemEquipped", ItemFunctions::HasItemEquipped},\ + {"HasItemEquipped", ItemFunctions::HasItemEquipped},\ \ - {"GetEquipmentItemRefId", ItemFunctions::GetEquipmentItemRefId},\ - {"GetEquipmentItemCount", ItemFunctions::GetEquipmentItemCount},\ - {"GetEquipmentItemCharge", ItemFunctions::GetEquipmentItemCharge},\ + {"GetEquipmentItemRefId", ItemFunctions::GetEquipmentItemRefId},\ + {"GetEquipmentItemCount", ItemFunctions::GetEquipmentItemCount},\ + {"GetEquipmentItemCharge", ItemFunctions::GetEquipmentItemCharge},\ + {"GetEquipmentItemEnchantmentCharge", ItemFunctions::GetEquipmentItemEnchantmentCharge},\ \ - {"GetInventoryItemRefId", ItemFunctions::GetInventoryItemRefId},\ - {"GetInventoryItemCount", ItemFunctions::GetInventoryItemCount},\ - {"GetInventoryItemCharge", ItemFunctions::GetInventoryItemCharge},\ + {"GetInventoryItemRefId", ItemFunctions::GetInventoryItemRefId},\ + {"GetInventoryItemCount", ItemFunctions::GetInventoryItemCount},\ + {"GetInventoryItemCharge", ItemFunctions::GetInventoryItemCharge},\ + {"GetInventoryItemEnchantmentCharge", ItemFunctions::GetInventoryItemEnchantmentCharge},\ \ - {"SendEquipment", ItemFunctions::SendEquipment},\ - {"SendInventoryChanges", ItemFunctions::SendInventoryChanges} + {"SendEquipment", ItemFunctions::SendEquipment},\ + {"SendInventoryChanges", ItemFunctions::SendInventoryChanges} class ItemFunctions { @@ -39,10 +41,10 @@ public: static int GetEquipmentSize() noexcept; static unsigned int GetInventoryChangesSize(unsigned short pid) noexcept; - static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge) noexcept; + static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; static void UnequipItem(unsigned short pid, unsigned short slot) noexcept; - static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge) noexcept; + static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, int enchantmentCharge = -1) noexcept; static void RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept; static bool HasItemEquipped(unsigned short pid, const char* refId); @@ -50,10 +52,12 @@ public: static const char *GetEquipmentItemRefId(unsigned short pid, unsigned short slot) noexcept; static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept; static int GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept; + static int GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept; static const char *GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept; static int GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept; static int GetInventoryItemCharge(unsigned short pid, unsigned int i) noexcept; + static int GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept; static void SendEquipment(unsigned short pid) noexcept; static void SendInventoryChanges(unsigned short pid, bool toOthers = false) noexcept; diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index f5cd6962d..5c0f3cc5c 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -69,6 +69,11 @@ int WorldFunctions::GetObjectCharge(unsigned int i) noexcept return readEvent->worldObjects.at(i).charge; } +int WorldFunctions::GetObjectEnchantmentCharge(unsigned int i) noexcept +{ + return readEvent->worldObjects.at(i).enchantmentCharge; +} + int WorldFunctions::GetObjectGoldValue(unsigned int i) noexcept { return readEvent->worldObjects.at(i).goldValue; @@ -147,6 +152,12 @@ int WorldFunctions::GetContainerItemCharge(unsigned int objectIndex, unsigned in .containerItems.at(itemIndex).charge; } +int WorldFunctions::GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept +{ + return readEvent->worldObjects.at(objectIndex) + .containerItems.at(itemIndex).enchantmentCharge; +} + int WorldFunctions::GetContainerItemActionCount(unsigned int objectIndex, unsigned int itemIndex) noexcept { return readEvent->worldObjects.at(objectIndex) @@ -193,6 +204,11 @@ void WorldFunctions::SetObjectCharge(int charge) noexcept tempWorldObject.charge = charge; } +void WorldFunctions::SetObjectEnchantmentCharge(int enchantmentCharge) noexcept +{ + tempWorldObject.enchantmentCharge = enchantmentCharge; +} + void WorldFunctions::SetObjectGoldValue(int goldValue) noexcept { tempWorldObject.goldValue = goldValue; @@ -266,6 +282,11 @@ void WorldFunctions::SetContainerItemCharge(int charge) noexcept tempContainerItem.charge = charge; } +void WorldFunctions::SetContainerItemEnchantmentCharge(int enchantmentCharge) noexcept +{ + tempContainerItem.enchantmentCharge = enchantmentCharge; +} + void WorldFunctions::AddWorldObject() noexcept { writeEvent.worldObjects.push_back(tempWorldObject); diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index 7b343301f..c3f901bb5 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -2,78 +2,82 @@ #define OPENMW_WORLDAPI_HPP #define WORLDAPI \ - {"ReadLastEvent", WorldFunctions::ReadLastEvent},\ - {"InitializeEvent", WorldFunctions::InitializeEvent},\ + {"ReadLastEvent", WorldFunctions::ReadLastEvent},\ + {"InitializeEvent", WorldFunctions::InitializeEvent},\ \ - {"GetObjectChangesSize", WorldFunctions::GetObjectChangesSize},\ - {"GetEventAction", WorldFunctions::GetEventAction},\ + {"GetObjectChangesSize", WorldFunctions::GetObjectChangesSize},\ + {"GetEventAction", WorldFunctions::GetEventAction},\ \ - {"GetObjectRefId", WorldFunctions::GetObjectRefId},\ - {"GetObjectRefNumIndex", WorldFunctions::GetObjectRefNumIndex},\ - {"GetObjectMpNum", WorldFunctions::GetObjectMpNum},\ - {"GetObjectCount", WorldFunctions::GetObjectCount},\ - {"GetObjectCharge", WorldFunctions::GetObjectCharge},\ - {"GetObjectGoldValue", WorldFunctions::GetObjectGoldValue},\ - {"GetObjectScale", WorldFunctions::GetObjectScale},\ - {"GetObjectState", WorldFunctions::GetObjectState},\ - {"GetObjectDoorState", WorldFunctions::GetObjectDoorState},\ - {"GetObjectLockLevel", WorldFunctions::GetObjectLockLevel},\ - {"GetObjectPosX", WorldFunctions::GetObjectPosX},\ - {"GetObjectPosY", WorldFunctions::GetObjectPosY},\ - {"GetObjectPosZ", WorldFunctions::GetObjectPosZ},\ - {"GetObjectRotX", WorldFunctions::GetObjectRotX},\ - {"GetObjectRotY", WorldFunctions::GetObjectRotY},\ - {"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\ + {"GetObjectRefId", WorldFunctions::GetObjectRefId},\ + {"GetObjectRefNumIndex", WorldFunctions::GetObjectRefNumIndex},\ + {"GetObjectMpNum", WorldFunctions::GetObjectMpNum},\ + {"GetObjectCount", WorldFunctions::GetObjectCount},\ + {"GetObjectCharge", WorldFunctions::GetObjectCharge},\ + {"GetObjectEnchantmentCharge", WorldFunctions::GetObjectEnchantmentCharge},\ + {"GetObjectGoldValue", WorldFunctions::GetObjectGoldValue},\ + {"GetObjectScale", WorldFunctions::GetObjectScale},\ + {"GetObjectState", WorldFunctions::GetObjectState},\ + {"GetObjectDoorState", WorldFunctions::GetObjectDoorState},\ + {"GetObjectLockLevel", WorldFunctions::GetObjectLockLevel},\ + {"GetObjectPosX", WorldFunctions::GetObjectPosX},\ + {"GetObjectPosY", WorldFunctions::GetObjectPosY},\ + {"GetObjectPosZ", WorldFunctions::GetObjectPosZ},\ + {"GetObjectRotX", WorldFunctions::GetObjectRotX},\ + {"GetObjectRotY", WorldFunctions::GetObjectRotY},\ + {"GetObjectRotZ", WorldFunctions::GetObjectRotZ},\ \ - {"GetContainerChangesSize", WorldFunctions::GetContainerChangesSize},\ - {"GetContainerItemRefId", WorldFunctions::GetContainerItemRefId},\ - {"GetContainerItemCount", WorldFunctions::GetContainerItemCount},\ - {"GetContainerItemCharge", WorldFunctions::GetContainerItemCharge},\ - {"GetContainerItemActionCount", WorldFunctions::GetContainerItemActionCount},\ + {"GetContainerChangesSize", WorldFunctions::GetContainerChangesSize},\ + {"GetContainerItemRefId", WorldFunctions::GetContainerItemRefId},\ + {"GetContainerItemCount", WorldFunctions::GetContainerItemCount},\ + {"GetContainerItemCharge", WorldFunctions::GetContainerItemCharge},\ + {"GetContainerItemEnchantmentCharge", WorldFunctions::GetContainerItemEnchantmentCharge},\ + {"GetContainerItemActionCount", WorldFunctions::GetContainerItemActionCount},\ \ - {"SetEventCell", WorldFunctions::SetEventCell},\ - {"SetEventAction", WorldFunctions::SetEventAction},\ - {"SetEventConsoleCommand", WorldFunctions::SetEventConsoleCommand},\ + {"SetEventCell", WorldFunctions::SetEventCell},\ + {"SetEventAction", WorldFunctions::SetEventAction},\ + {"SetEventConsoleCommand", WorldFunctions::SetEventConsoleCommand},\ \ - {"SetObjectRefId", WorldFunctions::SetObjectRefId},\ - {"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\ - {"SetObjectMpNum", WorldFunctions::SetObjectMpNum},\ - {"SetObjectCount", WorldFunctions::SetObjectCount},\ - {"SetObjectCharge", WorldFunctions::SetObjectCharge},\ - {"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\ - {"SetObjectScale", WorldFunctions::SetObjectScale},\ - {"SetObjectState", WorldFunctions::SetObjectState},\ - {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ - {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ - {"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\ - {"SetObjectMasterState", WorldFunctions::SetObjectMasterState},\ - {"SetObjectPosition", WorldFunctions::SetObjectPosition},\ - {"SetObjectRotation", WorldFunctions::SetObjectRotation},\ - {"SetPlayerAsObject", WorldFunctions::SetPlayerAsObject},\ + {"SetObjectRefId", WorldFunctions::SetObjectRefId},\ + {"SetObjectRefNumIndex", WorldFunctions::SetObjectRefNumIndex},\ + {"SetObjectMpNum", WorldFunctions::SetObjectMpNum},\ + {"SetObjectCount", WorldFunctions::SetObjectCount},\ + {"SetObjectCharge", WorldFunctions::SetObjectCharge},\ + {"SetObjectEnchantmentCharge", WorldFunctions::SetObjectEnchantmentCharge},\ + {"SetObjectGoldValue", WorldFunctions::SetObjectGoldValue},\ + {"SetObjectScale", WorldFunctions::SetObjectScale},\ + {"SetObjectState", WorldFunctions::SetObjectState},\ + {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ + {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ + {"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\ + {"SetObjectMasterState", WorldFunctions::SetObjectMasterState},\ + {"SetObjectPosition", WorldFunctions::SetObjectPosition},\ + {"SetObjectRotation", WorldFunctions::SetObjectRotation},\ + {"SetPlayerAsObject", WorldFunctions::SetPlayerAsObject},\ \ - {"SetContainerItemRefId", WorldFunctions::SetContainerItemRefId},\ - {"SetContainerItemCount", WorldFunctions::SetContainerItemCount},\ - {"SetContainerItemCharge", WorldFunctions::SetContainerItemCharge},\ + {"SetContainerItemRefId", WorldFunctions::SetContainerItemRefId},\ + {"SetContainerItemCount", WorldFunctions::SetContainerItemCount},\ + {"SetContainerItemCharge", WorldFunctions::SetContainerItemCharge},\ + {"SetContainerItemEnchantmentCharge", WorldFunctions::SetContainerItemEnchantmentCharge},\ \ - {"AddWorldObject", WorldFunctions::AddWorldObject},\ - {"AddContainerItem", WorldFunctions::AddContainerItem},\ + {"AddWorldObject", WorldFunctions::AddWorldObject},\ + {"AddContainerItem", WorldFunctions::AddContainerItem},\ \ - {"SendObjectPlace", WorldFunctions::SendObjectPlace},\ - {"SendObjectSpawn", WorldFunctions::SendObjectSpawn},\ - {"SendObjectDelete", WorldFunctions::SendObjectDelete},\ - {"SendObjectLock", WorldFunctions::SendObjectLock},\ - {"SendObjectTrap", WorldFunctions::SendObjectTrap},\ - {"SendObjectScale", WorldFunctions::SendObjectScale},\ - {"SendObjectState", WorldFunctions::SendObjectState},\ - {"SendDoorState", WorldFunctions::SendDoorState},\ - {"SendContainer", WorldFunctions::SendContainer},\ - {"SendConsoleCommand", WorldFunctions::SendConsoleCommand},\ + {"SendObjectPlace", WorldFunctions::SendObjectPlace},\ + {"SendObjectSpawn", WorldFunctions::SendObjectSpawn},\ + {"SendObjectDelete", WorldFunctions::SendObjectDelete},\ + {"SendObjectLock", WorldFunctions::SendObjectLock},\ + {"SendObjectTrap", WorldFunctions::SendObjectTrap},\ + {"SendObjectScale", WorldFunctions::SendObjectScale},\ + {"SendObjectState", WorldFunctions::SendObjectState},\ + {"SendDoorState", WorldFunctions::SendDoorState},\ + {"SendContainer", WorldFunctions::SendContainer},\ + {"SendConsoleCommand", WorldFunctions::SendConsoleCommand},\ \ - {"SetHour", WorldFunctions::SetHour},\ - {"SetMonth", WorldFunctions::SetMonth},\ - {"SetDay", WorldFunctions::SetDay} + {"SetHour", WorldFunctions::SetHour},\ + {"SetMonth", WorldFunctions::SetMonth},\ + {"SetDay", WorldFunctions::SetDay} -class WorldFunctions +class WorldFunctions { public: @@ -148,6 +152,14 @@ public: */ static int GetObjectCharge(unsigned int i) noexcept; + /** + * \brief Get the enchantment charge of the object at a certain index in the read event's object changes. + * + * \param i The index of the object. + * \return The enchantment charge. + */ + static int GetObjectEnchantmentCharge(unsigned int i) noexcept; + /** * \brief Get the gold value of the object at a certain index in the read event's object * changes. @@ -287,6 +299,16 @@ public: */ static int GetContainerItemCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept; + /** + * \brief Get the enchantment charge of the container item at a certain itemIndex in the container changes + * of the object at a certain objectIndex in the read event's object changes. + * + * \param objectIndex The index of the object. + * \param itemIndex The index of the container item. + * \return The enchantment charge. + */ + static int GetContainerItemEnchantmentCharge(unsigned int objectIndex, unsigned int itemIndex) noexcept; + /** * \brief Get the action count of the container item at a certain itemIndex in the container * changes of the object at a certain objectIndex in the read event's object changes. @@ -384,6 +406,16 @@ public: */ static void SetObjectCharge(int charge) noexcept; + /** + * \brief Set the enchantment charge of the temporary world object stored on the server. + * + * Object durabilities are set through this value. + * + * \param charge The enchantment charge. + * \return void + */ + static void SetObjectEnchantmentCharge(int enchantmentCharge) noexcept; + /** * \brief Set the gold value of the temporary world object stored on the server. * @@ -504,6 +536,14 @@ public: */ static void SetContainerItemCharge(int charge) noexcept; + /** + * \brief Set the enchantment charge of the temporary container item stored on the server. + * + * \param charge The enchantment charge. + * \return void + */ + static void SetContainerItemEnchantmentCharge(int enchantmentCharge) noexcept; + /** * \brief Add a copy of the server's temporary world object to the server's temporary event. * diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 13211f61b..62e8c7727 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -450,6 +450,8 @@ void LocalPlayer::updateEquipment(bool forceUpdate) item.refId = it->getCellRef().getRefId(); item.charge = it->getCellRef().getCharge(); + item.enchantmentCharge = it->getCellRef().getEnchantmentCharge(); + if (slot == MWWorld::InventoryStore::Slot_CarriedRight) { MWMechanics::WeaponType weaptype; @@ -467,7 +469,8 @@ void LocalPlayer::updateEquipment(bool forceUpdate) equipmentChanged = true; item.refId = ""; item.count = 0; - item.charge = 0; + item.charge = -1; + item.enchantmentCharge = -1; } } @@ -496,6 +499,7 @@ void LocalPlayer::updateInventory(bool forceUpdate) return true; item.count = iter.getRefData().getCount(); item.charge = iter.getCellRef().getCharge(); + item.enchantmentCharge = iter.getCellRef().getEnchantmentCharge(); return false; }; @@ -671,6 +675,9 @@ void LocalPlayer::addItems() MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer); if (item.charge != -1) itemPtr.getCellRef().setCharge(item.charge); + + if (item.enchantmentCharge != -1) + itemPtr.getCellRef().setEnchantmentCharge(item.enchantmentCharge); } catch (std::exception&) { @@ -1188,6 +1195,7 @@ void LocalPlayer::sendInventory() item.count = iter.getRefData().getCount(); item.charge = iter.getCellRef().getCharge(); + item.enchantmentCharge = iter.getCellRef().getEnchantmentCharge(); inventoryChanges.items.push_back(item); } diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 10f57b8aa..7e87d4821 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -95,6 +95,9 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore) if (containerItem.charge > -1) newPtr.getCellRef().setCharge(containerItem.charge); + if (containerItem.enchantmentCharge > -1) + newPtr.getCellRef().setEnchantmentCharge(containerItem.enchantmentCharge); + containerStore.add(newPtr, containerItem.count, ownerPtr, true); } else if (action == BaseEvent::REMOVE) @@ -105,8 +108,9 @@ void WorldEvent::editContainers(MWWorld::CellStore* cellStore) { if (Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), containerItem.refId)) { - if (ptr.getCellRef().getCharge() == containerItem.charge && - ptr.getRefData().getCount() == containerItem.count) + if (ptr.getRefData().getCount() == containerItem.count && + ptr.getCellRef().getCharge() == containerItem.charge && + ptr.getCellRef().getEnchantmentCharge() == containerItem.enchantmentCharge) { // Is this an actor's container? If so, unequip this item if it was equipped if (ptrFound.getClass().isActor()) @@ -153,8 +157,8 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore) { for (const auto &worldObject : worldObjects) { - LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i, charge: %i, count: %i", worldObject.refId.c_str(), - worldObject.refNumIndex, worldObject.mpNum, worldObject.charge, worldObject.count); + LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i, count: %i, charge: %i, enchantmentCharge: %i", worldObject.refId.c_str(), + worldObject.refNumIndex, worldObject.mpNum, worldObject.count, worldObject.charge, worldObject.enchantmentCharge); MWWorld::Ptr ptrFound = cellStore->searchExact(0, worldObject.mpNum); @@ -164,11 +168,14 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore) MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1); MWWorld::Ptr newPtr = ref.getPtr(); + if (worldObject.count > 1) + newPtr.getRefData().setCount(worldObject.count); + if (worldObject.charge > -1) newPtr.getCellRef().setCharge(worldObject.charge); - if (worldObject.count > 1) - newPtr.getRefData().setCount(worldObject.count); + if (worldObject.enchantmentCharge > -1) + newPtr.getCellRef().setEnchantmentCharge(worldObject.enchantmentCharge); newPtr.getCellRef().setGoldValue(worldObject.goldValue); newPtr = MWBase::Environment::get().getWorld()->placeObject(newPtr, cellStore, worldObject.position); @@ -580,6 +587,7 @@ void WorldEvent::addObjectPlace(const MWWorld::Ptr& ptr) worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.mpNum = 0; worldObject.charge = ptr.getCellRef().getCharge(); + worldObject.enchantmentCharge = ptr.getCellRef().getEnchantmentCharge(); // Make sure we send the RefData position instead of the CellRef one, because that's what // we actually see on this client @@ -944,6 +952,7 @@ void WorldEvent::sendContainers(MWWorld::CellStore* cellStore) containerItem.refId = itemPtr.getCellRef().getRefId(); containerItem.count = itemPtr.getRefData().getCount(); containerItem.charge = itemPtr.getCellRef().getCharge(); + containerItem.enchantmentCharge = itemPtr.getCellRef().getEnchantmentCharge(); worldObject.containerItems.push_back(containerItem); } diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 19f7e6ea3..f7718412c 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -12,12 +12,13 @@ namespace mwmp std::string refId; int count; int charge; + int enchantmentCharge; int actionCount; inline bool operator==(const ContainerItem& rhs) { - return refId == rhs.refId && count == rhs.count && charge == rhs.charge; + return refId == rhs.refId && count == rhs.count && charge == rhs.charge && enchantmentCharge == rhs.enchantmentCharge; } }; @@ -28,6 +29,7 @@ namespace mwmp int mpNum; int count; int charge; + int enchantmentCharge; int goldValue; ESM::Position position; diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 951ba4222..b915a903c 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -12,10 +12,11 @@ namespace mwmp std::string refId; int count; int charge; + int enchantmentCharge; inline bool operator==(const Item& rhs) { - return refId == rhs.refId && count == rhs.count && charge == rhs.charge; + return refId == rhs.refId && count == rhs.count && charge == rhs.charge && enchantmentCharge == rhs.enchantmentCharge; } }; diff --git a/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp b/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp index 513fd2833..3e613c78d 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorEquipment.cpp @@ -16,5 +16,6 @@ void PacketActorEquipment::Actor(BaseActor &actor, bool send) RW(actor.equipedItems[j].refId, send); RW(actor.equipedItems[j].count, send); RW(actor.equipedItems[j].charge, send); + RW(actor.equipedItems[j].enchantmentCharge, send); } } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp b/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp index e48c28941..3cb960f33 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerInventory.cpp @@ -36,6 +36,7 @@ void PacketPlayerInventory::Packet(RakNet::BitStream *bs, bool send) RW(item.refId, send, 1); RW(item.count, send); RW(item.charge, send); + RW(item.enchantmentCharge, send); if (!send) player->inventoryChanges.items.push_back(item); diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index e35af088a..2e272b523 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -48,6 +48,7 @@ void PacketContainer::Packet(RakNet::BitStream *bs, bool send) RW(containerItem.refId, send); RW(containerItem.count, send); RW(containerItem.charge, send); + RW(containerItem.enchantmentCharge, send); RW(containerItem.actionCount, send); if (!send) diff --git a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp index 7a13964cb..031913074 100644 --- a/components/openmw-mp/Packets/World/PacketObjectPlace.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectPlace.cpp @@ -14,6 +14,7 @@ void PacketObjectPlace::Object(WorldObject &worldObject, bool send) WorldPacket::Object(worldObject, send); RW(worldObject.count, send); RW(worldObject.charge, send); + RW(worldObject.enchantmentCharge, send); RW(worldObject.goldValue, send); RW(worldObject.position, send); }