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:
+11
-1
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user