extends GutTest const GridMapState = preload("res://scripts/domain/grid_map_state.gd") const ActorState = preload("res://scripts/domain/actor_state.gd") const GameState = preload("res://scripts/domain/game_state.gd") func _state_with_chest(chest: Vector2i, player: Vector2i = Vector2i(3, 3)) -> GameState: var map := GridMapState.new(Vector2i(9, 7), GridMapState.CellKind.FLOOR) map.set_cell(chest, GridMapState.CellKind.CHEST) return GameState.new(map, ActorState.new(&"player", player, 12, 3), {&"goblin": ActorState.new(&"goblin", Vector2i(7, 3), 6, 2)}) func test_closed_chest_is_not_walkable_and_movement_is_blocked_without_an_enemy_turn() -> void: var state := _state_with_chest(Vector2i(4, 3)) var results := state.try_player_action(Vector2i.RIGHT) assert_false(state.map.is_walkable(Vector2i(4, 3))) assert_eq(results.size(), 1) assert_eq(results[0].kind, &"blocked") assert_eq(state.player.cell, Vector2i(3, 3)) func test_chest_is_the_context_target_before_doors_but_stairs_keep_priority() -> void: var state := _state_with_chest(Vector2i(3, 2)) state.map.set_cell(Vector2i(4, 3), GridMapState.CellKind.CLOSED_DOOR) assert_eq(state.get_context_target(), &"chest") state.map.set_cell(state.player.cell, GridMapState.CellKind.STAIRS) assert_eq(state.get_context_target(), &"stairs") func test_opening_chest_replaces_it_with_floor_refreshes_fov_and_gets_one_enemy_response() -> void: var chest := Vector2i(3, 2) var revealed := Vector2i(3, 1) var state := _state_with_chest(chest) state.map.set_cell(revealed, GridMapState.CellKind.FLOOR) assert_false(state.visible_cells.has(revealed)) var results := state.try_interact() var enemy_response_count := 0 for result in results: if String(result.kind).begins_with("enemy_"): enemy_response_count += 1 assert_eq(results[0].kind, &"chest_opened") assert_eq(results[0].message, "You open the chest.") assert_eq(results[0].to_cell, chest) assert_eq(state.map.get_cell(chest), GridMapState.CellKind.FLOOR) assert_true(state.map.is_walkable(chest)) assert_true(state.visible_cells.has(revealed)) assert_eq(enemy_response_count, 1)