mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-28 08:09:39 +00:00
Rework prevent merchant equipping setting again
This commit is contained in:
parent
b948101a73
commit
ee4fa93bd4
15 changed files with 26 additions and 63 deletions
|
@ -25,12 +25,12 @@ namespace MWGui
|
|||
{
|
||||
}
|
||||
|
||||
MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count)
|
||||
MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool allowAutoEquip)
|
||||
{
|
||||
if (hasProfit(mActor))
|
||||
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count);
|
||||
|
||||
return InventoryItemModel::copyItem(item, count);
|
||||
return InventoryItemModel::copyItem(item, count, allowAutoEquip);
|
||||
}
|
||||
|
||||
void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace MWGui
|
|||
public:
|
||||
CompanionItemModel (const MWWorld::Ptr& actor);
|
||||
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count);
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool allowAutoEquip = true);
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
|
||||
bool hasProfit(const MWWorld::Ptr& actor);
|
||||
|
|
|
@ -91,12 +91,12 @@ ItemModel::ModelIndex ContainerItemModel::getIndex (ItemStack item)
|
|||
return -1;
|
||||
}
|
||||
|
||||
MWWorld::Ptr ContainerItemModel::copyItem (const ItemStack& item, size_t count)
|
||||
MWWorld::Ptr ContainerItemModel::copyItem (const ItemStack& item, size_t count, bool allowAutoEquip)
|
||||
{
|
||||
const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1];
|
||||
if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source))
|
||||
throw std::runtime_error("Item to copy needs to be from a different container!");
|
||||
return *source.getClass().getContainerStore(source).add(item.mBase, count, source);
|
||||
return *source.getClass().getContainerStore(source).add(item.mBase, count, source, allowAutoEquip);
|
||||
}
|
||||
|
||||
void ContainerItemModel::removeItem (const ItemStack& item, size_t count)
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace MWGui
|
|||
virtual ModelIndex getIndex (ItemStack item);
|
||||
virtual size_t getItemCount();
|
||||
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count);
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool allowAutoEquip = true);
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
|
||||
virtual void update();
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace MWGui
|
|||
public:
|
||||
WorldItemModel(float left, float top) : mLeft(left), mTop(top) {}
|
||||
virtual ~WorldItemModel() {}
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count)
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool /*allowAutoEquip*/)
|
||||
{
|
||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||
|
||||
|
|
|
@ -46,11 +46,11 @@ ItemModel::ModelIndex InventoryItemModel::getIndex (ItemStack item)
|
|||
return -1;
|
||||
}
|
||||
|
||||
MWWorld::Ptr InventoryItemModel::copyItem (const ItemStack& item, size_t count)
|
||||
MWWorld::Ptr InventoryItemModel::copyItem (const ItemStack& item, size_t count, bool allowAutoEquip)
|
||||
{
|
||||
if (item.mBase.getContainerStore() == &mActor.getClass().getContainerStore(mActor))
|
||||
throw std::runtime_error("Item to copy needs to be from a different container!");
|
||||
return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor);
|
||||
return *mActor.getClass().getContainerStore(mActor).add(item.mBase, count, mActor, allowAutoEquip);
|
||||
}
|
||||
|
||||
void InventoryItemModel::removeItem (const ItemStack& item, size_t count)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MWGui
|
|||
|
||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
|
||||
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count);
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool allowAutoEquip = true);
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
|
||||
/// Move items from this model to \a otherModel.
|
||||
|
|
|
@ -116,9 +116,9 @@ namespace MWGui
|
|||
return mSourceModel->allowedToUseItems();
|
||||
}
|
||||
|
||||
MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count)
|
||||
MWWorld::Ptr ProxyItemModel::copyItem (const ItemStack& item, size_t count, bool allowAutoEquip)
|
||||
{
|
||||
return mSourceModel->copyItem (item, count);
|
||||
return mSourceModel->copyItem (item, count, allowAutoEquip);
|
||||
}
|
||||
|
||||
void ProxyItemModel::removeItem (const ItemStack& item, size_t count)
|
||||
|
|
|
@ -65,9 +65,7 @@ namespace MWGui
|
|||
/// @note Derived implementations may return an empty Ptr if the move was unsuccessful.
|
||||
virtual MWWorld::Ptr moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
|
||||
|
||||
/// @param setNewOwner If true, set the copied item's owner to the actor we are copying to,
|
||||
/// otherwise reset owner to ""
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count) = 0;
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool allowAutoEquip = true) = 0;
|
||||
virtual void removeItem (const ItemStack& item, size_t count) = 0;
|
||||
|
||||
/// Is the player allowed to use items from this item model? (default true)
|
||||
|
@ -97,7 +95,7 @@ namespace MWGui
|
|||
virtual bool onDropItem(const MWWorld::Ptr &item, int count);
|
||||
virtual bool onTakeItem(const MWWorld::Ptr &item, int count);
|
||||
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count);
|
||||
virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool allowAutoEquip = true);
|
||||
virtual void removeItem (const ItemStack& item, size_t count);
|
||||
virtual ModelIndex getIndex (ItemStack item);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "tradeitemmodel.hpp"
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/containerstore.hpp"
|
||||
|
@ -139,8 +140,9 @@ namespace MWGui
|
|||
throw std::runtime_error("The borrowed item disappeared");
|
||||
|
||||
const ItemStack& item = sourceModel->getItem(i);
|
||||
static const bool prevent = Settings::Manager::getBool("prevent merchant equipping", "Game");
|
||||
// copy the borrowed items to our model
|
||||
copyItem(item, itemStack.mCount);
|
||||
copyItem(item, itemStack.mCount, !prevent);
|
||||
// then remove them from the source model
|
||||
sourceModel->removeItem(item, itemStack.mCount);
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ namespace MWMechanics
|
|||
if (actor.getClass().getCreatureStats(actor).isDead())
|
||||
return;
|
||||
|
||||
if (!actor.getClass().hasInventoryStore(actor) || !actor.getClass().getInventoryStore(actor).canActorAutoEquip(actor))
|
||||
if (!actor.getClass().hasInventoryStore(actor))
|
||||
return;
|
||||
|
||||
if (actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
|
||||
|
@ -1220,7 +1220,7 @@ namespace MWMechanics
|
|||
heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||
|
||||
// If we have a torch and can equip it, then equip it now.
|
||||
if (heldIter == inventoryStore.end() && inventoryStore.canActorAutoEquip(ptr))
|
||||
if (heldIter == inventoryStore.end())
|
||||
{
|
||||
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, torch, ptr);
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const std::string &
|
|||
return add(ref.getPtr(), count, actorPtr);
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr, int count, const Ptr& actorPtr)
|
||||
MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr, int count, const Ptr& actorPtr, bool /*allowAutoEquip*/)
|
||||
{
|
||||
Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace MWWorld
|
|||
|
||||
bool hasVisibleItems() const;
|
||||
|
||||
virtual ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr);
|
||||
virtual ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr, bool allowAutoEquip = true);
|
||||
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
|
||||
///
|
||||
/// \note The item pointed to is not required to exist beyond this function call.
|
||||
|
@ -146,8 +146,6 @@ namespace MWWorld
|
|||
/// \attention Do not add items to an existing stack by increasing the count instead of
|
||||
/// calling this function!
|
||||
///
|
||||
/// @param setOwner Set the owner of the added item to \a actorPtr? If false, the owner is reset to "".
|
||||
///
|
||||
/// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item.
|
||||
|
||||
ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <components/esm/loadench.hpp>
|
||||
#include <components/esm/inventorystate.hpp>
|
||||
#include <components/misc/rng.hpp>
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
@ -131,12 +130,12 @@ MWWorld::InventoryStore& MWWorld::InventoryStore::operator= (const InventoryStor
|
|||
return *this;
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr, int count, const Ptr& actorPtr)
|
||||
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr, int count, const Ptr& actorPtr, bool allowAutoEquip)
|
||||
{
|
||||
const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, count, actorPtr);
|
||||
const MWWorld::ContainerStoreIterator& retVal = MWWorld::ContainerStore::add(itemPtr, count, actorPtr, allowAutoEquip);
|
||||
|
||||
// Auto-equip items if an armor/clothing item is added, but not for the player nor werewolves
|
||||
if (actorPtr != MWMechanics::getPlayer()
|
||||
if (allowAutoEquip && actorPtr != MWMechanics::getPlayer()
|
||||
&& actorPtr.getClass().isNpc() && !actorPtr.getClass().getNpcStats(actorPtr).isWerewolf())
|
||||
{
|
||||
std::string type = itemPtr.getTypeName();
|
||||
|
@ -208,33 +207,6 @@ MWWorld::ConstContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
|||
return findSlot (slot);
|
||||
}
|
||||
|
||||
bool MWWorld::InventoryStore::canActorAutoEquip(const MWWorld::Ptr& actor)
|
||||
{
|
||||
// Treat player as non-trader indifferently from service flags.
|
||||
if (actor == MWMechanics::getPlayer())
|
||||
return true;
|
||||
|
||||
static const bool prevent = Settings::Manager::getBool("prevent merchant equipping", "Game");
|
||||
if (!prevent)
|
||||
return true;
|
||||
|
||||
// Corpses can be dressed up by the player as desired.
|
||||
if (actor.getClass().getCreatureStats(actor).isDead())
|
||||
return true;
|
||||
|
||||
// Companions can autoequip items.
|
||||
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;
|
||||
}
|
||||
|
||||
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::findSlot (int slot) const
|
||||
{
|
||||
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
|
||||
|
@ -552,9 +524,6 @@ void MWWorld::InventoryStore::autoEquipShield(const MWWorld::Ptr& actor, TSlots&
|
|||
|
||||
void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
|
||||
{
|
||||
if (!canActorAutoEquip(actor))
|
||||
return;
|
||||
|
||||
TSlots slots_;
|
||||
initSlots (slots_);
|
||||
|
||||
|
|
|
@ -124,17 +124,15 @@ namespace MWWorld
|
|||
|
||||
virtual InventoryStore* clone() { return new InventoryStore(*this); }
|
||||
|
||||
virtual ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr);
|
||||
virtual ContainerStoreIterator add (const Ptr& itemPtr, int count, const Ptr& actorPtr, bool allowAutoEquip = true);
|
||||
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
|
||||
/// Auto-equip items if specific conditions are fulfilled (see the implementation).
|
||||
/// Auto-equip items if specific conditions are fulfilled and allowAutoEquip is true (see the implementation).
|
||||
///
|
||||
/// \note The item pointed to is not required to exist beyond this function call.
|
||||
///
|
||||
/// \attention Do not add items to an existing stack by increasing the count instead of
|
||||
/// calling this function!
|
||||
///
|
||||
/// @param setOwner Set the owner of the added item to \a actorPtr?
|
||||
///
|
||||
/// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item.
|
||||
|
||||
void equip (int slot, const ContainerStoreIterator& iterator, const Ptr& actor);
|
||||
|
@ -160,8 +158,6 @@ namespace MWWorld
|
|||
void autoEquip (const MWWorld::Ptr& actor);
|
||||
///< Auto equip items according to stats and item value.
|
||||
|
||||
bool canActorAutoEquip(const MWWorld::Ptr& actor);
|
||||
|
||||
const MWMechanics::MagicEffects& getMagicEffects() const;
|
||||
///< Return magic effects from worn items.
|
||||
|
||||
|
|
Loading…
Reference in a new issue