1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-02 04:15:34 +00:00

Fixes #1100: Looting a corpse is no longer considered stealing

This commit is contained in:
scrawl 2014-04-27 05:40:07 +02:00
parent e8210c92c6
commit 93b76a603b
11 changed files with 62 additions and 26 deletions

View file

@ -10,7 +10,7 @@ namespace MWGui
{ {
} }
void CompanionItemModel::copyItem (const ItemStack& item, size_t count) void CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
{ {
if (mActor.getClass().isNpc()) if (mActor.getClass().isNpc())
{ {
@ -18,7 +18,7 @@ namespace MWGui
stats.modifyProfit(MWWorld::Class::get(item.mBase).getValue(item.mBase) * count); stats.modifyProfit(MWWorld::Class::get(item.mBase).getValue(item.mBase) * count);
} }
InventoryItemModel::copyItem(item, count); InventoryItemModel::copyItem(item, count, setNewOwner);
} }
void CompanionItemModel::removeItem (const ItemStack& item, size_t count) void CompanionItemModel::removeItem (const ItemStack& item, size_t count)

View file

@ -13,7 +13,7 @@ namespace MWGui
public: public:
CompanionItemModel (const MWWorld::Ptr& actor); CompanionItemModel (const MWWorld::Ptr& actor);
virtual void copyItem (const ItemStack& item, size_t count); virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
}; };

View file

@ -13,6 +13,7 @@
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwmechanics/pickpocket.hpp" #include "../mwmechanics/pickpocket.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "countdialog.hpp" #include "countdialog.hpp"
#include "tradewindow.hpp" #include "tradewindow.hpp"
@ -84,8 +85,7 @@ namespace MWGui
// otherwise, do the transfer // otherwise, do the transfer
if (targetModel != mSourceModel) if (targetModel != mSourceModel)
{ {
targetModel->copyItem(mItem, mDraggedCount); mSourceModel->moveItem(mItem, mDraggedCount, targetModel);
mSourceModel->removeItem(mItem, mDraggedCount);
} }
mSourceModel->update(); mSourceModel->update();
@ -292,8 +292,7 @@ namespace MWGui
if (!onTakeItem(item, item.mCount)) if (!onTakeItem(item, item.mCount))
break; break;
playerModel->copyItem(item, item.mCount); mModel->moveItem(item, item.mCount, playerModel);
mModel->removeItem(item, item.mCount);
} }
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
@ -341,7 +340,11 @@ namespace MWGui
} }
else else
{ {
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item.mBase, count); // Looting a dead corpse is considered OK
if (mPtr.getClass().isActor() && mPtr.getClass().getCreatureStats(mPtr).isDead())
return true;
else
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item.mBase, count);
} }
return true; return true;
} }

View file

@ -71,7 +71,7 @@ ItemModel::ModelIndex ContainerItemModel::getIndex (ItemStack item)
return -1; return -1;
} }
void ContainerItemModel::copyItem (const ItemStack& item, size_t count) void ContainerItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{ {
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))

View file

@ -21,7 +21,7 @@ namespace MWGui
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);
virtual size_t getItemCount(); virtual size_t getItemCount();
virtual void copyItem (const ItemStack& item, size_t count); virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
virtual void update(); virtual void update();

View file

@ -4,6 +4,8 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/creaturestats.hpp"
namespace MWGui namespace MWGui
{ {
@ -38,11 +40,11 @@ ItemModel::ModelIndex InventoryItemModel::getIndex (ItemStack item)
return -1; return -1;
} }
void InventoryItemModel::copyItem (const ItemStack& item, size_t count) void InventoryItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{ {
if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor)) if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
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!");
mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor); mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor, setNewOwner);
} }
@ -57,6 +59,18 @@ void InventoryItemModel::removeItem (const ItemStack& item, size_t count)
throw std::runtime_error("Not enough items in the stack to remove"); throw std::runtime_error("Not enough items in the stack to remove");
} }
void InventoryItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)
{
bool setNewOwner = false;
// Are you dead? Then you wont need that anymore
if (mActor.getClass().isActor() && mActor.getClass().getCreatureStats(mActor).isDead())
setNewOwner = true;
otherModel->copyItem(item, count, setNewOwner);
removeItem(item, count);
}
void InventoryItemModel::update() void InventoryItemModel::update()
{ {
MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor); MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor);

