From de0bb3cdab2d2a131acdc838c25967e4e6a4c73f Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 20 Jan 2018 18:32:26 +0800 Subject: [PATCH] [General] Change type of Item::enchantmentCharge to float --- apps/openmw-mp/Inventory.cpp | 4 ++-- apps/openmw-mp/Inventory.hpp | 4 ++-- apps/openmw/mwmp/DedicatedActor.cpp | 9 ++++++--- apps/openmw/mwmp/DedicatedPlayer.cpp | 3 +-- apps/openmw/mwmp/LocalPlayer.cpp | 4 ++-- components/openmw-mp/Base/BaseStructs.hpp | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/openmw-mp/Inventory.cpp b/apps/openmw-mp/Inventory.cpp index 78628a106..299412a08 100644 --- a/apps/openmw-mp/Inventory.cpp +++ b/apps/openmw-mp/Inventory.cpp @@ -97,7 +97,7 @@ int Inventory::getChangesSize() const return netActor->getNetCreature()->inventoryChanges.items.size(); } -void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, double enchantmentCharge) +void Inventory::equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, float enchantmentCharge) { netActor->getNetCreature()->equipmentItems[slot].refId = refId; netActor->getNetCreature()->equipmentItems[slot].count = count; @@ -119,7 +119,7 @@ void Inventory::unequipItem( unsigned short slot) } -void Inventory::addItem(const std::string &refId, unsigned int count, int charge, double enchantmentCharge) +void Inventory::addItem(const std::string &refId, unsigned int count, int charge, float enchantmentCharge) { if (inventoryChanged == mwmp::InventoryChanges::Type::Remove) return; diff --git a/apps/openmw-mp/Inventory.hpp b/apps/openmw-mp/Inventory.hpp index f6fb4a404..78f5a035c 100644 --- a/apps/openmw-mp/Inventory.hpp +++ b/apps/openmw-mp/Inventory.hpp @@ -25,7 +25,7 @@ public: //inventory int getChangesSize() const; - void addItem(const std::string& refId, unsigned int count, int charge, double enchantmentCharge); + void addItem(const std::string& refId, unsigned int count, int charge, float enchantmentCharge); void removeItem(const std::string& refId, unsigned short count); /** @@ -37,7 +37,7 @@ public: // equipment - void equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, double enchantmentCharge); + void equipItem(unsigned short slot, const std::string& refId, unsigned int count, int charge, float enchantmentCharge); void unequipItem(unsigned short slot); bool hasItemEquipped(const std::string& refId) const; diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index b49cc6dce..7315b10c3 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -172,15 +172,18 @@ void DedicatedActor::setEquipment() const string &packetRefId = equipmentItems[slot].refId; int packetCharge = equipmentItems[slot].charge; - std::string storeRefId = ""; bool equal = false; if (it != invStore.end()) { - storeRefId = it->getCellRef().getRefId(); + std::string storeRefId = it->getCellRef().getRefId(); + int count = invStore.count(storeRefId); - if (!Misc::StringUtils::ciEqual(storeRefId, packetRefId)) // if other item equiped + if (!Misc::StringUtils::ciEqual(storeRefId, packetRefId)) // if other item equipped + { invStore.unequipSlot(slot, ptr); + ptr.getClass().getContainerStore(ptr).remove(storeRefId, count, ptr); + } else equal = true; } diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 5a79aef35..88947e19c 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -170,11 +170,10 @@ void DedicatedPlayer::setEquipment() MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); const string &dedicItem = equipmentItems[slot].refId; - std::string item = ""; bool equal = false; if (it != invStore.end()) { - item = it->getCellRef().getRefId(); + const std::string &item = it->getCellRef().getRefId(); if (!Misc::StringUtils::ciEqual(item, dedicItem)) // if other item equiped { MWWorld::ContainerStore &store = ptr.getClass().getContainerStore(ptr); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index f3300eff5..5cfc2fdd4 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -455,11 +455,11 @@ void LocalPlayer::updateEquipment(bool forceUpdate) item.refId = ""; item.count = 0; item.charge = -1; - item.enchantmentCharge = -1; + item.enchantmentCharge = -1.0f; } } - if (equipmentIndexChanges.size() > 0) + if (!equipmentIndexChanges.empty()) { getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_EQUIPMENT)->Send(); diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index cc57c274d..531f395a2 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -12,7 +12,7 @@ namespace mwmp std::string refId; int count; int charge; - double enchantmentCharge; + float enchantmentCharge; inline bool operator==(const Item& rhs) {