Corrected RemoveItem function to handle monster loot and stage loot tracking.

pull/28/head
sigonasr2 1 year ago
parent 7cd54e5f80
commit 22d1a6d834
  1. 1
      Crawler/Crawler.cpp
  2. 30
      Crawler/Item.cpp
  3. 1
      Crawler/Item.h
  4. 2
      Crawler/Version.h

@ -176,6 +176,7 @@ bool Crawler::OnUserCreate(){
Inventory::AddItem("Blue Slime Remains",22); Inventory::AddItem("Blue Slime Remains",22);
LoadLevel(LEVEL_NAMES["starting_map"_S]); LoadLevel(LEVEL_NAMES["starting_map"_S]);
Inventory::AddItem("Bandages",3);
Inventory::AddItem("Blue Slime Remains",10,true); Inventory::AddItem("Blue Slime Remains",10,true);
ChangePlayerClass(WARRIOR); ChangePlayerClass(WARRIOR);

@ -184,21 +184,31 @@ bool Inventory::UseItem(IT it,uint32_t amt){
} }
//Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory. //Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory.
bool Inventory::RemoveItem(IT it,uint32_t amt){ bool Inventory::RemoveItem(IT it,ITCategory inventory,uint32_t amt){
//There are two places to manipulate items in (Both the sorted inventory and the actual inventory) //There are two places to manipulate items in (Both the sorted inventory and the actual inventory)
if (!_inventory.count(it))return false; if (!_inventory.count(it))return false;
if (amt>=_inventory.at(it).Amt()){ if (amt>=_inventory.at(it).Amt()){
int count=0; int count=0;
std::vector<Item>&sortedList=sortedInv.at(_inventory.at(it).Category()); std::vector<Item>&inv=sortedInv.at(inventory);
for(Item&item:sortedList){ bool eraseFromLootWindow=false;
if(inventory=="Monster Loot") {
inv=sortedInv.at("Monster Loot");
eraseFromLootWindow=true;
}else
if(inventory=="Stage Loot"){
inv=sortedInv.at("Stage Loot");
eraseFromLootWindow=true;
}
for(Item&item:inv){
if(item.Name()==it)break; if(item.Name()==it)break;
count++; count++;
} }
sortedList.erase(sortedList.begin()+count); inv.erase(inv.begin()+count);
if(!eraseFromLootWindow){
_inventory.erase(it); _inventory.erase(it);
ITCategory cat=ITEM_DATA[it].category; }
//Callback for GUI inventories. //Callback for GUI inventories.
Menu::InventorySlotsUpdated(cat); Menu::InventorySlotsUpdated(inventory);
return true; return true;
}else{ }else{
_inventory.at(it).amt-=amt; _inventory.at(it).amt-=amt;
@ -206,6 +216,12 @@ bool Inventory::RemoveItem(IT it,uint32_t amt){
} }
} }
//Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory.
bool Inventory::RemoveItem(IT it,uint32_t amt){
ITCategory cat = ITEM_DATA[it].category;
return RemoveItem(it, cat, amt);
}
std::vector<Item>&Inventory::get(ITCategory itemCategory){ std::vector<Item>&Inventory::get(ITCategory itemCategory){
return sortedInv.at(itemCategory); return sortedInv.at(itemCategory);
} }
@ -298,7 +314,7 @@ void Inventory::Clear(ITCategory itemCategory){
if(itemCategory=="Monster Loot"||itemCategory=="Stage Loot"){//These do not affect the actual inventory, we just clear the lists. if(itemCategory=="Monster Loot"||itemCategory=="Stage Loot"){//These do not affect the actual inventory, we just clear the lists.
itemQuantity=item.Amt(); itemQuantity=item.Amt();
} }
RemoveItem(item.Name(),itemQuantity); RemoveItem(item.Name(),itemCategory,itemQuantity);
} }
} }

@ -75,6 +75,7 @@ public:
static Item GetItem(IT it); static Item GetItem(IT it);
//Auto-executes its use function and removes the amt specified from the inventory. Multiple amounts will cause the item to execute its useFunc multiple times. //Auto-executes its use function and removes the amt specified from the inventory. Multiple amounts will cause the item to execute its useFunc multiple times.
static bool UseItem(IT it,uint32_t amt=1); static bool UseItem(IT it,uint32_t amt=1);
static bool RemoveItem(IT it,ITCategory inventory,uint32_t amt = 1);
static bool RemoveItem(IT it,uint32_t amt=1); static bool RemoveItem(IT it,uint32_t amt=1);
static std::vector<Item>&get(ITCategory itemCategory); static std::vector<Item>&get(ITCategory itemCategory);
static void Clear(ITCategory itemCategory); static void Clear(ITCategory itemCategory);

@ -35,7 +35,7 @@ SUCH DAMAGE.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 2975 #define VERSION_BUILD 2979
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save