feat: add safe rooms and repeatable Bobka rations

This commit is contained in:
goose
2026-10-04 11:08:19 -04:00
parent 34eb08f02a
commit 9bd003102c
16 changed files with 297 additions and 2 deletions
+70
View File
@@ -0,0 +1,70 @@
extends GutTest
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
const SafeRoomServiceType = preload("res://scripts/domain/world/safe_room_service.gd")
const GameScene = preload("res://scenes/Game.tscn")
var game: Game
func before_each() -> void:
game = GameScene.instantiate()
add_child_autofree(game)
await get_tree().process_frame
func test_real_bobka_dialogue_gives_three_free_rations_in_safe_room() -> void:
var catalog := ContentCatalogType.load_from_directory("res://data/ascii")
var floor := FloorGeneratorType.generate("BOBKA-E2E", 4, catalog)
var safe_room: RoomState = floor.safe_rooms()[0]
var bobka := _bobka_in_room(floor, safe_room)
var bed: Vector2i = floor.bed_cells_in(safe_room)[0]
var run := game.get_run_state()
var state := game.get_game_state()
run.set_floor_state(floor)
run.current_floor = 4
state.set_floor_state(floor)
state.content_catalog = catalog
state.player.cell = bobka.cell + Vector2i.LEFT
var gold_before := run.gold
var no_events: Array[GameEvent] = []
game.get_node("HUD").refresh(state, no_events, run)
assert_ne(floor.room_at(floor.entrance).kind, &"refuge")
assert_ne(floor.room_at(floor.entrance).kind, &"sanctuary")
assert_eq(Array(SafeRoomServiceType.validate_floor(floor)), [])
assert_true(SafeRoomServiceType.can_rest(floor, bed))
state.player.cell = bed
game.get_node("HUD").refresh(state, no_events, run)
assert_string_contains((game.get_node("HUD/ContextPromptLabel") as Label).text, "Se reposer")
state.player.cell = bobka.cell + Vector2i.LEFT
for ration_number in range(3):
await _dispatch_key(KEY_E)
var panel := game.get_node("HUD/DialoguePanel") as PanelContainer
assert_true(panel.visible, "ration %d opens Bobka dialogue" % (ration_number + 1))
assert_string_contains((game.get_node("HUD/DialoguePanel/Entries") as RichTextLabel).get_parsed_text(), "Prendre une ration.")
await _dispatch_key(KEY_ENTER)
assert_eq(run.inventory.count_by_definition(&"consumable_ration"), ration_number + 1)
assert_eq(run.gold, gold_before)
assert_true(run.recent_events(3).any(func(event: GameEvent) -> bool: return event.kind == &"bobka_ration_given"))
await _dispatch_key(KEY_ENTER)
assert_false(panel.visible)
func _bobka_in_room(floor: FloorState, room: RoomState) -> ActorState:
for npc: ActorState in floor.npcs.values():
if npc.content_id == &"npc_bobka" and room.bounds.has_point(npc.cell):
return npc
return null
func _dispatch_key(keycode: Key) -> void:
Input.parse_input_event(_key_event(keycode, true))
await get_tree().process_frame
Input.parse_input_event(_key_event(keycode, false))
await get_tree().process_frame
func _key_event(keycode: Key, pressed: bool) -> InputEventKey:
var event := InputEventKey.new()
event.keycode = keycode
event.physical_keycode = keycode
event.pressed = pressed
return event
@@ -0,0 +1 @@
uid://cuwm0yskud28x
@@ -0,0 +1,29 @@
extends GutTest
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
const SafeRoomServiceType = preload("res://scripts/domain/world/safe_room_service.gd")
const ASCII_CATALOG_PATH := "res://data/ascii"
func test_twenty_seeds_keep_entrance_non_safe_and_bed_free() -> void:
for seed_index in range(20):
var floor := _generate("SAFE-START-%d" % seed_index)
var entrance_room: RoomState = floor.room_at(floor.entrance)
assert_false(entrance_room.kind in SafeRoomServiceType.SAFE_ROOM_KINDS, "seed %d entrance is never safe" % seed_index)
assert_false(floor.metadata.get("bed_cells", []).has(floor.entrance), "seed %d entrance has no bed" % seed_index)
assert_false(floor.npcs.values().any(func(npc: ActorState) -> bool: return npc.cell == floor.entrance), "seed %d entrance has no NPC" % seed_index)
func test_twenty_seeds_guarantee_safe_rooms_beds_and_bobka() -> void:
for seed_index in range(20):
var floor := _generate("SAFE-%d" % seed_index)
var safe_rooms: Array[RoomState] = floor.safe_rooms()
assert_gt(safe_rooms.size(), 0, "seed %d has a non-entrance safe room" % seed_index)
assert_eq(Array(SafeRoomServiceType.validate_floor(floor)), [], "seed %d satisfies safe-room invariants" % seed_index)
for room: RoomState in safe_rooms:
var beds: Array[Vector2i] = floor.bed_cells_in(room)
assert_eq(beds.size(), 1, "seed %d safe room %s has one bed" % [seed_index, room.id])
assert_true(floor.npcs.values().any(func(npc: ActorState) -> bool: return npc.content_id == &"npc_bobka" and room.bounds.has_point(npc.cell)), "seed %d safe room %s has Bobka" % [seed_index, room.id])
func _generate(seed: String) -> FloorState:
return FloorGeneratorType.generate(seed, 4, ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH))
@@ -0,0 +1 @@
uid://dsysgwqhw1hf8
+34
View File
@@ -0,0 +1,34 @@
extends GutTest
const ContentCatalogType = preload("res://scripts/domain/content/content_catalog.gd")
const FloorGeneratorType = preload("res://scripts/domain/world/floor_generator.gd")
const RunSettingsType = preload("res://scripts/domain/run/run_settings.gd")
const RunStateType = preload("res://scripts/domain/run/run_state.gd")
const SafeRoomServiceType = preload("res://scripts/domain/world/safe_room_service.gd")
const ASCII_CATALOG_PATH := "res://data/ascii"
func test_safe_room_contract_accepts_a_generated_non_surface_floor() -> void:
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
var floor := FloorGeneratorType.generate("SAFE-SERVICE", 4, catalog)
assert_eq(Array(SafeRoomServiceType.validate_floor(floor)), [])
assert_gt(floor.safe_rooms().size(), 0)
for room: RoomState in floor.safe_rooms():
assert_true(SafeRoomServiceType.is_safe_room(room))
assert_true(SafeRoomServiceType.can_rest(floor, room.bounds.get_center()))
func test_bobka_ration_is_repeatable_and_free() -> void:
var catalog := ContentCatalogType.load_from_directory(ASCII_CATALOG_PATH)
var run := RunStateType.new("SAFE-RATION", RunSettingsType.new("SAFE-RATION"))
run.content_catalog = catalog
run.gold = 47
var gold_before := run.gold
var first: Array[GameEvent] = SafeRoomServiceType.give_bobka_ration(run, &"npc_bobka_00")
var second: Array[GameEvent] = SafeRoomServiceType.give_bobka_ration(run, &"npc_bobka_00")
assert_eq(run.inventory.count_by_definition(&"consumable_ration"), 2)
assert_eq(run.gold, gold_before)
assert_eq(first.map(func(event: GameEvent) -> StringName: return event.kind), [&"item_granted", &"bobka_ration_given"])
assert_eq(second.map(func(event: GameEvent) -> StringName: return event.kind), [&"item_granted", &"bobka_ration_given"])
+1
View File
@@ -0,0 +1 @@
uid://donevcqeo5rwg