Randoloot/tests/levels/wreck_rewards_test.gd
2026-10-17 18:58:40 +02:00

56 lines
2.4 KiB
GDScript

extends Node2D
const POI = preload("res://scripts/levels/exploration_poi.gd")
func _ready() -> void:
var weights := {"minerals": 0, "ammunition": 0, "missile": 0, "module": 0}
for roll in 100:
weights[POI.wreck_reward_from_roll(roll)] += 1
assert(weights == {"minerals": 65, "ammunition": 10, "missile": 10, "module": 15})
GameState.start_new_run()
GameState.system_level = 1
var ship := preload("res://scenes/game/player_ship.tscn").instantiate()
add_child(ship)
ship.set_physics_process(false)
ship.get_node("WeaponController").set_physics_process(false)
ship.get_node("ExtensionSystems").set_physics_process(false)
var inv: ShipInventory = ship.get_node("ShipInventory")
var counts := {"minerals": 0, "ammunition": 0, "missile": 0, "module": 0}
for reward_seed in range(1, 251):
var poi := StaticBody2D.new()
poi.set_script(POI)
poi.kind = "wreck"
poi.player = ship
poi.reward_seed = reward_seed
poi.poi_id = "wreck-rewards:%d" % reward_seed
add_child(poi)
poi.set_physics_process(false)
var state: int = poi._rng.state
var reward: String = POI.wreck_reward_from_roll(poi._rng.randi_range(0, 99))
poi._rng.state = state
counts[reward] += 1
var minerals_before: Dictionary = GameState.captain.minerals.duplicate()
var ammo_before := inv.ammunition
var rockets_before := inv.missile_ammunition
var mineral: String = poi._mineral
assert(poi.claim())
assert(not poi.claim(), "A wreck can be claimed only once")
assert(GameState.captain.parts == 0.0)
if reward == "minerals":
var delta: int = GameState.captain.minerals[mineral] - minerals_before[mineral]
assert(delta >= 3 and delta <= 8)
for key in minerals_before:
if key != mineral:
assert(GameState.captain.minerals[key] == minerals_before[key])
else:
assert(GameState.captain.minerals == minerals_before)
if reward == "ammunition":
assert(inv.ammunition - ammo_before >= 40 and inv.ammunition - ammo_before <= 60)
else:
assert(inv.ammunition == ammo_before)
assert(inv.missile_ammunition - rockets_before == (1 if reward == "missile" else 0))
await get_tree().process_frame
assert(get_tree().get_nodes_in_group("loot").size() == counts.module, "Every module reward must physically drop one item")
assert(counts.minerals > counts.ammunition + counts.missile)
print("WRECK_REWARDS_TEST: PASS exact 65/10/10/15 weights, 250 actual wrecks, mineral/ammo amounts, single exclusive rewards, physical modules and no duplicate claims")
get_tree().quit()