extends Node const GAME := preload("res://scenes/game/game.tscn") const GENERATOR := preload("res://scripts/items/item_generator.gd") func equip(inventory: ShipInventory, id: String, slot: int) -> void: for index in inventory.cargo.size(): var item := inventory.cargo[index] if item != null and item.definition.item_id == id: assert(inventory.move_item("cargo", index, "module", slot)) return assert(false, "Starter extension missing: " + id) func _ready() -> void: GameState.start_new_run() var game := GAME.instantiate() add_child(game) await get_tree().process_frame var ship: CharacterBody2D = game.get_node("PlayerShip") ship.set_physics_process(false) var inventory: ShipInventory = ship.get_node("ShipInventory") equip(inventory, "afterburner", 0) equip(inventory, "shield_charge", 1) equip(inventory, "repair_drones", 5) assert(ship.call("get_active_ability", 2) == null) assert(not ship.call("activate_ability", 2)) ship.set("energy", ship.get("max_energy") - 0.01) assert(not ship.call("activate_ability", 0)) assert(not ship.call("activate_ability", 1)) ship.set("energy", ship.get("max_energy")) assert(not ship.call("activate_ability", 1)) # Full shields: no wasted energy. ship.set("shields", ship.get("max_shields") - 30.0) assert(ship.call("activate_ability", 1)) assert(ship.get("shields") == ship.get("max_shields") and ship.get("energy") == 0.0) ship.set("shields", 0.0) ship.set("energy", ship.get("max_energy")) assert(ship.call("activate_ability", 1)) assert(ship.get("shields") == minf(100.0, ship.get("max_shields"))) assert(not inventory.delete_cargo_item(-1)) assert(GameState.captain.parts == 0.0) assert(inventory.delete_cargo_item(0)) assert(not inventory.delete_cargo_item(0)) assert(GameState.captain.parts == 10.0) ship.set("hull", ship.get("max_hull") - 4.25) ship.set("energy", 0.0) assert(ship.call("activate_ability", 5)) assert(ship.get("hull") == ship.get("max_hull")) assert(is_equal_approx(GameState.captain.parts, 5.75) and ship.get("energy") == 0.0) assert(not ship.call("activate_ability", 5)) ship.set("hull", ship.get("max_hull") - 20.0) assert(ship.call("activate_ability", 5)) assert(GameState.captain.parts == 0.0) assert(not ship.call("activate_ability", 5)) ship.set("energy", ship.get("max_energy")) ship.velocity = Vector2.ZERO var key := InputEventKey.new() key.physical_keycode = KEY_1 key.pressed = true ship.call("_unhandled_key_input", key) assert(ship.get("energy") == 0.0 and ship.call("is_boosting")) assert(not ship.call("activate_ability", 0)) ship.call("_physics_process", 0.1) var first_speed := ship.velocity.length() assert(first_speed > 0.0 and first_speed < ship.get("max_speed") * 3.0) ship.call("_physics_process", 0.1) ship.call("_physics_process", 0.1) assert(is_equal_approx(ship.velocity.length(), ship.get("max_speed") * 3.0)) ship.call("_physics_process", 0.1) assert(ship.velocity.length() < ship.get("max_speed") * 3.0 and ship.velocity.length() > ship.get("max_speed")) for frame in 300: ship.call("_physics_process", 0.1) assert(not ship.call("is_boosting")) ship.set("is_docked", true) ship.set("energy", ship.get("max_energy")) assert(not ship.call("activate_ability", 0)) ship.set("is_docked", false) var item := inventory.get_item("module", 0) assert(inventory.move_item("module", 0, "cargo", 0)) assert(ship.call("get_active_ability", 0) == null) assert(inventory.move_item("cargo", 0, "module", 3)) assert(ship.call("get_active_ability", 3) == item.definition.active_ability) for definition in GENERATOR.DEFINITIONS: if definition.category == ItemDefinition.Category.ACTIVE_EXTENSION: var loot := GENERATOR.generate_for_definition(definition, 100) assert(loot.definition.active_ability != null and not loot.additional_modifiers.is_empty()) GameState.captain.parts = 17.5 inventory.preserve_for_restart() game.queue_free() await get_tree().process_frame var restarted := GAME.instantiate() add_child(restarted) await get_tree().process_frame assert(GameState.captain.parts == 17.5) assert(restarted.get_node("PlayerShip/ShipInventory").get_item("module", 3) == item) assert(not restarted.get_node("PlayerShip").call("is_boosting")) print("ACTIVE_ABILITIES_TEST: PASS — costs, hotkeys, boost ramp/decay, salvage, repairs, equipment, loot, restart")