From 22d1a6d83486659735494bb5ea958a08943b33fd Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 21 Nov 2023 19:53:14 -0600 Subject: [PATCH] Corrected RemoveItem function to handle monster loot and stage loot tracking. --- Crawler/Crawler.cpp | 1 + Crawler/Item.cpp | 36 ++++++++++++++++++++++++++---------- Crawler/Item.h | 1 + Crawler/Version.h | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index d712e488..b089b39e 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -176,6 +176,7 @@ bool Crawler::OnUserCreate(){ Inventory::AddItem("Blue Slime Remains",22); LoadLevel(LEVEL_NAMES["starting_map"_S]); + Inventory::AddItem("Bandages",3); Inventory::AddItem("Blue Slime Remains",10,true); ChangePlayerClass(WARRIOR); diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 0e553f61..36fcbcc9 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -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. -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) - if(!_inventory.count(it))return false; - if(amt>=_inventory.at(it).Amt()){ + if (!_inventory.count(it))return false; + if (amt>=_inventory.at(it).Amt()){ int count=0; - std::vector&sortedList=sortedInv.at(_inventory.at(it).Category()); - for(Item&item:sortedList){ + std::vector&inv=sortedInv.at(inventory); + 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; count++; } - sortedList.erase(sortedList.begin()+count); - _inventory.erase(it); - ITCategory cat=ITEM_DATA[it].category; + inv.erase(inv.begin()+count); + if(!eraseFromLootWindow){ + _inventory.erase(it); + } //Callback for GUI inventories. - Menu::InventorySlotsUpdated(cat); + Menu::InventorySlotsUpdated(inventory); return true; }else{ _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&Inventory::get(ITCategory 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. itemQuantity=item.Amt(); } - RemoveItem(item.Name(),itemQuantity); + RemoveItem(item.Name(),itemCategory,itemQuantity); } } diff --git a/Crawler/Item.h b/Crawler/Item.h index 65514cf3..8ffb2e03 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -75,6 +75,7 @@ public: 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. 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 std::vector&get(ITCategory itemCategory); static void Clear(ITCategory itemCategory); diff --git a/Crawler/Version.h b/Crawler/Version.h index 39ac9a36..32f8bc50 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -35,7 +35,7 @@ SUCH DAMAGE. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 2975 +#define VERSION_BUILD 2979 #define stringify(a) stringify_(a) #define stringify_(a) #a