mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Fixes #1100: Looting a corpse is no longer considered stealing
This commit is contained in:
parent
e8210c92c6
commit
93b76a603b
11 changed files with 62 additions and 26 deletions
|
@ -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())
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace MWGui
|
|||
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)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace MWGui
|
|||
public:
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "../mwworld/containerstore.hpp"
|
||||
|
||||
#include "../mwmechanics/pickpocket.hpp"
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
|
||||
#include "countdialog.hpp"
|
||||
#include "tradewindow.hpp"
|
||||
|
@ -84,8 +85,7 @@ namespace MWGui
|
|||
// otherwise, do the transfer
|
||||
if (targetModel != mSourceModel)
|
||||
{
|
||||
targetModel->copyItem(mItem, mDraggedCount);
|
||||
mSourceModel->removeItem(mItem, mDraggedCount);
|
||||
mSourceModel->moveItem(mItem, mDraggedCount, targetModel);
|
||||
}
|
||||
|
||||
mSourceModel->update();
|
||||
|
@ -292,8 +292,7 @@ namespace MWGui
|
|||
if (!onTakeItem(item, item.mCount))
|
||||
break;
|
||||
|
||||
playerModel->copyItem(item, item.mCount);
|
||||
mModel->removeItem(item, item.mCount);
|
||||
mModel->moveItem(item, item.mCount, playerModel);
|
||||
}
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Container);
|
||||
|
@ -341,7 +340,11 @@ namespace MWGui
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ ItemModel::ModelIndex ContainerItemModel::getIndex (ItemStack item)
|
|||
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];
|
||||
if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source))
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace MWGui
|
|||
virtual ModelIndex getIndex (ItemStack item);
|
||||
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 update();
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
|
@ -38,11 +40,11 @@ ItemModel::ModelIndex InventoryItemModel::getIndex (ItemStack item)
|
|||
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))
|
||||
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");
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
MWWorld::ContainerStore& store = MWWorld::Class::get(mActor).getContainerStore(mActor);
|
||||
|
|
|
@ -15,9 +15,12 @@ namespace MWGui
|
|||
virtual ModelIndex getIndex (ItemStack item);
|
||||
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);
|
||||
|
||||
/// Move items from this model to \a otherModel.
|
||||
virtual void moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
|
||||
|
||||
virtual void update();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
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
|
||||
mSourceModel->copyItem (item, count);
|
||||
mSourceModel->copyItem (item, count, setNewOwner);
|
||||
}
|
||||
|
||||
void ProxyItemModel::removeItem (const ItemStack& item, size_t count)
|
||||
|
|
|
@ -55,7 +55,11 @@ namespace MWGui
|
|||
|
||||
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;
|
||||
|
||||
private:
|
||||
|
@ -69,7 +73,7 @@ namespace MWGui
|
|||
{
|
||||
public:
|
||||
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 ModelIndex getIndex (ItemStack item);
|
||||
|
||||
|
|
|
@ -120,14 +120,11 @@ namespace MWGui
|
|||
if (i == sourceModel->getItemCount())
|
||||
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);
|
||||
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
|
||||
copyItem(item, it->mCount);
|
||||
item.mBase.getCellRef().mOwner = owner;
|
||||
copyItem(item, it->mCount, setNewOwner);
|
||||
// then remove them from the source model
|
||||
sourceModel->removeItem(item, it->mCount);
|
||||
}
|
||||
|
|
|
@ -199,16 +199,25 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr
|
|||
item.getCellRef().mPos.pos[1] = 0;
|
||||
item.getCellRef().mPos.pos[2] = 0;
|
||||
|
||||
Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
||||
|
||||
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);
|
||||
if(script != "")
|
||||
{
|
||||
CellStore *cell;
|
||||
|
||||
Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue