@ -46,7 +46,7 @@ safemap<std::string,ItemScript>ITEM_SCRIPTS;
safemap < std : : string , std : : set < std : : string > > ITEM_CATEGORIES ;
Item Item : : BLANK ;
std : : map < IT , Item > Inventory : : _inventory ;
std : : map < ITCategory , std : : vector < IT > > Inventory : : sortedInv ;
std : : map < ITCategory , std : : vector < Item > > Inventory : : sortedInv ;
ItemInfo : : ItemInfo ( )
: customProps ( { nullptr , nullptr } ) , img ( nullptr ) { }
@ -151,10 +151,11 @@ void Inventory::AddItem(IT it,uint32_t amt,bool monsterDrop){
//There are two places to manipulate items in (Both the sorted inventory and the actual inventory)
if ( ! _inventory . count ( it ) ) {
_inventory [ it ] = Item { amt , it } ;
InsertIntoSortedInv ( it , monsterDrop ) ;
InsertIntoSortedInv ( it ) ;
} else {
_inventory . at ( it ) . amt + = amt ;
}
InsertIntoStageInventoryCategory ( it , amt , monsterDrop ) ;
}
Item Inventory : : GetItem ( IT it ) {
@ -174,7 +175,7 @@ uint32_t Inventory::GetItemCount(IT it){
bool Inventory : : UseItem ( IT it , uint32_t amt ) {
if ( ! _inventory . count ( it ) ) return false ;
//There are two places to manipulate items in (Both the sorted inventory and the actual inventory)
for ( int i = 0 ; i < amt ; i + + ) {
for ( u int32_ t i = 0 ; i < amt ; i + + ) {
if ( ExecuteAction ( it ) ) {
return RemoveItem ( it ) ;
}
@ -188,9 +189,9 @@ bool Inventory::RemoveItem(IT it,uint32_t amt){
if ( ! _inventory . count ( it ) ) return false ;
if ( amt > = _inventory . at ( it ) . Amt ( ) ) {
int count = 0 ;
std : : vector < IT > & sortedList = sortedInv . at ( _inventory . at ( it ) . Category ( ) ) ;
for ( std : : string & itemName : sortedList ) {
if ( itemName = = it ) break ;
std : : vector < Item > & sortedList = sortedInv . at ( _inventory . at ( it ) . Category ( ) ) ;
for ( Item & item : sortedList ) {
if ( item . Name ( ) = = it ) break ;
count + + ;
}
sortedList . erase ( sortedList . begin ( ) + count ) ;
@ -205,19 +206,28 @@ bool Inventory::RemoveItem(IT it,uint32_t amt){
}
}
std : : vector < IT > & Inventory : : get ( ITCategory itemCategory ) {
std : : vector < Item > & Inventory : : get ( ITCategory itemCategory ) {
return sortedInv . at ( itemCategory ) ;
}
void Inventory : : InsertIntoSortedInv ( IT item , bool monsterDrop ) {
sortedInv . at ( ITEM_DATA [ item ] . category ) . push_back ( item ) ;
void Inventory : : InsertIntoSortedInv ( IT item ) {
sortedInv . at ( ITEM_DATA [ item ] . category ) . push_back ( Item { 1 , item } ) ;
//This should be a callback to menus that we need to update the interface with another item slot since a new one has appeared.
Menu : : InventorySlotsUpdated ( ITEM_DATA [ item ] . category ) ;
}
void Inventory : : InsertIntoStageInventoryCategory ( IT item , uint32_t amt , bool monsterDrop ) {
std : : string stageInventoryCategory = " Stage Loot " ;
if ( monsterDrop ) {
stageInventoryCategory = " Monster Loot " ;
}
sortedInv . at ( stageInventoryCategory ) . push_back ( item ) ;
//This should be a callback to menus that we need to update the interface with another item slot since a new one has appeared.
Menu : : InventorySlotsUpdated ( ITEM_DATA [ item ] . category ) ;
std : : vector < Item > & inv = sortedInv . at ( stageInventoryCategory ) ;
std : : vector < Item > : : iterator it = std : : find ( inv . begin ( ) , inv . end ( ) , Item { amt , item } ) ;
if ( it ! = inv . end ( ) ) {
( * it ) . amt + = amt ;
} else {
inv . push_back ( Item { amt , item } ) ;
}
Menu : : InventorySlotsUpdated ( stageInventoryCategory ) ;
}
@ -230,14 +240,14 @@ bool Inventory::ExecuteAction(IT item){
}
bool Inventory : : SwapItems ( ITCategory itemCategory , uint32_t slot1 , uint32_t slot2 ) {
std : : vector < IT > & inv = sortedInv . at ( itemCategory ) ;
std : : vector < Item > & inv = sortedInv . at ( itemCategory ) ;
int largestSlot = std : : max ( slot1 , slot2 ) ;
if ( inv . size ( ) < = largestSlot ) {
//The inventory is too small, so expand out blank slots to accomodate.
inv . resize ( largestSlot + size_t ( 1 ) ) ;
}
IT & item1 = inv . at ( slot1 ) ;
IT & item2 = inv . at ( slot2 ) ;
Item & item1 = inv . at ( slot1 ) ;
Item & item2 = inv . at ( slot2 ) ;
std : : swap ( item1 , item2 ) ;
return true ;
}
@ -282,8 +292,16 @@ bool Item::IsBlank(){
}
void Inventory : : Clear ( ITCategory itemCategory ) {
std : : vector < IT > itemList = get ( itemCategory ) ; //We have to make a copy here because RemoveItem() will modify the list provided by get() inline.
for ( IT & item : itemList ) {
RemoveItem ( item , GetItemCount ( item ) ) ;
std : : vector < Item > itemList = get ( itemCategory ) ; //We have to make a copy here because RemoveItem() will modify the list provided by get() inline.
for ( Item & item : itemList ) {
size_t itemQuantity = GetItemCount ( item . Name ( ) ) ; //Normally we want to clear all the items that are actually in our inventory...But...
if ( itemCategory = = " Monster Loot " | | itemCategory = = " Stage Loot " ) { //These do not affect the actual inventory, we just clear the lists.
itemQuantity = item . Amt ( ) ;
}
RemoveItem ( item . Name ( ) , itemQuantity ) ;
}
}
bool Item : : operator = = ( const Item & rhs ) const {
return it = = rhs . it ;
}