feat: generate animal-care quests and render them in the journal

This commit is contained in:
2026-08-08 20:27:59 +02:00
parent 089fef9968
commit 6cdeea6e46
8 changed files with 314 additions and 38 deletions
+83 -2
View File
@@ -133,8 +133,89 @@ func _run() -> void:
),
"A stale need should expire its quest without granting standing",
)
berry.queue_free()
stale_tree.queue_free()
berry.free()
stale_tree.free()
var animal_manager := _create_manager(906)
animal_manager.player_quest_opened.connect(_on_quest_opened)
animal_manager.player_quest_completed.connect(_on_quest_completed)
var caretaker: SimNPC = animal_manager.npcs[0]
var pantry: StorageStateRecord = animal_manager.get_pantry()
pantry.withdraw(SimulationIds.RESOURCE_FOOD, pantry.get_amount(SimulationIds.RESOURCE_FOOD))
pantry.deposit(SimulationIds.RESOURCE_FOOD, 5.0)
animal_manager.economy.sync_resource(SimulationIds.RESOURCE_FOOD)
caretaker.position = Vector3.ZERO
var goat := AnimalNode.new()
goat.name = "Dunja"
goat.animal_id = SimulationIds.ANIMAL_DUNJA
goat.display_name = "Dunja"
goat.species_id = SimulationIds.SPECIES_GOAT
goat.initial_enabled = true
goat.can_npcs_feed = true
goat.can_player_feed = true
goat.initial_hunger = 0.0
root.add_child(goat)
_check(
animal_manager.animal_care.register_node(goat),
"The animal-care quest branch should register a real named goat"
)
var animal_state: AnimalStateRecord = animal_manager.animal_care.get_state(
SimulationIds.ANIMAL_DUNJA
)
_check(animal_state != null, "The animal-care quest branch needs Dunja's state")
if animal_state == null:
_finish()
return
animal_state.set_hunger(animal_state.FEED_THRESHOLD + 1.0)
animal_manager.simulate_tick()
var animal_quest: PlayerQuestRecord = animal_manager.get_active_player_quest()
_check(
(
animal_quest != null
and animal_quest.has_animal_target()
and animal_quest.get_animal_id() == SimulationIds.ANIMAL_DUNJA
and animal_quest.get_quest_type() == SimulationIds.OPPORTUNITY_FEED_HUNGRY_ANIMAL
and animal_quest.get_requester_npc_id() == caretaker.id
),
"A hungry, player-feedable goat should generate an animal-care quest for a nearby villager",
)
var standing_before_animal: float = animal_manager.get_player_standing().get_standing()
_check(
animal_manager.feed_animal(SimulationIds.ANIMAL_DUNJA),
"The player should resolve the animal quest through the ordinary feed command"
)
var animal_latest: PlayerQuestRecord = animal_manager.get_latest_player_quest_for_requester(
caretaker.id
)
_check(
(
completed_quest_ids.has(animal_quest.get_quest_id())
and animal_latest != null
and animal_latest.get_status() == PlayerQuestRecord.STATUS_COMPLETED
and is_equal_approx(
animal_manager.get_player_standing().get_standing(),
standing_before_animal + animal_quest.get_standing_reward()
)
),
"Feeding the goat should complete its quest and grant standing",
)
var animal_saved: String = animal_manager.serialize_state()
var animal_restored := _create_manager(907)
_check(
animal_restored.restore_state_from_json(animal_saved),
"The completed animal-care quest should restore through the current schema"
)
_check(
(
animal_restored.get_state_checksum() == animal_manager.get_state_checksum()
and animal_restored.get_active_player_quest() == null
),
"Restored animal-care state should preserve checksum and closed quest",
)
animal_restored.free()
goat.free()
animal_manager.free()
_finish()
manager.free()
invalidated.free()
_finish()