[Client] Don't add bound items to inventory as a result of item packets

Additionally, don't include bound items when sending PlayerInventory packets.
This commit is contained in:
David Cernat 2018-08-11 16:05:37 +03:00
parent a3b9274365
commit 9598212aad

View file

@ -677,6 +677,10 @@ void LocalPlayer::addItems()
for (const auto &item : inventoryChanges.items) for (const auto &item : inventoryChanges.items)
{ {
// Skip bound items
if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(item.refId))
continue;
try try
{ {
MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer); MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer);
@ -1116,17 +1120,21 @@ void LocalPlayer::setEquipment()
return Misc::StringUtils::ciEqual(itemPtr.getCellRef().getRefId(), currentItem.refId); return Misc::StringUtils::ciEqual(itemPtr.getCellRef().getRefId(), currentItem.refId);
}); });
if (it == ptrInventory.end()) // If the item is not in our inventory, add it // If the item is not in our inventory, add it as long as it's not a bound item
if (it == ptrInventory.end())
{ {
try if (!MWBase::Environment::get().getMechanicsManager()->isBoundItem(currentItem.refId))
{ {
auto addIter = ptrInventory.ContainerStore::add(currentItem.refId.c_str(), currentItem.count, ptrPlayer); try
{
auto addIter = ptrInventory.ContainerStore::add(currentItem.refId.c_str(), currentItem.count, ptrPlayer);
ptrInventory.equip(slot, addIter, ptrPlayer); ptrInventory.equip(slot, addIter, ptrPlayer);
} }
catch (std::exception&) catch (std::exception&)
{ {
LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid equipment item %s", currentItem.refId.c_str()); LOG_APPEND(Log::LOG_INFO, "- Ignored addition of invalid equipment item %s", currentItem.refId.c_str());
}
} }
} }
else else
@ -1368,7 +1376,13 @@ void LocalPlayer::sendInventory()
for (const auto &iter : ptrInventory) for (const auto &iter : ptrInventory)
{ {
item.refId = iter.getCellRef().getRefId(); item.refId = iter.getCellRef().getRefId();
if (item.refId.find("$dynamic") != string::npos) // skip generated items (self enchanted for e.g.)
// Skip any items that somehow have clientside-only dynamic IDs
if (item.refId.find("$dynamic") != string::npos)
continue;
// Skip bound items
if (MWBase::Environment::get().getMechanicsManager()->isBoundItem(item.refId))
continue; continue;
item.count = iter.getRefData().getCount(); item.count = iter.getRefData().getCount();