feat: add player resource node harvesting

This commit is contained in:
2026-07-04 19:47:31 +02:00
parent f5e7326d49
commit 326df51cbe
6 changed files with 117 additions and 18 deletions
+29 -10
View File
@@ -7,8 +7,6 @@ extends CharacterBody3D
@export var simulation_manager: Node
@export var farm_zone: Marker3D
@export var forest_zone: Marker3D
@export var food_zone: Marker3D
@export var guard_zone: Marker3D
@export var study_zone: Marker3D
@@ -62,13 +60,10 @@ func try_interact() -> void:
if simulation_manager == null:
return
if is_near(farm_zone):
simulation_manager.add_food(5.0)
print("Player gathered food for the village.")
elif is_near(forest_zone):
simulation_manager.add_wood(5.0)
print("Player gathered wood for the village.")
elif is_near(guard_zone):
if try_harvest_resource_node():
return
if is_near(guard_zone):
simulation_manager.add_safety(3.0)
print("Player helped guard the village.")
elif is_near(study_zone):
@@ -76,7 +71,31 @@ func try_interact() -> void:
print("Player shared knowledge.")
elif is_near(food_zone):
simulation_manager.eat_food(stomach_capacity_for_food)
print("Player eating shit up.")
print("Player ate food from the village supply.")
func try_harvest_resource_node() -> bool:
var node := ResourceNode.find_nearest_for_player(global_position, interaction_range)
if node == null:
return false
if not node.enabled:
print("%s is unavailable." % node.node_id)
return true
if node.is_depleted():
print("%s is depleted." % node.node_id)
return true
if not simulation_manager.has_method("harvest_resource_node"):
push_error("Player: SimulationManager cannot harvest ResourceNodes")
return true
var extracted: float = simulation_manager.harvest_resource_node(node)
if extracted > 0.0:
print("Player gathered %s %s from %s." % [extracted, node.resource_id, node.node_id])
else:
print("%s could not be harvested." % node.node_id)
return true
func is_near(zone: Marker3D) -> bool:
if zone == null: