From 20caea083aa9af84ae723be15eae7151dab7614f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 12 Mar 2018 23:31:37 +0200 Subject: [PATCH] [Client] Use correct count for items in equipment packets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, throwing weapon sync was completely broken for players, as the count for their equipped throwing weapons was never set and – as a result – defaulted to a count of 1 on other clients. As a result, any time a player threw a dart, they would then appear as having switched to hand-to-hand for other players. Moreover, the count of equipped items was mistakenly based on the total count of items with that refId in the inventory. As a result, if – for example – I equipped 1 Daedric Longsword and had 4 others in my inventory, my DedicatedPlayer on other clients would equip a Daedric Longsword with a count of 5. If I was overencumbered by having that many Daedric Longswords on me and then dropped 4 of them, allowing myself to move again, my DedicatedPlayer would still walk around with 5 Daedric Longswords and lack animations due to still being overencumbered on the other clients. These problems were less prevalent for actors, but their equipment updating code has also been changed to match that of players. --- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwmp/LocalActor.cpp | 15 ++++----------- apps/openmw/mwmp/LocalPlayer.cpp | 12 +----------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 26efa0a99..e1030c4a4 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -964,7 +964,7 @@ namespace MWMechanics Start of tes3mp change (major) We need DedicatedPlayers and DedicatedActors to not automatically - equip their light-emitting items, so additions conditions have been + equip their light-emitting items, so additional conditions have been added for them */ if (!isPlayer && !mwmp::PlayerList::isDedicatedPlayer(ptr) && !mwmp::Main::get().getCellController()->isDedicatedActor(ptr)) diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index 7c4143517..ac474776e 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -193,8 +193,8 @@ void LocalActor::updateEquipment(bool forceUpdate) MWWorld::InventoryStore &invStore = ptr.getClass().getInventoryStore(ptr); for (int slot = 0; slot < MWWorld::InventoryStore::Slots; slot++) { - MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); auto &item = equipedItems[slot]; + MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); if (it != invStore.end()) { @@ -205,16 +205,8 @@ void LocalActor::updateEquipment(bool forceUpdate) 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()); + item.enchantmentCharge = it->getCellRef().getEnchantmentCharge(); + item.count = it->getRefData().getCount(); } } else if (!item.refId.empty()) @@ -223,6 +215,7 @@ void LocalActor::updateEquipment(bool forceUpdate) item.refId = ""; item.count = 0; item.charge = 0; + item.enchantmentCharge = -1; } } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index c70b2e499..28439a773 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -471,17 +471,7 @@ 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; - MWMechanics::getActiveWeapon(ptrPlayer.getClass().getCreatureStats(ptrPlayer), - ptrPlayer.getClass().getInventoryStore(ptrPlayer), &weaptype); - if (weaptype != MWMechanics::WeapType_Thrown) - item.count = 1; - } - else - item.count = invStore.count(it->getCellRef().getRefId()); + item.count = it->getRefData().getCount(); } } else if (!item.refId.empty())