61 lines
1.5 KiB
GDScript
61 lines
1.5 KiB
GDScript
extends Item
|
|
class_name Fork
|
|
|
|
const USE_INTERVAL = 0.15
|
|
|
|
func get_item_name() -> String:
|
|
return tr("FORK")
|
|
|
|
func get_description() -> String:
|
|
return tr("FORK_DESC_TEXT")
|
|
|
|
func get_icon() -> Texture2D:
|
|
return preload("res://common/icons/fork.svg")
|
|
|
|
func get_pointer() -> Texture2D:
|
|
return preload("res://gui/pointer/assets/cursors/pointer-fork.svg")
|
|
|
|
func get_item_type() -> ItemType:
|
|
return Item.ItemType.TOOL_ITEM
|
|
|
|
func snap_usage_to_grid():
|
|
return true
|
|
|
|
func get_energy_used() -> int:
|
|
return 1
|
|
|
|
func get_usage_zone_radius() -> int:
|
|
return 10
|
|
|
|
func get_usage_objects_affected(areas : Array[Area2D], zone : Player.ActionZone) -> Array[Area2D]:
|
|
areas = areas.filter(
|
|
func (a): return a is Plant and a.position.distance_to(zone.area.position) < 5
|
|
)
|
|
if len(areas) == 0:
|
|
return []
|
|
else:
|
|
return [areas[0]]
|
|
|
|
func use_text() -> String:
|
|
return tr("HARVEST")
|
|
|
|
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
|
|
print(zone)
|
|
var areas = get_usage_objects_affected(zone.get_affected_areas(), zone)
|
|
if len(areas) > 0:
|
|
return true
|
|
print("nope")
|
|
return false
|
|
|
|
func use(player : Player, zone : Player.ActionZone) -> bool:
|
|
var has_plant = false
|
|
var areas = get_usage_objects_affected(zone.get_affected_areas(), zone)
|
|
if len(areas) > 0:
|
|
harvest(areas[0], player)
|
|
has_plant = true
|
|
return has_plant
|
|
|
|
func harvest(p : Plant, _player: Player):
|
|
AudioManager.play_sfx("Harvest")
|
|
p.harvest()
|