Files
seeding-planets/entities/player/inventory/scripts/items/shovel.gd

54 lines
1.6 KiB
GDScript

extends Fork
class_name Shovel
const DIG_PARTICLES := preload("res://entities/player/inventory/scripts/items/utils/dig_particles.tscn")
const SHOVEL_ZONE_RADIUS = 50
func get_item_name() -> String:
return tr("SHOVEL")
func get_description() -> String:
return tr("SHOVEL_DESC_TEXT")
func get_icon() -> Texture2D:
return preload("res://common/icons/shovel.svg")
func get_usage_zone_radius() -> int:
return SHOVEL_ZONE_RADIUS
func get_usage_object_affected(i : InspectableEntity) -> bool:
return i is Plant
func use_text() -> String:
return tr("DIG")
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
var areas = zone.get_affected_areas()
var bodies = zone.area.get_overlapping_bodies()
for body in bodies :
if body is RockLayer:
return true
for area in areas :
if area is Plant:
return true
return false
func use(player : Player, zone : Player.ActionZone) -> bool:
AudioManager.play_sfx("Rocks")
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
var bodies = zone.area.get_overlapping_bodies()
var rock_layers = bodies.filter(func (b) : return b is RockLayer)
for rock_layer in rock_layers:
player.region.dig_rocks(zone.get_tiles())
var particles := (DIG_PARTICLES.instantiate() as DigParticleEmmitter)
player.region.add_child(particles)
particles.global_position = zone.get_global_position()
particles.emit()
return true