1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-12 03:36:32 +00:00
OpenMW/apps/openmw/mwgui/companionitemmodel.cpp

52 lines
1.4 KiB
C++
Raw Normal View History

2013-05-11 16:38:27 +00:00
#include "companionitemmodel.hpp"
#include "../mwworld/class.hpp"
namespace
{
void modifyProfit(const MWWorld::Ptr& actor, int diff)
{
std::string script = actor.getClass().getScript(actor);
if (!script.empty())
{
int profit = actor.getRefData().getLocals().getIntVar(script, "minimumprofit");
profit += diff;
actor.getRefData().getLocals().setVarByInt(script, "minimumprofit", profit);
}
}
}
2013-05-11 16:38:27 +00:00
namespace MWGui
{
CompanionItemModel::CompanionItemModel(const MWWorld::Ptr &actor)
: InventoryItemModel(actor)
{
}
MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
2013-05-11 16:38:27 +00:00
{
if (hasProfit(mActor))
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count);
2013-05-11 16:38:27 +00:00
return InventoryItemModel::copyItem(item, count, setNewOwner);
2013-05-11 16:38:27 +00:00
}
void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
{
if (hasProfit(mActor))
modifyProfit(mActor, -item.mBase.getClass().getValue(item.mBase) * count);
2013-05-11 16:38:27 +00:00
InventoryItemModel::removeItem(item, count);
}
bool CompanionItemModel::hasProfit(const MWWorld::Ptr &actor)
{
std::string script = actor.getClass().getScript(actor);
if (script.empty())
return false;
return actor.getRefData().getLocals().hasVar(script, "minimumprofit");
}
2013-05-11 16:38:27 +00:00
}