#ifndef OPENMW_MWMECHANICS_INVENTORY_H #define OPENMW_MWMECHANICS_INVENTORY_H #include "../mwbase/environment.hpp" #include "../mwworld/esmstore.hpp" #include #include #include #include namespace MWMechanics { template void modifyBaseInventory(const ESM::RefId& actorId, const ESM::RefId& itemId, int amount) { T copy = *MWBase::Environment::get().getESMStore()->get().find(actorId); for (auto& it : copy.mInventory.mList) { if (it.mItem == itemId) { const int sign = it.mCount < 1 ? -1 : 1; it.mCount = sign * std::max(it.mCount * sign + amount, 0); MWBase::Environment::get().getESMStore()->overrideRecord(copy); return; } } if (amount > 0) { ESM::ContItem cont; cont.mItem = itemId; cont.mCount = amount; copy.mInventory.mList.push_back(cont); MWBase::Environment::get().getESMStore()->overrideRecord(copy); } } } #endif