Files
DungeonCrawlerWorld/tests/e2e/test_enemy_ai_e2e.gd
2026-10-03 01:22:20 -04:00

39 lines
1.7 KiB
GDScript

extends GutTest
const ActorState = preload("res://scripts/domain/actor_state.gd")
const GridMapState = preload("res://scripts/domain/grid_map_state.gd")
const GameScene = preload("res://scenes/Game.tscn")
func test_real_game_enemy_detects_approaches_attacks_and_dies_with_feedback() -> void:
var game := GameScene.instantiate() as Game
add_child_autofree(game)
await get_tree().process_frame
var state := game.get_game_state()
var enemy: ActorState = state.enemies[&"goblin"]
enemy.cell = state.player.cell + Vector2i(3, 0)
enemy.hit_points = 3
enemy.max_hit_points = 3
enemy.content_id = &"enemy_goblin"
enemy.ai_behavior = &"aggressive"
enemy.vision_range = 6
var approach := game.submit_test_action(Vector2i.DOWN)
assert_eq(approach.map(func(result: TurnResult) -> StringName: return result.kind), [&"moved", &"enemy_moved"])
assert_eq(enemy.cell, Vector2i(6, 12))
assert_ne(enemy.cell, state.player.cell)
# A real contextual action keeps the player in place, allowing the detected
# enemy to execute its adjacent C2 melee turn.
enemy.cell = state.player.cell + Vector2i.RIGHT
state.map.set_cell(state.player.cell + Vector2i.UP, GridMapState.CellKind.CHEST)
var attack := game.submit_test_interact()
assert_eq(attack.map(func(result: TurnResult) -> StringName: return result.kind), [&"chest_opened", &"enemy_melee"])
assert_eq(state.player.hit_points, 10)
var death := game.submit_test_action(Vector2i.RIGHT)
assert_eq(death.map(func(result: TurnResult) -> StringName: return result.kind), [&"melee", &"enemy_defeated"])
assert_false(state.enemies.has(&"goblin"))
await get_tree().create_timer(1.2).timeout
assert_eq(game.get_node("World/Enemies").get_child_count(), 0)
assert_string_contains(game.get_node("HUD/EventLog").get_parsed_text(), "defeated")