Randoloot/tests/distant_defeat_return.gd
2026-10-25 16:12:08 +01:00

85 lines
4.0 KiB
GDScript

extends Node
var is_runner := false
func _ready() -> void:
if not is_runner:
var runner = get_script().new()
runner.is_runner = true
get_tree().root.add_child.call_deferred(runner)
else:
_run.call_deferred()
func frames(count := 5) -> void:
for frame in count: await get_tree().process_frame
func freeze(game: Node) -> void:
game.set_physics_process(false)
game.player.set_physics_process(false)
game.player.get_node("WeaponController").set_physics_process(false)
for enemy in get_tree().get_nodes_in_group("enemies"): enemy.set_physics_process(false)
func _run() -> void:
GameState.start_new_run()
GameState.system_level = 7
GameState.system_seed = 777
GameState.remember_system()
GameState.hull_bastion_used = true
var progress: Resource = GameState.captain.expedition
progress.distant_maps["defeat_test"] = {"id":"defeat_test","level":125,"seed":123456,"name":"Sektor testowy","source_planet":"Test","source_level":120}
progress.deuter = 130000
assert(GameState.depart_distant("defeat_test"))
assert(not GameState.hull_bastion_used,"New expedition receives its own Last Bastion use")
GameState.hull_bastion_used = true
assert(not progress.distant_maps.has("defeat_test") and progress.deuter==5000)
get_tree().change_scene_to_file("res://scenes/game/game.tscn")
await frames()
var game := get_tree().current_scene
freeze(game)
var inventory: ShipInventory = game.player.get_node("ShipInventory")
var weapon: ItemInstance = inventory.weapon_slots[0]
weapon.special_orbs.append("piercing")
inventory.ammunition = 123
progress.distant_maps["found_on_expedition"] = {"id":"found_on_expedition","level":130,"seed":98765,"name":"Zdobyta mapa"}
GameState.explored_pois["777:kept"] = true
game.player._destroy_ship()
var explosion: Node = game.get_node("PlayerDestructionEffect")
explosion.set_process(false)
explosion._process(6.0)
assert(game.has_node("DefeatOverlay"))
var overlay: Node = game.get_node("DefeatOverlay")
var retry: Button = overlay.find_child("RetryButton",true,false)
assert(retry.text.contains("UKŁADU 7") and not retry.text.contains("PONOWNIE"))
overlay._retry()
overlay._retry()
await frames(10)
game = get_tree().current_scene
freeze(game)
assert(GameState.system_level==7 and GameState.system_seed==777)
assert(GameState.active_distant_map.is_empty() and GameState.distant_home.is_empty())
assert(GameState.hull_bastion_used,"Return restores the home's spent Last Bastion use")
assert(not progress.distant_maps.has("defeat_test") and progress.distant_maps.has("found_on_expedition"))
assert(progress.deuter==5000,"Defeat cannot refund flight fuel")
assert(not GameState.depart_distant("defeat_test"),"Consumed expedition cannot be retried")
assert(GameState.explored_pois.has("777:kept"),"Failed expedition must not reset home exploration")
assert(game.has_node("Freighter") and not game.has_node("DistantSector"))
inventory = game.player.get_node("ShipInventory")
assert(inventory.ammunition==123 and "piercing" in inventory.weapon_slots[0].special_orbs)
assert(not game.player._is_destroyed)
assert(game.player.is_docked and is_instance_valid(game.get_node("PlanetExpeditions").screen))
game.get_node("PlanetExpeditions")._leave()
GameState.explored_pois["777:regular_retry"] = true
game.player._destroy_ship()
explosion = game.get_node("PlayerDestructionEffect")
explosion.set_process(false)
explosion._process(6.0)
game.get_node("DefeatOverlay")._retry()
await frames(10)
game = get_tree().current_scene
freeze(game)
assert(GameState.system_level==7 and GameState.system_seed==777)
assert(GameState.asteroid_retry_seeds.has(777) and not GameState.explored_pois.has("777:regular_retry"))
assert(not game.player.is_docked and not get_tree().paused,"Normal-system defeat still retries the current system")
assert(GameState.hull_bastion_used,"Retry cannot renew Last Bastion")
assert(not progress.distant_maps.has("defeat_test") and progress.deuter==5000)
print("DISTANT_DEFEAT_RETURN: PASS (original system and seed, consumed map/fuel, preserved inventory and found maps, freighter docking, duplicate retry guarded)")