Files
DungeonCrawlerWorld/tests/e2e/test_death_mode_e2e.gd

98 lines
4.9 KiB
GDScript

extends GutTest
const GameScene = preload("res://scenes/Game.tscn")
const MainMenuScene = preload("res://scenes/menu/MainMenu.tscn")
const RunSettingsType = preload("res://scripts/domain/run/run_settings.gd")
const ItemDefinitionType = preload("res://scripts/domain/items/item_definition.gd")
const ItemInstanceType = preload("res://scripts/domain/items/item_instance.gd")
const PHYLACTERY_ID: StringName = &"misc_phylactere_narratif"
func test_classic_death_ends_actions_shows_death_panel_and_preserves_the_run_slot() -> void:
var game := await _game(false)
_kill_player_through_real_enemy_turn(game)
var panel := game.get_node("HUD/DeathPanel") as PanelContainer
assert_true(game.get_run_state().is_game_over)
assert_eq(game.get_run_state().slot_policy, &"preserve")
assert_true(panel.visible)
assert_string_contains((panel.get_node("Layout/Body") as RichTextLabel).get_parsed_text(), "Classique")
assert_true((panel.get_node("Layout/Actions/LoadButton") as Button).visible)
var navigation: Array[StringName] = []
game.connect("death_navigation_requested", func(action: StringName) -> void: navigation.append(action))
(panel.get_node("Layout/Actions/NewRunButton") as Button).pressed.emit()
assert_eq(navigation, [&"new_run"])
assert_true(game.get_run_state().recent_events(game.get_run_state().log.size()).any(func(event: GameEvent) -> bool: return event.kind == &"run_ended"))
assert_eq(game.submit_test_action(Vector2i.RIGHT), [])
func test_permadeath_death_retires_the_run_slot_and_reports_the_mode() -> void:
var game := await _game(true)
_kill_player_through_real_enemy_turn(game)
var panel := game.get_node("HUD/DeathPanel") as PanelContainer
assert_true(game.get_run_state().is_game_over)
assert_eq(game.get_run_state().slot_policy, &"retire")
assert_true(panel.visible)
assert_string_contains((panel.get_node("Layout/Body") as RichTextLabel).get_parsed_text(), "permanente")
assert_false((panel.get_node("Layout/Actions/LoadButton") as Button).visible)
var navigation: Array[StringName] = []
game.connect("death_navigation_requested", func(action: StringName) -> void: navigation.append(action))
(panel.get_node("Layout/Actions/MenuButton") as Button).pressed.emit()
assert_eq(navigation, [&"menu"])
assert_true(game.get_run_state().recent_events(game.get_run_state().log.size()).any(func(event: GameEvent) -> bool: return event.kind == &"permadeath_run_retired"))
func test_death_navigation_returns_to_the_real_main_menu_and_opens_requested_flow() -> void:
var menu := MainMenuScene.instantiate() as MainMenu
add_child_autofree(menu)
await get_tree().process_frame
await get_tree().process_frame
menu._start_new_run(RunSettingsType.new("death-nav", &"crawler", false), "Death Nav")
await get_tree().process_frame
var game := menu.get_node("Game") as Game
game.death_navigation_requested.emit(&"new_run")
await get_tree().process_frame
assert_null(menu.get_node_or_null("Game"))
assert_false(menu.get_node("Menu").visible)
assert_true(menu.get_node("CharacterCreation").visible)
func test_qualified_narrative_resurrection_continues_the_real_game_without_showing_death_panel() -> void:
var game := await _game(true)
var state := game.get_game_state()
game.get_run_state().inventory.add_item(ItemInstanceType.new(ItemDefinitionType.from_catalog(game.spell_catalog, PHYLACTERY_ID)))
var end_before := game.get_dialogue_player().attributes.get_attribute(&"end")
_kill_player_through_real_enemy_turn(game)
var panel := game.get_node("HUD/DeathPanel") as PanelContainer
assert_false(game.get_run_state().is_game_over)
assert_eq(game.get_run_state().slot_policy, &"active")
assert_false(panel.visible)
assert_eq(state.player.hit_points, maxi(1, int(state.player.max_hit_points * 0.25)))
assert_eq(game.get_dialogue_player().attributes.get_attribute(&"end"), end_before - 1)
assert_true(game.get_dialogue_player().flags.get(&"marked_by_death", false))
assert_false(game.get_run_state().inventory.items.any(func(item: ItemInstance) -> bool: return item.definition.id == PHYLACTERY_ID))
assert_true(game.get_run_state().recent_events(game.get_run_state().log.size()).any(func(event: GameEvent) -> bool: return event.kind == &"narrative_resurrection"))
func _kill_player_through_real_enemy_turn(game: Game) -> void:
var state := game.get_game_state()
var enemy: ActorState = state.enemies.get(&"goblin")
if enemy == null:
enemy = ActorState.new(&"goblin", state.player.cell + Vector2i.RIGHT, 6, 2)
state.enemies[enemy.id] = enemy
enemy.cell = state.player.cell + Vector2i.RIGHT
enemy.weapon_damage = state.player.hit_points
enemy.damage_variance = 0
enemy.accuracy = 30
var results: Array[TurnResult] = []
TurnResolver.append_enemy_response(state, results)
game._resolve_player_action(results, false)
func _game(permadeath: bool) -> Game:
var game := GameScene.instantiate() as Game
game.configure_new_run(RunSettingsType.new("F6-E2E", &"crawler", permadeath), "F6 Hero")
add_child_autofree(game)
await get_tree().process_frame
return game