Corrected GetInventorySlot() to return actual slot when there are multiple unique instances of an item instead of just the first index.

This commit is contained in:
2023-12-31 17:04:34 -06:00
parent 0e5d871c68
commit 4daf4f0135
3 changed files with 22 additions and 2 deletions
+11 -1
View File
@@ -919,7 +919,17 @@ void Item::SetAmt(uint32_t newAmt){
}
const std::weak_ptr<Item>Inventory::GetInventorySlot(ITCategory itemCategory,size_t slot){
return GetItem(get(itemCategory).at(slot)->ActualName())[0];
auto GetFirstIndex = [](ITCategory itemCategory,size_t slot){
auto firstIter=std::find_if(get(itemCategory).begin(),get(itemCategory).end(),[&](std::shared_ptr<Item>item){
if(item->ActualName()==get(itemCategory).at(slot)->ActualName())return true;
return false;
});
size_t firstIndex=firstIter-get(itemCategory).begin();
if(firstIter==get(itemCategory).end())ERR(std::format("Invalid slot {} for category {} specified!",slot,itemCategory));
return firstIndex;
};
return GetItem(get(itemCategory).at(slot)->ActualName())[slot-GetFirstIndex(itemCategory,slot)];
}
bool Item::IsBlank(std::shared_ptr<Item>item){