feat: implement pet companion commands and support

This commit is contained in:
goose
2026-10-03 17:40:06 -04:00
parent 86a67a6d3c
commit 2bd2589810
21 changed files with 568 additions and 5 deletions
+67
View File
@@ -0,0 +1,67 @@
extends GutTest
const ActorState = preload("res://scripts/domain/actor_state.gd")
const CompanionState = preload("res://scripts/domain/entities/companion_state.gd")
const GameScene = preload("res://scenes/Game.tscn")
const RunSettings = preload("res://scripts/domain/run/run_settings.gd")
var game: Game
func before_each() -> void:
game = GameScene.instantiate()
game.configure_new_run(RunSettings.new("E4-PET-E2E", &"crawler", false, true), "Pet Tester", &"vanguard")
add_child_autofree(game)
await get_tree().process_frame
await get_tree().process_frame
func test_pet_choice_spawns_visible_companion_and_real_input_changes_command_stance() -> void:
var companion := game.get_game_state().companion
assert_not_null(companion)
assert_true(companion.is_alive())
assert_not_null(game.get_node_or_null("World/Companion"))
var panel := game.get_node("HUD/CompanionPanel") as PanelContainer
assert_false(panel.visible)
await _dispatch_key(KEY_K)
assert_true(panel.visible)
assert_string_contains((panel.get_node("Body") as RichTextLabel).get_parsed_text(), "Follow")
await _dispatch_key(KEY_RIGHT)
assert_eq(companion.stance, CompanionState.Stance.DEFEND)
assert_string_contains(String(game.get_run_state().recent_events(1)[0].kind), "companion_stance")
await _dispatch_key(KEY_ESCAPE)
assert_false(panel.visible)
func test_live_enemy_attack_is_intercepted_in_support_and_companion_death_leaves_player_run_alive() -> void:
var state := game.get_game_state()
var companion := state.companion
companion.actor.hit_points = 1
companion.actor.max_hit_points = 1
companion.actor.cell = state.player.cell + Vector2i.RIGHT
assert_true(companion.set_stance(CompanionState.Stance.SUPPORT))
var enemy: ActorState = state.enemies.values()[0]
enemy.cell = state.player.cell + Vector2i.LEFT
enemy.weapon_damage = 20
enemy.attack_damage = 20
enemy.ai_behavior = &"aggressive"
enemy.vision_range = 6
state.map.set_cell(state.player.cell + Vector2i.UP, GridMapState.CellKind.CHEST)
await _dispatch_key(KEY_E)
assert_eq(state.player.hit_points, state.player.max_hit_points)
assert_false(companion.is_alive())
assert_not_null(game.get_node_or_null("World/Companion"))
assert_string_contains((game.get_node("HUD/EventLog") as RichTextLabel).get_parsed_text(), "companion")
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
+1
View File
@@ -0,0 +1 @@
uid://d4ar3dlxopohr