Transfer item ownership to the buyer if item wasn't stolen (Fixes #1933)

This commit is contained in:
scrawl 2014-09-21 18:01:52 +02:00
parent 45b4304237
commit 5d77c5e8ca
4 changed files with 10 additions and 7 deletions

View file

@ -76,7 +76,7 @@ MWWorld::Ptr ContainerItemModel::copyItem (const ItemStack& item, size_t count,
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1]; const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source)) if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source))
throw std::runtime_error("Item to copy needs to be from a different container!"); throw std::runtime_error("Item to copy needs to be from a different container!");
return *source.getClass().getContainerStore(source).add(item.mBase, count, source); return *source.getClass().getContainerStore(source).add(item.mBase, count, source, setNewOwner);
} }
void ContainerItemModel::removeItem (const ItemStack& item, size_t count) void ContainerItemModel::removeItem (const ItemStack& item, size_t count)

View file

@ -119,7 +119,7 @@ namespace MWGui
return mBorrowedToUs; return mBorrowedToUs;
} }
void TradeItemModel::transferItems() void TradeItemModel::transferItems(const MWWorld::Ptr& transferFrom)
{ {
std::vector<ItemStack>::iterator it = mBorrowedToUs.begin(); std::vector<ItemStack>::iterator it = mBorrowedToUs.begin();
for (; it != mBorrowedToUs.end(); ++it) for (; it != mBorrowedToUs.end(); ++it)
@ -135,9 +135,11 @@ namespace MWGui
if (i == sourceModel->getItemCount()) if (i == sourceModel->getItemCount())
throw std::runtime_error("The borrowed item disappeared"); throw std::runtime_error("The borrowed item disappeared");
// reset owner while copying, but only for items bought by the player
bool setNewOwner = (mMerchant.isEmpty());
const ItemStack& item = sourceModel->getItem(i); const ItemStack& item = sourceModel->getItem(i);
bool setNewOwner = Misc::StringUtils::ciEqual(item.mBase.getCellRef().getOwner(), transferFrom.getCellRef().getRefId())
|| item.mBase.getCellRef().getOwner().empty();
// copy the borrowed items to our model // copy the borrowed items to our model
copyItem(item, it->mCount, setNewOwner); copyItem(item, it->mCount, setNewOwner);
// then remove them from the source model // then remove them from the source model

View file

@ -30,7 +30,8 @@ namespace MWGui
void returnItemBorrowedFromUs (ModelIndex itemIndex, ItemModel* source, size_t count); void returnItemBorrowedFromUs (ModelIndex itemIndex, ItemModel* source, size_t count);
/// Permanently transfers items that were borrowed to us from another model to this model /// Permanently transfers items that were borrowed to us from another model to this model
void transferItems (); /// @param transferFrom the actor that lent us the items
void transferItems (const MWWorld::Ptr& transferFrom);
/// Aborts trade /// Aborts trade
void abort(); void abort();

View file

@ -360,8 +360,8 @@ namespace MWGui
MWBase::Environment::get().getDialogueManager()->applyDispositionChange(iBarterSuccessDisposition); MWBase::Environment::get().getDialogueManager()->applyDispositionChange(iBarterSuccessDisposition);
// make the item transfer // make the item transfer
mTradeModel->transferItems(); mTradeModel->transferItems(player);
playerItemModel->transferItems(); playerItemModel->transferItems(mPtr);
// transfer the gold // transfer the gold
if (mCurrentBalance != 0) if (mCurrentBalance != 0)