mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:23:54 +00:00
Merge pull request #1395 from akortunov/tradeconfiscatefix
Confiscate an item when you try to sell it to its owner
This commit is contained in:
commit
24eaced7d2
5 changed files with 47 additions and 5 deletions
|
@ -241,6 +241,8 @@ namespace MWBase
|
||||||
virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) = 0;
|
virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) = 0;
|
||||||
|
|
||||||
virtual void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId) = 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)
|
if (msg.find("%s") != std::string::npos)
|
||||||
msg.replace(msg.find("%s"), 2, item.getClass().getName(item));
|
msg.replace(msg.find("%s"), 2, item.getClass().getName(item));
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
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().getWindowManager()->removeGuiMode (GM_Enchanting);
|
||||||
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
|
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -311,9 +311,9 @@ namespace MWGui
|
||||||
if (msg.find("%s") != std::string::npos)
|
if (msg.find("%s") != std::string::npos)
|
||||||
msg.replace(msg.find("%s"), 2, it->mBase.getClass().getName(it->mBase));
|
msg.replace(msg.find("%s"), 2, it->mBase.getClass().getName(it->mBase));
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
MWBase::Environment::get().getWindowManager()->messageBox(msg);
|
||||||
MWBase::Environment::get().getMechanicsManager()->commitCrime(player, mPtr, MWBase::MechanicsManager::OT_Theft,
|
|
||||||
it->mBase.getClass().getValue(it->mBase)
|
MWBase::Environment::get().getMechanicsManager()->confiscateStolenItemToOwner(player, it->mBase, mPtr, it->mCount);
|
||||||
* it->mCount, true);
|
|
||||||
onCancelButtonClicked(mCancelButton);
|
onCancelButtonClicked(mCancelButton);
|
||||||
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
|
MWBase::Environment::get().getDialogueManager()->goodbyeSelected();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -907,6 +907,43 @@ namespace MWMechanics
|
||||||
return ownerFound != owners.end();
|
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)
|
void MechanicsManager::confiscateStolenItems(const MWWorld::Ptr &player, const MWWorld::Ptr &targetContainer)
|
||||||
{
|
{
|
||||||
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
|
MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
|
||||||
|
|
|
@ -206,6 +206,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
virtual void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId);
|
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:
|
private:
|
||||||
void reportCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim,
|
void reportCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim,
|
||||||
OffenseType type, int arg=0);
|
OffenseType type, int arg=0);
|
||||||
|
|
Loading…
Reference in a new issue