Handle item owners during pickpocketing

pull/1549/head
Andrei Kortunov 7 years ago
parent 3694b6ec90
commit a02124f884

@ -140,7 +140,7 @@ namespace MWBase
/// Utility to check if taking this item is illegal and calling commitCrime if so
/// @param container The container the item is in; may be empty for an item in the world
virtual void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, const MWWorld::Ptr& container,
int count) = 0;
int count, bool alarm = true) = 0;
/// Utility to check if opening (i.e. unlocking) this object is illegal and calling commitCrime if so
virtual void objectOpened (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item) = 0;
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.
@ -250,7 +250,6 @@ namespace MWBase
virtual void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId) = 0;
virtual void confiscateStolenItemToOwner(const MWWorld::Ptr &player, const MWWorld::Ptr &item, const MWWorld::Ptr& victim, int count) = 0;
virtual bool isAttackPrepairing(const MWWorld::Ptr& ptr) = 0;
virtual bool isRunning(const MWWorld::Ptr& ptr) = 0;
virtual bool isSneaking(const MWWorld::Ptr& ptr) = 0;

@ -7,6 +7,7 @@
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/pickpocket.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/class.hpp"
#include "../mwbase/environment.hpp"
@ -76,7 +77,6 @@ namespace MWGui
void PickpocketItemModel::removeItem (const ItemStack &item, size_t count)
{
ProxyItemModel::removeItem(item, count);
/// \todo check if player is detected
}
bool PickpocketItemModel::allowedToInsertItems() const
@ -115,7 +115,14 @@ namespace MWGui
if (mActor.getClass().getCreatureStats(mActor).getKnockedDown())
return mSourceModel->onTakeItem(item, count);
return stealItem(item, count);
bool success = stealItem(item, count);
if (success)
{
MWWorld::Ptr player = MWMechanics::getPlayer();
MWBase::Environment::get().getMechanicsManager()->itemTaken(player, item, mActor, count, false);
}
return success;
}
bool PickpocketItemModel::stealItem(const MWWorld::Ptr &item, int count)

@ -1024,7 +1024,7 @@ namespace MWMechanics
}
void MechanicsManager::itemTaken(const MWWorld::Ptr &ptr, const MWWorld::Ptr &item, const MWWorld::Ptr& container,
int count)
int count, bool alarm)
{
if (ptr != getPlayer())
return;
@ -1053,19 +1053,29 @@ namespace MWMechanics
return;
Owner owner;
owner.first = ownerCellRef->getOwner();
owner.second = false;
if (owner.first.empty())
if (!container.isEmpty() && container.getClass().isActor())
{
owner.first = ownerCellRef->getFaction();
owner.second = true;
// "container" is an actor inventory, so just take actor's ID
owner.first = ownerCellRef->getRefId();
}
else
{
owner.first = ownerCellRef->getOwner();
if (owner.first.empty())
{
owner.first = ownerCellRef->getFaction();
owner.second = true;
}
}
Misc::StringUtils::lowerCaseInPlace(owner.first);
if (!Misc::StringUtils::ciEqual(item.getCellRef().getRefId(), MWWorld::ContainerStore::sGoldId))
mStolenItems[Misc::StringUtils::lowerCase(item.getCellRef().getRefId())][owner] += count;
commitCrime(ptr, victim, OT_Theft, item.getClass().getValue(item) * count);
if (alarm)
commitCrime(ptr, victim, OT_Theft, item.getClass().getValue(item) * count);
}

@ -135,7 +135,7 @@ namespace MWMechanics
/// Utility to check if taking this item is illegal and calling commitCrime if so
/// @param container The container the item is in; may be empty for an item in the world
virtual void itemTaken (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item, const MWWorld::Ptr& container,
int count);
int count, bool alarm = true);
/// Utility to check if opening (i.e. unlocking) this object is illegal and calling commitCrime if so
virtual void objectOpened (const MWWorld::Ptr& ptr, const MWWorld::Ptr& item);
/// Attempt sleeping in a bed. If this is illegal, call commitCrime.

Loading…
Cancel
Save