seeding-planets/common/inventory/scripts/items/fork.gd

45 lines
971 B
GDScript

extends Item
class_name Fork
const USE_INTERVAL = 0.15
func get_item_name() -> String:
return "Fork"
func get_description() -> String:
return "Use it to harvest mature plants."
func get_icon() -> Texture2D:
return preload("res://common/icons/fork.svg")
func get_energy_used() -> int:
return 1
func get_usage_zone_radius() -> int:
return 50
func get_usage_object_affected(i : InspectableEntity) -> bool:
return i is Plant
func use_text() -> String:
return "Harvest"
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
var areas = zone.get_affected_areas()
for area in areas :
if area is Plant:
return true
return false
func use(player : Player, zone : Player.ActionZone) -> bool:
for area in zone.get_affected_areas():
if area and area is Plant:
harvest(area, player)
await player.get_tree().create_timer(USE_INTERVAL).timeout
return true
func harvest(p : Plant, player: Player):
player.play_sfx("harvest")
p.harvest()