Remove sold items from equipment slots and loadout slots if they exist there so they no longer linger. Relase Build 7870. Game Version 0.4.2

This commit is contained in:
2024-03-01 17:04:12 -06:00
parent 84e713b9a2
commit 613e2be21f
9 changed files with 33 additions and 20 deletions
+21
View File
@@ -205,9 +205,30 @@ void Merchant::SellItem(std::weak_ptr<Item>item,uint32_t amt){
}
totalCost=item.lock()->SellValue()*amt;
//If the item is equipped on our character, remove it.
EquipSlot equippedItemSlot=Inventory::GetSlotEquippedIn(item);
if(equippedItemSlot!=EquipSlot::NONE)Inventory::UnequipItem(equippedItemSlot);
int foundLoadoutSlot=-1;
//If the item exists in our loadout, remove it.
for(int i=0;i<game->GetLoadoutSize();i++){
if(!ISBLANK(game->GetLoadoutItem(i))&&game->GetLoadoutItem(i).lock()->ActualName()==item.lock()->ActualName()){
game->ClearLoadoutItem(i);
if(foundLoadoutSlot!=-1)ERR("WARNING! Found two loadout item slots with the same item! THIS SHOULD NOT BE HAPPENING!")
foundLoadoutSlot=i;
}
}
std::string itemName=item.lock()->ActualName(); //We need the item name since our reference to the item is about to be deleted.
Inventory::RemoveItem(item,amt);
game->GetPlayer()->SetMoney(game->GetPlayer()->GetMoney()+totalCost);
//If we still have some in our inventory, we'll add them back in.
if(Inventory::GetItemCount(itemName)>0){
game->SetLoadoutItem(foundLoadoutSlot,itemName);
}
sellFunctionPrimed=false;
};