Files
aetherbound-guild/runtime/tests/p9_0r5_first_session_arc_test.gd
T

150 lines
6.2 KiB
GDScript

extends SceneTree
const MainScene = preload("res://main.tscn")
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
var game := MainScene.instantiate()
game.auto_boot = false
root.add_child(game)
await settle(10)
game.locale = "zh_CN"
game.muted = true
prepare_second_result(game, "Hearthguard", "Farstring", "EQ-002")
game.open_guild_return()
expect(game.page == game.AppPage.GUILD_RETURN, "second result returns to Guild")
expect(game.coin == 20 and game.guild_choice.is_empty(), "Guild opens with 20 Coin and no preselection")
expect(find_control(game, "GuildChoice_retain_item") != null and find_control(game, "GuildChoice_recruit_rear") != null, "both Guild responses render")
var depart := find_control(game, "BeginThirdBattle") as BaseButton
expect(depart != null and depart.disabled, "third departure waits for a choice")
game.choose_guild_option("invalid")
expect(game.guild_choice.is_empty(), "invalid Guild choice is rejected")
game.coin = 11
game.choose_guild_option("retain_item")
expect(game.guild_choice.is_empty() and game.coin == 11, "insufficient Coin cannot select an unaffordable response")
game.coin = 20
game.choose_guild_option("retain_item")
expect(game.coin == 20, "selection does not spend Coin")
game.choose_guild_option("recruit_rear")
expect(game.guild_choice == "recruit_rear" and game.coin == 20, "Guild choice can be revised before commit")
game.choose_guild_option("retain_item")
game.coin = 10
game.begin_third_battle()
expect(game.page == game.AppPage.GUILD_RETURN and not game.guild_committed and game.coin == 10, "commit rechecks Coin without partial mutation")
game.coin = 20
game.begin_third_battle()
expect(game.guild_committed and game.coin == 8, "retain commit spends 12 Coin exactly once")
expect(game.retained_item == "EQ-002" and game.added_rear.is_empty(), "retain route keeps item and has no added rear")
game.begin_third_battle()
expect(game.coin == 8, "duplicate departure cannot spend twice")
var safe_time := resolve_third_battle(game)
expect(game.page == game.AppPage.SESSION_RESULT, "retain route reaches session result")
expect(game.front_hp == 90 and game.enemy_hp == 0, "Frontpin Farstring route ends at 90 HP and wins")
expect(is_equal_approx(safe_time, 7.60), "Frontpin route declares 7.60 seconds")
expect(find_control(game, "SessionResultFacts") != null, "session result renders exact facts")
game.clear_experience()
prepare_second_result(game, "Wayrunner", "Kindhand", "EQ-002")
game.open_guild_return()
game.choose_guild_option("retain_item")
game.begin_third_battle()
resolve_third_battle(game)
expect(game.front_hp == 100 and game.coin == 8, "Frontpin Kindhand route heals to 100 and keeps 8 Coin")
game.clear_experience()
prepare_second_result(game, "Hearthguard", "Farstring", "EQ-061")
game.open_guild_return()
game.choose_guild_option("retain_item")
game.begin_third_battle()
var fast_time := resolve_third_battle(game)
expect(game.front_hp == 70 and game.coin == 8, "Early Bell Farstring route accepts 70 HP and keeps 8 Coin")
expect(is_equal_approx(fast_time, 6.60) and fast_time < safe_time, "Early Bell route declares 6.60 seconds and is faster")
game.clear_experience()
prepare_second_result(game, "Wayrunner", "Kindhand", "EQ-061")
game.open_guild_return()
game.choose_guild_option("retain_item")
game.begin_third_battle()
resolve_third_battle(game)
expect(game.front_hp == 82, "Early Bell Kindhand route heals 70 to 82")
game.go_home()
expect(game.page == game.AppPage.TITLE and game.coin == 0 and game.added_rear.is_empty(), "Home clears the full three-battle session")
for original_rear in ["Farstring", "Kindhand"]:
game.clear_experience()
prepare_second_result(game, "Hearthguard", original_rear, "EQ-002")
game.open_guild_return()
game.choose_guild_option("recruit_rear")
game.begin_third_battle()
expect(game.coin == 6 and game.retained_item.is_empty(), "recruit route spends 14 Coin and returns the loan")
expect(game.added_rear == ("Kindhand" if original_rear == "Farstring" else "Farstring"), "recruit route adds the missing rear role")
var recruit_time := resolve_third_battle(game)
expect(game.front_hp == 82 and game.enemy_hp == 0, "both recruit formations end at 82 HP and win")
expect(is_equal_approx(recruit_time, 7.00), "recruit route declares 7.00 seconds")
expect(game.battle_feedback_history.size() == 5, "recruit route emits exactly five HP mutations")
game.request_restart()
game.confirm_restart()
expect(game.page == game.AppPage.TITLE, "confirmed Restart returns to Title")
expect(game.coin == 0 and game.guild_choice.is_empty() and game.retained_item.is_empty() and game.added_rear.is_empty(), "Restart clears the full three-battle session")
game.queue_free()
await settle(90)
if failures.is_empty():
print("ABG_P9_0R5_FIRST_SESSION_OK unselected=true revision=true spend_once=true coin=8,6 company=2,3 hp=90,100,70,82 times=7.60,6.60,7.00 routes=6 cleanup=true")
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func prepare_second_result(game: Control, front: String, rear: String, item: String) -> void:
game.front_choice = front
game.rear_choice = rear
game.coin = 20
game.first_reward_committed = true
game.adaptation_choice = item
game.adaptation_committed = true
game.front_hp = 90 if item == "EQ-002" else 70
game.enemy_hp = 0
game.second_result_time = 7.05 if item == "EQ-002" else 6.00
game.page = game.AppPage.SECOND_RESULT
game.render()
func resolve_third_battle(game: Control) -> float:
var declared_time := 0.0
for phase in range(7):
var duration: float = game.phase_duration(phase)
declared_time += duration
game.third_battle_elapsed += duration
game.advance_battle_phase()
return declared_time
func find_control(node: Node, node_name: String) -> Control:
if node.name == node_name and node is Control and not node.is_queued_for_deletion():
return node
for child in node.get_children():
var found := find_control(child, node_name)
if found != null:
return found
return null
func settle(frames: int) -> void:
for frame in range(frames):
await process_frame
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("P9.0R5 first session: %s" % message)