Merge pull request #1395 from akortunov/tradeconfiscatefix

Confiscate an item when you try to sell it to its owner
pull/280/head
scrawl 7 years ago committed by GitHub
commit 24eaced7d2

@ -241,6 +241,8 @@ namespace MWBase
virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) = 0;
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;
};
}

@ -360,8 +360,9 @@ namespace MWGui
if (msg.find("%s") != std::string::npos)
msg.replace(msg.find("%s"), 2, item.getClass().getName(item));
MWBase::Environment::get().getWindowManager()->messageBox(msg);
MWBase::Environment::get().getMechanicsManager()->commitCrime(player, mPtr, MWBase::MechanicsManager::OT_Theft,
item.getClass().getValue(item), true);
MWBase::Environment::get().getMechanicsManager()->confiscateStolenItemToOwner(player, item, mPtr, 1);
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Enchanting);
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
return;

@ -311,9 +311,9 @@ namespace MWGui
if (msg.find("%s") != std::string::npos)
msg.replace(msg.find("%s"), 2, it->mBase.getClass().getName(it->mBase));
MWBase::Environment::get().getWindowManager()->messageBox(msg);
MWBase::Environment::get().getMechanicsManager()->commitCrime(player, mPtr, MWBase::MechanicsManager::OT_Theft,
it->mBase.getClass().getValue(it->mBase)
* it->mCount, true);
MWBase::Environment::get().getMechanicsManager()->confiscateStolenItemToOwner(player, it->mBase, mPtr, it->mCount);
onCancelButtonClicked(mCancelButton);
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
return;

@ -907,6 +907,43 @@ namespace MWMechanics
return ownerFound != owners.end();
}
void MechanicsManager::confiscateStolenItemToOwner(const MWWorld::Ptr &player, const MWWorld::Ptr &item, const MWWorld::Ptr& victim, int count)
{
if (player != getPlayer())
return;
const std::string itemId = Misc::StringUtils::lowerCase(item.getCellRef().getRefId());
StolenItemsMap::iterator stolenIt = mStolenItems.find(itemId);
if (stolenIt == mStolenItems.end())
return;
Owner owner;
owner.first = victim.getCellRef().getRefId();
owner.second = false;
Misc::StringUtils::lowerCaseInPlace(owner.first);
// decrease count of stolen items
int toRemove = std::min(count, mStolenItems[itemId][owner]);
mStolenItems[itemId][owner] -= toRemove;
if (mStolenItems[itemId][owner] == 0)
{
// erase owner from stolen items owners
OwnerMap& owners = stolenIt->second;
OwnerMap::iterator ownersIt = owners.find(owner);
if (ownersIt != owners.end())
owners.erase(ownersIt);
}
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
// move items from player to owner and report about theft
victim.getClass().getContainerStore(victim).add(item, toRemove, victim);
store.remove(item, toRemove, player);
commitCrime(player, victim, OT_Theft, item.getClass().getValue(item) * toRemove);
}
void MechanicsManager::confiscateStolenItems(const MWWorld::Ptr &player, const MWWorld::Ptr &targetContainer)
{
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);

@ -206,6 +206,8 @@ namespace MWMechanics
virtual void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId);
virtual void confiscateStolenItemToOwner(const MWWorld::Ptr &player, const MWWorld::Ptr &item, const MWWorld::Ptr& victim, int count);
private:
void reportCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim,
OffenseType type, int arg=0);

Loading…
Cancel
Save