1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 18:49:54 +00:00
openmw-tes3mp/apps/openmw/mwgui/companionitemmodel.cpp
scrawl 2346c3528d Remove NpcStats::mProfit and store it in the script instead
Also use the Profit label when the "minimumProfit" script variable exists, rather than hardcoding to NPCs.
2015-01-31 22:40:40 +01:00

52 lines
1.5 KiB
C++

#include "companionitemmodel.hpp"
#include "../mwmechanics/npcstats.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);
}
}
}
namespace MWGui
{
CompanionItemModel::CompanionItemModel(const MWWorld::Ptr &actor)
: InventoryItemModel(actor)
{
}
MWWorld::Ptr CompanionItemModel::copyItem (const ItemStack& item, size_t count, bool setNewOwner=false)
{
if (hasProfit(mActor))
modifyProfit(mActor, item.mBase.getClass().getValue(item.mBase) * count);
return InventoryItemModel::copyItem(item, count, setNewOwner);
}
void CompanionItemModel::removeItem (const ItemStack& item, size_t count)
{
if (hasProfit(mActor))
modifyProfit(mActor, -item.mBase.getClass().getValue(item.mBase) * count);
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");
}
}