From 9519c467eb16429266c5a4efce704b5f23866e5d Mon Sep 17 00:00:00 2001 From: Koncord Date: Thu, 29 Jun 2017 14:52:23 +0800 Subject: [PATCH] [Client] Simplify updateEquipment for LocalPlayer & LocalActor --- apps/openmw/mwmp/LocalActor.cpp | 32 +++++++++++++++------------ apps/openmw/mwmp/LocalPlayer.cpp | 37 ++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index ffaf8e323..7465c6216 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -195,24 +195,28 @@ void LocalActor::updateEquipment(bool forceUpdate) MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); auto &item = equipedItems[slot]; - if (it != invStore.end() && !::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), item.refId)) + if (it != invStore.end()) { - equipmentChanged = true; - - item.refId = it->getCellRef().getRefId(); - item.charge = it->getCellRef().getCharge(); - if (slot == MWWorld::InventoryStore::Slot_CarriedRight) + auto &cellRef = it->getCellRef(); + if (!::Misc::StringUtils::ciEqual(cellRef.getRefId(), item.refId)) { - MWMechanics::WeaponType weaptype; - auto &_class = ptr.getClass(); - MWMechanics::getActiveWeapon(_class.getCreatureStats(ptr), _class.getInventoryStore(ptr), &weaptype); - if (weaptype != MWMechanics::WeapType_Thrown) - item.count = 1; + equipmentChanged = true; + + item.refId = cellRef.getRefId(); + item.charge = cellRef.getCharge(); + if (slot == MWWorld::InventoryStore::Slot_CarriedRight) + { + MWMechanics::WeaponType weaptype; + auto &_class = ptr.getClass(); + MWMechanics::getActiveWeapon(_class.getCreatureStats(ptr), _class.getInventoryStore(ptr), &weaptype); + if (weaptype != MWMechanics::WeapType_Thrown) + item.count = 1; + } + else + item.count = invStore.count(cellRef.getRefId()); } - else - item.count = invStore.count(it->getCellRef().getRefId()); } - else if (it == invStore.end() && !item.refId.empty()) + else if (!item.refId.empty()) { equipmentChanged = true; item.refId = ""; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 18026e3b8..9d2ea017c 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -407,29 +407,34 @@ void LocalPlayer::updateEquipment(bool forceUpdate) MWWorld::InventoryStore &invStore = player.getClass().getInventoryStore(player); for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++) { + auto &item = equipedItems[slot]; MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); - if (it != invStore.end() && !::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), equipedItems[slot].refId)) + if (it != invStore.end()) { - equipmentChanged = true; - - equipedItems[slot].refId = it->getCellRef().getRefId(); - equipedItems[slot].charge = it->getCellRef().getCharge(); - if (slot == MWWorld::InventoryStore::Slot_CarriedRight) + if (!::Misc::StringUtils::ciEqual(it->getCellRef().getRefId(), equipedItems[slot].refId)) { - MWMechanics::WeaponType weaptype; - MWMechanics::getActiveWeapon(player.getClass().getCreatureStats(player), player.getClass().getInventoryStore(player), &weaptype); - if (weaptype != MWMechanics::WeapType_Thrown) - equipedItems[slot].count = 1; + equipmentChanged = true; + + item.refId = it->getCellRef().getRefId(); + item.charge = it->getCellRef().getCharge(); + if (slot == MWWorld::InventoryStore::Slot_CarriedRight) + { + MWMechanics::WeaponType weaptype; + MWMechanics::getActiveWeapon(player.getClass().getCreatureStats(player), + player.getClass().getInventoryStore(player), &weaptype); + if (weaptype != MWMechanics::WeapType_Thrown) + item.count = 1; + } + else + item.count = invStore.count(it->getCellRef().getRefId()); } - else - equipedItems[slot].count = invStore.count(it->getCellRef().getRefId()); } - else if (it == invStore.end() && !equipedItems[slot].refId.empty()) + else if (!item.refId.empty()) { equipmentChanged = true; - equipedItems[slot].refId = ""; - equipedItems[slot].count = 0; - equipedItems[slot].charge = 0; + item.refId = ""; + item.count = 0; + item.charge = 0; } }