[Client] Fix addition of items to player inventories

Previously, multiple stacks of the same item ID could overwrite data in each other because of how the logic in ContainerStore::add() works. For example, a stack of 5 grand soul gems with no souls would get added to the player, then the attempt to add a grand soul gem with a particular soul would retrieve the previous stack first before setting all of it to that soul, resulting in 6 grand soul gems with that soul.
experimental-mono
David Cernat 5 years ago
parent 76ac905efc
commit 343dd8b5ea

@ -675,6 +675,7 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
void LocalPlayer::addItems()
{
MWWorld::Ptr ptrPlayer = getPlayerPtr();
const MWWorld::ESMStore &esmStore = MWBase::Environment::get().getWorld()->getStore();
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
for (const auto &item : inventoryChanges.items)
@ -685,7 +686,9 @@ void LocalPlayer::addItems()
try
{
MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer);
MWWorld::ManualRef itemRef(esmStore, item.refId, item.count);
MWWorld::Ptr itemPtr = itemRef.getPtr();
if (item.charge != -1)
itemPtr.getCellRef().setCharge(item.charge);
@ -694,6 +697,8 @@ void LocalPlayer::addItems()
if (!item.soul.empty())
itemPtr.getCellRef().setSoul(item.soul);
ptrStore.add(itemPtr, item.count, ptrPlayer);
}
catch (std::exception&)
{

Loading…
Cancel
Save