mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-05-08 12:11:28 +00:00
[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.
This commit is contained in:
parent
76ac905efc
commit
343dd8b5ea
1 changed files with 6 additions and 1 deletions
|
@ -675,6 +675,7 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate)
|
||||||
void LocalPlayer::addItems()
|
void LocalPlayer::addItems()
|
||||||
{
|
{
|
||||||
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
||||||
|
const MWWorld::ESMStore &esmStore = MWBase::Environment::get().getWorld()->getStore();
|
||||||
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
|
MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer);
|
||||||
|
|
||||||
for (const auto &item : inventoryChanges.items)
|
for (const auto &item : inventoryChanges.items)
|
||||||
|
@ -685,7 +686,9 @@ void LocalPlayer::addItems()
|
||||||
|
|
||||||
try
|
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)
|
if (item.charge != -1)
|
||||||
itemPtr.getCellRef().setCharge(item.charge);
|
itemPtr.getCellRef().setCharge(item.charge);
|
||||||
|
|
||||||
|
@ -694,6 +697,8 @@ void LocalPlayer::addItems()
|
||||||
|
|
||||||
if (!item.soul.empty())
|
if (!item.soul.empty())
|
||||||
itemPtr.getCellRef().setSoul(item.soul);
|
itemPtr.getCellRef().setSoul(item.soul);
|
||||||
|
|
||||||
|
ptrStore.add(itemPtr, item.count, ptrPlayer);
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue