feat: add nearby villager field notes
This commit is contained in:
@@ -8,6 +8,7 @@ signal interaction_feedback(heading: String, message: String, succeeded: bool)
|
||||
@export var camera_rig: Node3D
|
||||
|
||||
@export var simulation_manager: Node
|
||||
@export var world_view_manager: Node
|
||||
|
||||
@export var pantry_storage: StorageNode
|
||||
@export var guard_site: ActivitySite
|
||||
@@ -15,6 +16,7 @@ signal interaction_feedback(heading: String, message: String, succeeded: bool)
|
||||
|
||||
@export var stomach_capacity_for_food := 5
|
||||
@export var interaction_range := 3.0
|
||||
@export var villager_inspection_range := 3.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -115,6 +117,44 @@ func get_interaction_context() -> PlayerInteractionResult:
|
||||
return null
|
||||
|
||||
|
||||
func get_nearby_villager_inspection() -> VillagerInspectionResult:
|
||||
if (
|
||||
simulation_manager == null
|
||||
or world_view_manager == null
|
||||
or not world_view_manager.has_method("find_nearest_active_npc_id")
|
||||
):
|
||||
return null
|
||||
var npc_id: int = world_view_manager.find_nearest_active_npc_id(
|
||||
global_position, villager_inspection_range
|
||||
)
|
||||
var npc := _find_npc(npc_id)
|
||||
if npc == null:
|
||||
return null
|
||||
var action_name := _get_action_display_name(npc.current_task)
|
||||
var target_name := _get_target_display_name(npc.target_id)
|
||||
var carried_amounts := {}
|
||||
for raw_item_id in npc.inventory:
|
||||
var amount := npc.get_inventory_amount(StringName(raw_item_id))
|
||||
if amount > 0.0:
|
||||
carried_amounts[String(raw_item_id)] = amount
|
||||
var reason := ""
|
||||
if simulation_manager.has_method("get_latest_decision"):
|
||||
var decision: ActionSelectionResult = simulation_manager.get_latest_decision(npc.id)
|
||||
if decision != null and decision.action_id == npc.current_task:
|
||||
reason = decision.reason
|
||||
return VillagerInspectionResult.new(
|
||||
npc.id,
|
||||
npc.npc_name,
|
||||
npc.current_task,
|
||||
action_name,
|
||||
npc.task_state,
|
||||
npc.target_id,
|
||||
target_name,
|
||||
carried_amounts,
|
||||
reason
|
||||
)
|
||||
|
||||
|
||||
func _find_feed_animal() -> AnimalNode:
|
||||
if not ("animal_care" in simulation_manager) or simulation_manager.animal_care == null:
|
||||
push_error("Player: SimulationManager has no animal-care service")
|
||||
@@ -129,6 +169,44 @@ func _find_resource_node() -> ResourceNode:
|
||||
return simulation_manager.find_resource_node_for_player(global_position, interaction_range)
|
||||
|
||||
|
||||
func _find_npc(npc_id: int) -> SimNPC:
|
||||
if npc_id < 0:
|
||||
return null
|
||||
for npc in simulation_manager.npcs:
|
||||
if npc.id == npc_id and not npc.is_dead:
|
||||
return npc
|
||||
return null
|
||||
|
||||
|
||||
func _get_action_display_name(action_id: StringName) -> String:
|
||||
if action_id == SimulationIds.ACTION_IDLE:
|
||||
return "Idle"
|
||||
if action_id == SimulationIds.ACTION_DEAD:
|
||||
return "Dead"
|
||||
var definition := SimulationDefinitions.get_action(action_id)
|
||||
return definition.display_name if definition != null else _display_id(action_id)
|
||||
|
||||
|
||||
func _get_target_display_name(target_id: StringName) -> String:
|
||||
if target_id.is_empty():
|
||||
return "None recorded"
|
||||
if "animal_care" in simulation_manager and simulation_manager.animal_care != null:
|
||||
var animal_state: AnimalStateRecord = simulation_manager.animal_care.get_state(target_id)
|
||||
if animal_state != null:
|
||||
return animal_state.get_display_name()
|
||||
var storage := StorageNode.get_by_id(target_id) as StorageNode
|
||||
if storage != null:
|
||||
return storage.display_name
|
||||
var activity := ActivitySite.get_by_id(target_id) as ActivitySite
|
||||
if activity != null:
|
||||
return activity.display_name
|
||||
return _display_id(target_id)
|
||||
|
||||
|
||||
static func _display_id(value: StringName) -> String:
|
||||
return String(value).replace("_", " ").capitalize()
|
||||
|
||||
|
||||
func _build_animal_context(node: AnimalNode) -> PlayerInteractionResult:
|
||||
var cost := _get_animal_feed_cost()
|
||||
var pantry_food := _get_pantry_food()
|
||||
|
||||
Reference in New Issue
Block a user