feat: add physical animal care delivery
This commit is contained in:
@@ -141,6 +141,38 @@ func withdraw_to_inventory(npc: SimNPC, item_id: StringName, amount: float) -> f
|
||||
return withdrawn
|
||||
|
||||
|
||||
func withdraw_exact_to_inventory(npc: SimNPC, item_id: StringName, amount: float) -> float:
|
||||
if npc == null or not is_finite(amount) or amount <= 0.0:
|
||||
return 0.0
|
||||
var storage := get_storage_for_resource(item_id)
|
||||
if storage == null or storage.get_amount(item_id) < amount:
|
||||
return 0.0
|
||||
return withdraw_to_inventory(npc, item_id, amount)
|
||||
|
||||
|
||||
func remove_exact_from_inventory(npc: SimNPC, item_id: StringName, amount: float) -> float:
|
||||
if (
|
||||
npc == null
|
||||
or not is_finite(amount)
|
||||
or amount <= 0.0
|
||||
or npc.get_inventory_amount(item_id) < amount
|
||||
):
|
||||
return 0.0
|
||||
var removed := npc.remove_inventory(item_id, amount)
|
||||
if not is_equal_approx(removed, amount):
|
||||
npc.add_inventory(item_id, removed)
|
||||
return 0.0
|
||||
inventory_changed.emit(npc, item_id, npc.get_inventory_amount(item_id))
|
||||
return removed
|
||||
|
||||
|
||||
func restore_to_inventory(npc: SimNPC, item_id: StringName, amount: float) -> void:
|
||||
if npc == null or not is_finite(amount) or amount <= 0.0:
|
||||
return
|
||||
npc.add_inventory(item_id, amount)
|
||||
inventory_changed.emit(npc, item_id, npc.get_inventory_amount(item_id))
|
||||
|
||||
|
||||
func consume_npc_food(npc: SimNPC) -> bool:
|
||||
if npc.remove_inventory(SimulationIds.RESOURCE_FOOD, 1.0) < 1.0:
|
||||
npc.hunger = minf(npc.hunger + 5.0, 100.0)
|
||||
|
||||
Reference in New Issue
Block a user