feat: surface inspected villager's open village need in field notes
This commit is contained in:
@@ -14,6 +14,11 @@ var carried_amounts: Dictionary
|
||||
var decision_reason: String
|
||||
var _has_decision_reason: bool
|
||||
|
||||
var has_open_need := false
|
||||
var need_type: StringName
|
||||
var need_progress: String
|
||||
var need_response: String
|
||||
|
||||
|
||||
func _init(
|
||||
inspection_npc_id: int,
|
||||
@@ -24,7 +29,8 @@ func _init(
|
||||
inspection_target_id: StringName,
|
||||
inspection_target_name: String,
|
||||
inspection_carried_amounts: Dictionary,
|
||||
inspection_decision_reason := ""
|
||||
inspection_decision_reason := "",
|
||||
inspection_need: Dictionary = {}
|
||||
) -> void:
|
||||
npc_id = inspection_npc_id
|
||||
npc_name = inspection_npc_name
|
||||
@@ -36,6 +42,10 @@ func _init(
|
||||
carried_amounts = inspection_carried_amounts.duplicate(true)
|
||||
_has_decision_reason = not inspection_decision_reason.strip_edges().is_empty()
|
||||
decision_reason = (inspection_decision_reason if _has_decision_reason else AWAITING_REASON)
|
||||
has_open_need = bool(inspection_need.get("has_open_need", false))
|
||||
need_type = StringName(inspection_need.get("need_type", &""))
|
||||
need_progress = String(inspection_need.get("progress", ""))
|
||||
need_response = String(inspection_need.get("response", ""))
|
||||
|
||||
|
||||
func has_decision_reason() -> bool:
|
||||
@@ -80,6 +90,10 @@ func cache_key() -> String:
|
||||
target_name,
|
||||
",".join(carried_parts),
|
||||
decision_reason,
|
||||
str(has_open_need),
|
||||
String(need_type),
|
||||
need_progress,
|
||||
need_response,
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
+97
-1
@@ -142,6 +142,7 @@ func get_nearby_villager_inspection() -> VillagerInspectionResult:
|
||||
var decision: ActionSelectionResult = simulation_manager.get_latest_decision(npc.id)
|
||||
if decision != null and decision.action_id == npc.current_task:
|
||||
reason = decision.reason
|
||||
var need := _get_open_need_for_npc(npc)
|
||||
return VillagerInspectionResult.new(
|
||||
npc.id,
|
||||
npc.npc_name,
|
||||
@@ -151,10 +152,105 @@ func get_nearby_villager_inspection() -> VillagerInspectionResult:
|
||||
npc.target_id,
|
||||
target_name,
|
||||
carried_amounts,
|
||||
reason
|
||||
reason,
|
||||
need
|
||||
)
|
||||
|
||||
|
||||
func _get_open_need_for_npc(npc: SimNPC) -> Dictionary:
|
||||
if not simulation_manager.has_method("get_latest_opportunity_for_npc"):
|
||||
return {
|
||||
"has_open_need": false,
|
||||
"need_type": &"",
|
||||
"progress": "",
|
||||
"response": "",
|
||||
}
|
||||
var opportunity: OpportunityStateRecord = simulation_manager.get_latest_opportunity_for_npc(
|
||||
npc.id
|
||||
)
|
||||
if (
|
||||
opportunity == null
|
||||
or opportunity.get_status() != OpportunityStateRecord.STATUS_OPEN
|
||||
or opportunity.get_interested_npc_id() != npc.id
|
||||
):
|
||||
return {
|
||||
"has_open_need": false,
|
||||
"need_type": &"",
|
||||
"progress": "",
|
||||
"response": "",
|
||||
}
|
||||
var resource_name := String(opportunity.get_resource_id()).capitalize()
|
||||
var current_amount := _get_need_storage_amount(opportunity)
|
||||
var progress := (
|
||||
"%s %.0f / %.0f" % [resource_name, current_amount, opportunity.get_target_amount()]
|
||||
)
|
||||
var response := "No one is able to supply this right now."
|
||||
if simulation_manager.has_method("get_active_opportunity_helper"):
|
||||
var helper: OpportunityHelperResult = simulation_manager.get_active_opportunity_helper()
|
||||
if helper != null and helper.opportunity_id == opportunity.get_opportunity_id():
|
||||
var helper_name := _get_npc_name(helper.helper_npc_id)
|
||||
var action_phrase := _get_action_phrase(helper.action_id)
|
||||
response = "%s can %s." % [helper_name, action_phrase]
|
||||
if response == "No one is able to supply this right now.":
|
||||
if simulation_manager.has_method("get_active_opportunity_player_response"):
|
||||
var player_route: OpportunityPlayerResponseResult = (
|
||||
simulation_manager.get_active_opportunity_player_response()
|
||||
)
|
||||
if player_route != null:
|
||||
var route_phrase := (
|
||||
"forage food"
|
||||
if opportunity.get_resource_id() == SimulationIds.RESOURCE_FOOD
|
||||
else "harvest a tree"
|
||||
)
|
||||
response = (
|
||||
"You can help — %s to the %s."
|
||||
% [route_phrase, _get_need_target_name(opportunity)]
|
||||
)
|
||||
return {
|
||||
"has_open_need": true,
|
||||
"need_type": opportunity.get_opportunity_type(),
|
||||
"progress": progress,
|
||||
"response": response,
|
||||
}
|
||||
|
||||
|
||||
func _get_need_storage_amount(opportunity: OpportunityStateRecord) -> float:
|
||||
if not simulation_manager.has_method("get_pantry"):
|
||||
return 0.0
|
||||
match opportunity.get_target_id():
|
||||
SimulationIds.STORAGE_VILLAGE_PANTRY:
|
||||
var pantry: StorageStateRecord = simulation_manager.get_pantry()
|
||||
return pantry.get_amount(opportunity.get_resource_id()) if pantry != null else 0.0
|
||||
SimulationIds.STORAGE_VILLAGE_WOODPILE:
|
||||
if simulation_manager.has_method("get_woodpile"):
|
||||
var woodpile: StorageStateRecord = simulation_manager.get_woodpile()
|
||||
return (
|
||||
woodpile.get_amount(opportunity.get_resource_id()) if woodpile != null else 0.0
|
||||
)
|
||||
return 0.0
|
||||
|
||||
|
||||
func _get_npc_name(npc_id: int) -> String:
|
||||
for npc in simulation_manager.npcs:
|
||||
if npc.id == npc_id:
|
||||
return npc.npc_name
|
||||
return "Someone"
|
||||
|
||||
|
||||
func _get_action_phrase(action_id: StringName) -> String:
|
||||
var definition := SimulationDefinitions.get_action(action_id)
|
||||
return definition.display_name.to_lower() if definition != null else String(action_id)
|
||||
|
||||
|
||||
func _get_need_target_name(opportunity: OpportunityStateRecord) -> String:
|
||||
match opportunity.get_target_id():
|
||||
SimulationIds.STORAGE_VILLAGE_PANTRY:
|
||||
return "village pantry"
|
||||
SimulationIds.STORAGE_VILLAGE_WOODPILE:
|
||||
return "village woodpile"
|
||||
return String(opportunity.get_target_id()).replace("_", " ")
|
||||
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user