View file

@ -15,9 +15,12 @@ namespace MWGui
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);
virtual size_t getItemCount(); virtual size_t getItemCount();
virtual void copyItem (const ItemStack& item, size_t count); virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
/// Move items from this model to \a otherModel.
virtual void moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
virtual void update(); virtual void update();
protected: protected:

View file

@ -71,16 +71,22 @@ namespace MWGui
{ {
} }
void ItemModel::moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)
{
otherModel->copyItem(item, count);
removeItem(item, count);
}
ProxyItemModel::~ProxyItemModel() ProxyItemModel::~ProxyItemModel()
{ {
delete mSourceModel; delete mSourceModel;
} }
void ProxyItemModel::copyItem (const ItemStack& item, size_t count) void ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner)
{ {
// no need to use mapToSource since itemIndex refers to an index in the sourceModel // no need to use mapToSource since itemIndex refers to an index in the sourceModel
mSourceModel->copyItem (item, count); mSourceModel->copyItem (item, count, setNewOwner);
} }
void ProxyItemModel::removeItem (const ItemStack& item, size_t count) void ProxyItemModel::removeItem (const ItemStack& item, size_t count)

View file

@ -55,7 +55,11 @@ namespace MWGui
virtual void update() = 0; virtual void update() = 0;
virtual void copyItem (const ItemStack& item, size_t count) = 0; /// Move items from this model to \a otherModel.
virtual void moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
/// @param setNewOwner Set the copied item's owner to the actor we are copying to, or keep the original owner?
virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0;
virtual void removeItem (const ItemStack& item, size_t count) = 0; virtual void removeItem (const ItemStack& item, size_t count) = 0;
private: private:
@ -69,7 +73,7 @@ namespace MWGui
{ {
public: public:
virtual ~ProxyItemModel(); virtual ~ProxyItemModel();
virtual void copyItem (const ItemStack& item, size_t count); virtual void copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
virtual void removeItem (const ItemStack& item, size_t count); virtual void removeItem (const ItemStack& item, size_t count);
virtual ModelIndex getIndex (ItemStack item); virtual ModelIndex getIndex (ItemStack item);

View file

@ -120,14 +120,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 before copying // 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);
std::string owner = item.mBase.getCellRef().mOwner;
if (mMerchant.isEmpty()) // only for items bought by player
item.mBase.getCellRef().mOwner = "";
// copy the borrowed items to our model // copy the borrowed items to our model
copyItem(item, it->mCount); copyItem(item, it->mCount, setNewOwner);
item.mBase.getCellRef().mOwner = owner;
// then remove them from the source model // then remove them from the source model
sourceModel->removeItem(item, it->mCount); sourceModel->removeItem(item, it->mCount);
} }

View file

@ -199,16 +199,25 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr
item.getCellRef().mPos.pos[1] = 0; item.getCellRef().mPos.pos[1] = 0;
item.getCellRef().mPos.pos[2] = 0; item.getCellRef().mPos.pos[2] = 0;
Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
if (setOwner && actorPtr.getClass().isActor()) if (setOwner && actorPtr.getClass().isActor())
item.getCellRef().mOwner = actorPtr.getCellRef().mRefID; {
if (actorPtr == player)
{
// No point in setting owner to the player - NPCs will not respect this anyway
// Additionally, setting it to "player" would make those items not stack with items that don't have an owner
item.getCellRef().mOwner = "";
}
else
item.getCellRef().mOwner = actorPtr.getCellRef().mRefID;
}
std::string script = MWWorld::Class::get(item).getScript(item); std::string script = MWWorld::Class::get(item).getScript(item);
if(script != "") if(script != "")
{ {
CellStore *cell; CellStore *cell;
Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
if(&(MWWorld::Class::get (player).getContainerStore (player)) == this) if(&(MWWorld::Class::get (player).getContainerStore (player)) == this)
{ {
cell = 0; // Items in player's inventory have cell set to 0, so their scripts will never be removed cell = 0; // Items in player's inventory have cell set to 0, so their scripts will never be removed