feat: generate animal-care quests and render them in the journal
This commit is contained in:
@@ -173,6 +173,7 @@ func simulate_tick() -> void:
|
||||
if debug_logs:
|
||||
print("--- Tick ", tick_count, " ---")
|
||||
animal_care.advance(tick_count)
|
||||
_consider_animal_care_quests()
|
||||
var village_was_changed := false
|
||||
_population_view.rebuild(npcs)
|
||||
for npc in npcs:
|
||||
@@ -570,10 +571,26 @@ func _on_economic_event_recorded(event: EconomicEventRecord) -> void:
|
||||
)
|
||||
for learned_record in learned_records:
|
||||
_apply_new_event_knowledge(learned_record, event)
|
||||
if StringName(event.data["event_type"]) == SimulationIds.EVENT_ANIMAL_FED:
|
||||
_resolve_animal_care_quest(event)
|
||||
_update_opportunity_from_event(event)
|
||||
economic_event_recorded.emit(event)
|
||||
|
||||
|
||||
func _resolve_animal_care_quest(event: EconomicEventRecord) -> void:
|
||||
var animal_id := StringName(event.data["destination_id"])
|
||||
var animal_state := animal_care.get_state(animal_id)
|
||||
var resolution := player_quest_system.on_animal_fed(animal_state, event, tick_count)
|
||||
if not resolution.has("quest"):
|
||||
return
|
||||
var quest: PlayerQuestRecord = resolution["quest"]
|
||||
if resolution["completed"]:
|
||||
player_quest_completed.emit(quest)
|
||||
player_standing_changed.emit(player_quest_system.standing)
|
||||
else:
|
||||
player_quest_expired.emit(quest)
|
||||
|
||||
|
||||
func try_communicate_at_shared_activity(speaker_id: int, listener_id: int) -> bool:
|
||||
var speaker := _find_npc_by_id(speaker_id)
|
||||
var listener := _find_npc_by_id(listener_id)
|
||||
@@ -760,6 +777,31 @@ func get_active_player_quest() -> PlayerQuestRecord:
|
||||
return player_quest_system.get_active_quest()
|
||||
|
||||
|
||||
func _consider_animal_care_quests() -> void:
|
||||
var pantry: StorageStateRecord = get_pantry()
|
||||
for animal_state in animal_care.get_all_states():
|
||||
var requester := _find_animal_requester(animal_state)
|
||||
var quest := player_quest_system.consider_animal_care(
|
||||
animal_state, requester, tick_count, pantry
|
||||
)
|
||||
if quest != null:
|
||||
player_quest_opened.emit(quest)
|
||||
|
||||
|
||||
func _find_animal_requester(animal_state: AnimalStateRecord) -> int:
|
||||
var animal_position := animal_state.get_position()
|
||||
var nearest_id := -1
|
||||
var nearest_distance := INF
|
||||
for npc in npcs:
|
||||
if npc.is_dead:
|
||||
continue
|
||||
var distance := npc.position.distance_squared_to(animal_position)
|
||||
if distance < nearest_distance:
|
||||
nearest_distance = distance
|
||||
nearest_id = npc.id
|
||||
return nearest_id
|
||||
|
||||
|
||||
func get_player_quests() -> Array[PlayerQuestRecord]:
|
||||
return player_quest_system.get_all_sorted()
|
||||
|
||||
@@ -846,6 +888,11 @@ func get_pantry() -> StorageStateRecord:
|
||||
return economy.get_pantry()
|
||||
|
||||
|
||||
func get_animal_display_name(animal_id: StringName) -> String:
|
||||
var animal_state := animal_care.get_state(animal_id)
|
||||
return animal_state.get_display_name() if animal_state != null else ""
|
||||
|
||||
|
||||
func get_woodpile() -> StorageStateRecord:
|
||||
return economy.get_woodpile()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user