@ -1,5 +1,10 @@
# include "inventoryitemmodel.hpp"
# include "inventoryitemmodel.hpp"
# include <sstream>
# include "../mwmechanics/actorutil.hpp"
# include "../mwmechanics/npcstats.hpp"
# include "../mwworld/containerstore.hpp"
# include "../mwworld/containerstore.hpp"
# include "../mwworld/class.hpp"
# include "../mwworld/class.hpp"
# include "../mwworld/inventorystore.hpp"
# include "../mwworld/inventorystore.hpp"
@ -45,16 +50,33 @@ MWWorld::Ptr InventoryItemModel::copyItem (const ItemStack& item, size_t count,
return * mActor . getClass ( ) . getContainerStore ( mActor ) . add ( item . mBase , count , mActor , setNewOwner ) ;
return * mActor . getClass ( ) . getContainerStore ( mActor ) . add ( item . mBase , count , mActor , setNewOwner ) ;
}
}
void InventoryItemModel : : removeItem ( const ItemStack & item , size_t count )
void InventoryItemModel : : removeItem ( const ItemStack & item , size_t count )
{
{
int removed = 0 ;
// Re-equipping makes sense only if a target has inventory
if ( mActor . getClass ( ) . hasInventoryStore ( mActor ) )
{
MWWorld : : InventoryStore & store = mActor . getClass ( ) . getInventoryStore ( mActor ) ;
removed = store . remove ( item . mBase , count , mActor , true ) ;
}
else
{
MWWorld : : ContainerStore & store = mActor . getClass ( ) . getContainerStore ( mActor ) ;
MWWorld : : ContainerStore & store = mActor . getClass ( ) . getContainerStore ( mActor ) ;
int removed = store . remove ( item . mBase , count , mActor ) ;
removed = store . remove ( item . mBase , count , mActor ) ;
}
std : : stringstream error ;
if ( removed = = 0 )
if ( removed = = 0 )
throw std : : runtime_error ( " Item to remove not found in container store " ) ;
{
error < < " Item ' " < < item . mBase . getCellRef ( ) . getRefId ( ) < < " ' was not found in container store to remove " ;
throw std : : runtime_error ( error . str ( ) ) ;
}
else if ( removed < static_cast < int > ( count ) )
else if ( removed < static_cast < int > ( count ) )
throw std : : runtime_error ( " Not enough items in the stack to remove " ) ;
{
error < < " Not enough items ' " < < item . mBase . getCellRef ( ) . getRefId ( ) < < " ' in the stack to remove ( " < < static_cast < int > ( count ) < < " requested, " < < removed < < " found) " ;
throw std : : runtime_error ( error . str ( ) ) ;
}
}
}
MWWorld : : Ptr InventoryItemModel : : moveItem ( const ItemStack & item , size_t count , ItemModel * otherModel )
MWWorld : : Ptr InventoryItemModel : : moveItem ( const ItemStack & item , size_t count , ItemModel * otherModel )