1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 07:53:53 +00:00

Rework 'prevent merchant equipping' feature

This commit is contained in:
Andrei Kortunov 2019-10-12 14:00:36 +04:00
parent 1a610d3f72
commit 31e78ed41f
3 changed files with 51 additions and 23 deletions

View file

@ -298,10 +298,31 @@ namespace MWMechanics
bool wasEquipped = currentItem != store.end() && Misc::StringUtils::ciEqual(currentItem->getCellRef().getRefId(), itemId); bool wasEquipped = currentItem != store.end() && Misc::StringUtils::ciEqual(currentItem->getCellRef().getRefId(), itemId);
store.remove(itemId, 1, actor, true); store.remove(itemId, 1, actor);
if (actor != MWMechanics::getPlayer()) if (actor != MWMechanics::getPlayer())
{
// Equip a replacement
if (!wasEquipped)
return;
std::string type = currentItem->getTypeName();
if (type != typeid(ESM::Weapon).name() && type != typeid(ESM::Armor).name() && type != typeid(ESM::Clothing).name())
return;
if (actor.getClass().getCreatureStats(actor).isDead())
return;
if (!actor.getClass().hasInventoryStore(actor) || !actor.getClass().getInventoryStore(actor).canActorAutoEquip(actor))
return;
if (actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
return;
actor.getClass().getInventoryStore(actor).autoEquip(actor);
return; return;
}
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
std::string prevItemId = player.getPreviousItem(itemId); std::string prevItemId = player.getPreviousItem(itemId);
@ -1199,7 +1220,7 @@ namespace MWMechanics
heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft); heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
// If we have a torch and can equip it, then equip it now. // If we have a torch and can equip it, then equip it now.
if (heldIter == inventoryStore.end()) if (heldIter == inventoryStore.end() && inventoryStore.canActorAutoEquip(ptr))
{ {
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, torch, ptr); inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, torch, ptr);
} }
@ -1808,6 +1829,8 @@ namespace MWMechanics
// Make sure spell effects are removed // Make sure spell effects are removed
purgeSpellEffects(stats.getActorId()); purgeSpellEffects(stats.getActorId());
calculateCreatureStatModifiers(iter->first, 0);
if( iter->first == getPlayer()) if( iter->first == getPlayer())
{ {
//player's death animation is over //player's death animation is over

View file

@ -135,7 +135,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr,
{ {
const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, count, actorPtr); const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, count, actorPtr);
// Auto-equip items if an armor/clothing or weapon item is added, but not for the player nor werewolves // Auto-equip items if an armor/clothing item is added, but not for the player nor werewolves
if (actorPtr != MWMechanics::getPlayer() if (actorPtr != MWMechanics::getPlayer()
&& actorPtr.getClass().isNpc() && !actorPtr.getClass().getNpcStats(actorPtr).isWerewolf()) && actorPtr.getClass().isNpc() && !actorPtr.getClass().getNpcStats(actorPtr).isWerewolf())
{ {
@ -208,22 +208,29 @@ MWWorld::ConstContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
return findSlot (slot); return findSlot (slot);
} }
bool MWWorld::InventoryStore::canActorAutoEquip(const MWWorld::Ptr& actor, const MWWorld::Ptr& item) bool MWWorld::InventoryStore::canActorAutoEquip(const MWWorld::Ptr& actor)
{ {
if (!Settings::Manager::getBool("prevent merchant equipping", "Game")) // Treat player as non-trader indifferently from service flags.
if (actor == MWMechanics::getPlayer())
return true; return true;
// Only autoEquip if we are the original owner of the item. static const bool prevent = Settings::Manager::getBool("prevent merchant equipping", "Game");
// This stops merchants from auto equipping anything you sell to them. if (!prevent)
// ...unless this is a companion, he should always equip items given to him. return true;
if (!Misc::StringUtils::ciEqual(item.getCellRef().getOwner(), actor.getCellRef().getRefId()) &&
(actor.getClass().getScript(actor).empty() || // Corpses can be dressed up by the player as desired.
!actor.getRefData().getLocals().getIntVar(actor.getClass().getScript(actor), "companion")) if (actor.getClass().getCreatureStats(actor).isDead())
&& !actor.getClass().getCreatureStats(actor).isDead() // Corpses can be dressed up by the player as desired return true;
)
{ // Companions can autoequip items.
return false; if (!actor.getClass().getScript(actor).empty() &&
} actor.getRefData().getLocals().getIntVar(actor.getClass().getScript(actor), "companion"))
return true;
// If the actor is trader, he can auto-equip items only during initial auto-equipping
int services = actor.getClass().getServices(actor);
if (services & ESM::NPC::AllItems)
return mFirstAutoEquip;
return true; return true;
} }
@ -325,9 +332,6 @@ void MWWorld::InventoryStore::autoEquipWeapon (const MWWorld::Ptr& actor, TSlots
for (ContainerStoreIterator iter(begin(ContainerStore::Type_Weapon)); iter!=end(); ++iter) for (ContainerStoreIterator iter(begin(ContainerStore::Type_Weapon)); iter!=end(); ++iter)
{ {
if (!canActorAutoEquip(actor, *iter))
continue;
const ESM::Weapon* esmWeapon = iter->get<ESM::Weapon>()->mBase; const ESM::Weapon* esmWeapon = iter->get<ESM::Weapon>()->mBase;
if (MWMechanics::getWeaponType(esmWeapon->mData.mType)->mWeaponClass == ESM::WeaponType::Ammo) if (MWMechanics::getWeaponType(esmWeapon->mData.mType)->mWeaponClass == ESM::WeaponType::Ammo)
@ -429,9 +433,6 @@ void MWWorld::InventoryStore::autoEquipArmor (const MWWorld::Ptr& actor, TSlots&
{ {
Ptr test = *iter; Ptr test = *iter;
if (!canActorAutoEquip(actor, test))
continue;
switch(test.getClass().canBeEquipped (test, actor).first) switch(test.getClass().canBeEquipped (test, actor).first)
{ {
case 0: case 0:
@ -551,6 +552,9 @@ void MWWorld::InventoryStore::autoEquipShield(const MWWorld::Ptr& actor, TSlots&
void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor) void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
{ {
if (!canActorAutoEquip(actor))
return;
TSlots slots_; TSlots slots_;
initSlots (slots_); initSlots (slots_);

View file

@ -112,7 +112,6 @@ namespace MWWorld
virtual void storeEquipmentState (const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const; virtual void storeEquipmentState (const MWWorld::LiveCellRefBase& ref, int index, ESM::InventoryState& inventory) const;
virtual void readEquipmentState (const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory); virtual void readEquipmentState (const MWWorld::ContainerStoreIterator& iter, int index, const ESM::InventoryState& inventory);
bool canActorAutoEquip(const MWWorld::Ptr& actor, const MWWorld::Ptr& item);
ContainerStoreIterator findSlot (int slot) const; ContainerStoreIterator findSlot (int slot) const;
public: public:
@ -161,6 +160,8 @@ namespace MWWorld
void autoEquip (const MWWorld::Ptr& actor); void autoEquip (const MWWorld::Ptr& actor);
///< Auto equip items according to stats and item value. ///< Auto equip items according to stats and item value.
bool canActorAutoEquip(const MWWorld::Ptr& actor);
const MWMechanics::MagicEffects& getMagicEffects() const; const MWMechanics::MagicEffects& getMagicEffects() const;
///< Return magic effects from worn items. ///< Return magic effects from worn items.