extends RefCounted class_name ItemDrying const raisinScript = preload("res://Items/Foods/Fruits/Raisin.gd") static func dry_inventory_items(inventory:Inventory, amount:int = 1): var amountLeftToDry = amount amountLeftToDry = dry_wet_inventory_items(inventory, amountLeftToDry) if amountLeftToDry > 0: amountLeftToDry = dry_other_inventory_items(inventory, amountLeftToDry) static func dry_wet_inventory_items(inventory:Inventory, amount:int): var amountLeftToDry = amount var pairedInvCopy = inventory.get_item_quantity_pair_array() pairedInvCopy.shuffle() var originalInventorySize = pairedInvCopy.size() var i = 0 while i < originalInventorySize: var currentItem:Item = pairedInvCopy[i][0] if Item.modifications.Wet in currentItem.itemModifications: var newItem = dry_item(currentItem) var originalItemQuantity = pairedInvCopy[i][1] var amountDrying = originalItemQuantity if amountDrying > amountLeftToDry: amountDrying = amountLeftToDry inventory.remove_item(currentItem, amountDrying) inventory.add_item(newItem, amountDrying) amountLeftToDry -= amountDrying if amountLeftToDry <= 0: break i += 1 return amountLeftToDry static func dry_other_inventory_items(inventory:Inventory, amount:int): var amountLeftToDry = amount var pairedInvCopy = inventory.get_item_quantity_pair_array() pairedInvCopy.shuffle() var originalInventorySize = pairedInvCopy.size() var i = 0 while i < originalInventorySize: var currentItem:Item = pairedInvCopy[i][0] var newItem = dry_item(currentItem) if !newItem.equals(currentItem): var originalItemQuantity = pairedInvCopy[i][1] var amountDrying = originalItemQuantity if amountDrying > amountLeftToDry: amountDrying = amountLeftToDry inventory.remove_item(currentItem, amountDrying) inventory.add_item(newItem, amountDrying) amountLeftToDry -= amountDrying if amountLeftToDry <= 0: break i += 1 return amountLeftToDry static func dry_item(item:Item): var newItem:Item = item.duplicate() if Item.modifications.Wet in newItem.itemModifications: newItem.remove_modification(Item.modifications.Wet) elif newItem.get_name(false) == "Grape": newItem = raisinScript.new() return newItem static func sun_dry_item(item:Item): var newItem:Item = item.duplicate() if Item.modifications.Wet in newItem.itemModifications: newItem.remove_modification(Item.modifications.Wet) elif Item.types.Juice in newItem.itemTypes: newItem = concentrate_juice(newItem) elif newItem.get_name(false) == "Grape": newItem = raisinScript.new() return newItem static func concentrate_juice(item:Item): var newItem:Item = item.duplicate() if Item.modifications.Sugared in newItem.itemModifications: newItem = candy_item(newItem) else: newItem.set_modification(Item.modifications.Concentrated) return newItem static func candy_item(item:Item): var newCandy = CandyGenerator.generate_candy(item) return newCandy