113 lines
5.9 KiB
GDScript
113 lines
5.9 KiB
GDScript
extends "res://tests/distant_integration.gd"
|
|
const SERVICE := preload("res://scripts/planets/time_engineer.gd")
|
|
const ITEM_GENERATOR := preload("res://scripts/items/item_generator.gd")
|
|
func _run() -> void:
|
|
await super._run()
|
|
var game := get_tree().current_scene
|
|
var player := game.get_node("PlayerShip")
|
|
var inventory := player.get_node("ShipInventory")
|
|
var progress: Resource = GameState.captain.expedition
|
|
var saved_item: ItemInstance = inventory.cargo[0]
|
|
progress.active = true
|
|
for definition in ITEM_GENERATOR.DEFINITIONS:
|
|
var item := ITEM_GENERATOR.generate_for_definition(definition,20,2)
|
|
if item.additional_modifiers.is_empty(): continue
|
|
item.special_orbs.assign(["piercing"] if definition.category == ItemDefinition.Category.WEAPON else [])
|
|
var effects := item.special_orbs.duplicate()
|
|
inventory.cargo[0] = item
|
|
for addon in item.additional_modifiers.size():
|
|
item.additional_modifiers[addon].value = item.additional_modifiers[addon].affix.get_value_range(20).x
|
|
var selected := -1
|
|
for addon in item.additional_modifiers.size():
|
|
if SERVICE.can_maximize(item,addon):
|
|
selected = addon
|
|
break
|
|
if selected < 0:
|
|
progress.time_crystals = 200
|
|
check(not SERVICE.maximize(progress,inventory,item,0) and progress.time_crystals==200,"Fixed addons already maximum and free")
|
|
continue
|
|
var old: ItemStatModifier = item.additional_modifiers[selected]
|
|
var values: Array[float] = []
|
|
for modifier in item.additional_modifiers: values.append(modifier.value)
|
|
progress.time_crystals = 199
|
|
check(not SERVICE.maximize(progress,inventory,item,selected),"Cannot maximize without crystals")
|
|
check(progress.time_crystals==199,"Rejected service free")
|
|
progress.time_crystals = 200
|
|
check(SERVICE.maximize(progress,inventory,item,selected),"Maximize available addon")
|
|
check(progress.time_crystals==0,"Exact crystal price")
|
|
check(is_equal_approx(item.additional_modifiers[selected].value,SERVICE.maximum(item,selected)),"Maximum at current level")
|
|
check(item.additional_modifiers[selected] != old and old.value==values[selected],"Shared modifier unchanged")
|
|
check(item.special_orbs==effects and item.item_level==20,"Effects and level unchanged")
|
|
for index in values.size():
|
|
if index != selected: check(item.additional_modifiers[index].value==values[index],"Only selected addon changed")
|
|
progress.time_crystals = 200
|
|
check(not SERVICE.maximize(progress,inventory,item,selected) and progress.time_crystals==200,"Already maximum not charged")
|
|
check(not SERVICE.maximize(progress,inventory,item,-1),"Invalid index rejected")
|
|
var test_item := ITEM_GENERATOR.generate_for_definition(preload("res://resources/items/plasma_cannon.tres"),125,2)
|
|
check(SERVICE.cost(test_item)==1250,"Level 125 price")
|
|
test_item.item_level = 1000
|
|
check(SERVICE.cost(test_item)==10000,"Level 1000 price")
|
|
check(not SERVICE.maximize(progress,inventory,test_item,0),"Unowned item rejected")
|
|
inventory.cargo[0] = saved_item
|
|
progress.active = false
|
|
var crystals := Node2D.new()
|
|
crystals.set_script(preload("res://scripts/items/time_crystal_pickup.gd"))
|
|
crystals.amount = 7
|
|
crystals.position = player.position
|
|
game.add_child(crystals)
|
|
var previous: int = progress.time_crystals
|
|
crystals._physics_process(0)
|
|
crystals._physics_process(0)
|
|
check(progress.time_crystals==previous+7,"Crystal collected once")
|
|
await frames()
|
|
check(LOOT.crystal_amount(125,0,2)==26 and LOOT.crystal_amount(125,2,2)==130,"Crystal level and rank scaling")
|
|
var cloned: Resource = progress.duplicate(true)
|
|
check(cloned.time_crystals==progress.time_crystals,"Currency preserved")
|
|
var profile := {}
|
|
for seed_value in 100:
|
|
var candidate := preload("res://scripts/planets/planet_profiles.gd").generate(seed_value,0,"Test")
|
|
if SERVICE.has_engineer(candidate):
|
|
profile = candidate
|
|
break
|
|
check(not profile.is_empty(),"Engineer exists")
|
|
var surface := preload("res://scripts/planets/surface_generator.gd").generate(int(profile.seed),profile)
|
|
var engineers := 0
|
|
for poi in surface.pois:
|
|
if poi.kind=="time_engineer": engineers += 1
|
|
check(engineers==1 and SERVICE.has_engineer(profile),"Engineer POI generated")
|
|
# Exercise the real landing screen and the actual item/addon selectors.
|
|
game.set_physics_process(false)
|
|
for enemy in get_tree().get_nodes_in_group("enemies"): enemy.queue_free()
|
|
await frames()
|
|
var controller := game.get_node("PlanetExpeditions")
|
|
controller._leave()
|
|
player.position = game.protected_planet.position
|
|
progress.lander_hp = 100
|
|
progress.scan(game.protected_planet.planet_profile)
|
|
var weapon: ItemInstance
|
|
for attempt in 100:
|
|
weapon = ITEM_GENERATOR.generate_for_definition(preload("res://resources/items/plasma_cannon.tres"),20,2)
|
|
var bounds := weapon.additional_modifiers[1].affix.get_value_range(20)
|
|
if bounds.y > bounds.x + 0.000001: break
|
|
for modifier in weapon.additional_modifiers: modifier.value = modifier.affix.get_value_range(20).x
|
|
inventory.weapon_slots[0] = weapon
|
|
progress.time_crystals = 400
|
|
controller.land_nearby()
|
|
await frames()
|
|
var screen: Control = controller.screen
|
|
check(is_instance_valid(screen),"Actual surface screen opened")
|
|
screen._poi = {"kind":"time_engineer","position":screen.lander.position}
|
|
screen._engineer_item = weapon
|
|
screen._engineer_addon = 0
|
|
screen._show_poi()
|
|
var addon_choice: OptionButton = screen.find_child("EngineerAddon",true,false)
|
|
addon_choice.item_selected.emit(1)
|
|
var chosen_index: int = screen._engineer_addon
|
|
check(chosen_index==1,"Addon selector targets requested addon")
|
|
var before_first: float = weapon.additional_modifiers[0].value
|
|
screen.find_child("MaximizeSelectedAddon",true,false).pressed.emit()
|
|
check(progress.time_crystals==200,"UI service charged once")
|
|
check(weapon.additional_modifiers[0].value==before_first and is_equal_approx(weapon.additional_modifiers[1].value,SERVICE.maximum(weapon,1)),"UI maximizes only chosen addon")
|
|
check(screen.find_child("MaximizeSelectedAddon",true,false).disabled,"UI blocks already-max addon")
|
|
print("TIME_CRYSTALS_CHECKS: "+JSON.stringify({"failures":failures,"passed":failures.is_empty()}))
|