Files
Diabolo/Demon_v0.19/economy_tests.gd
T

110 lines
8.1 KiB
GDScript
Raw Normal View History

extends RefCounted
const E=preload("res://economy.gd")
var checks=0
func check(ok,message):
checks+=1
if not ok:
push_error("ECONOMY QA #%d: %s"%[checks,message]);Engine.get_main_loop().quit(1)
func run(g):
await g.get_tree().process_frame
g.start_game();g.set_process(false)
var w=g.workshop;var dev=g.development
check(g.coins==240 and g.essence==0 and dev.xp==0,"new game wallets")
w.upgrade("hire");check(w.helpers.is_empty(),"gold cannot hire a helper")
g.essence=6;var gold=g.coins;w.upgrade("hire")
check(w.helpers.size()==1 and g.essence==0 and g.coins==gold,"hire uses souls exclusively")
g.essence=4;w.upgrade("auto");check(w.automation and g.essence==0,"autonomous work uses souls")
g.essence=13;w.upgrade("haste");w.upgrade("diligence")
check(w.helper_speed==1 and w.helper_diligence==1 and g.essence==0 and g.coins==gold,"helper skills use souls")
g.essence=100;g.coins=0;w.upgrade("tool0")
check(g.coins==0 and g.essence==100,"removed tool upgrades cannot spend souls")
g.coins=240;w.upgrade("tool0");check(g.coins==240,"removed tool upgrades cannot spend gold")
check(w.node_buttons.all(func(n):return not n.key.begins_with("tool")),"no tool upgrade nodes in grimoire")
check(w.context.find_children("*","Button",true,false).size()==0,"selected tool menu has no action buttons")
check(w.buy_labels.all(func(l):return not "ранг" in l.text),"purchase catalogue has no equipment ranks")
w.upgrade("unlock1");check(w.unlock==1 and g.coins==185,"new apparatus purchases remain available")
var d=w.add_station(0,Vector3(0,0,0));var d2=w.add_station(0,Vector3(3,0,0))
check(is_equal_approx(w.action_rate(d),1.0) and is_equal_approx(w.action_rate(d2),1.0),"tools have fixed base speed")
var points=dev.points;w.upgrade("power")
check(dev.action_level==0 and dev.points==points,"money cannot buy heroine level skills")
dev.reward(89);check(dev.points==0 and E.level(dev.xp)==1,"before first level threshold")
dev.reward(1);check(E.level(dev.xp)==2 and dev.points==1 and dev.xp_bar.value==0,"level grants one point and resets fill")
gold=g.coins;var souls=g.essence;w.upgrade("power")
check(dev.action_level==1 and dev.points==0 and g.coins==gold and g.essence==souls,"hero skill uses level point only")
check(is_equal_approx(w.action_rate(d),1.2/1.18),"manual work scales with heroine and difficulty")
d.operator=0
check(is_equal_approx(w.action_rate(d),1.25/1.18),"helper uses diligence instead of heroine power")
dev.reward(280);check(dev.points==2 and E.level(dev.xp)==4,"multiple level thresholds")
w.upgrade("leadership");check(is_equal_approx(w.action_rate(d),1.25*1.08/1.54),"leadership helps the team")
d.operator=-1
dev.reward(99999);check(dev.points==7 and E.level(dev.xp)==10 and dev.xp==2170,"bounded maximum level and total nine points")
dev.reward(100);check(dev.points==7 and dev.xp_bar.value==dev.xp_bar.max_value,"no repeated points at max level")
check(E.recipe_size(3,210,6)==1 and E.recipe_size(8,570,6)==1,"one apparatus per soul at every level")
for id in range(100):
check(E.recipe_size(id,2170,1)==1,"never require a missing tool")
check(E.recipe_size(id,2170,6)==1,"late game still requires exactly one apparatus")
check(E.reward([0],0)=={"gold":12,"souls":1,"xp":18},"base completion rewards")
check(E.reward([0,2],0)=={"gold":27,"souls":2,"xp":34},"multi-stage final rewards")
check(E.reward([0],0).gold==12,"fixed tool gold yield without ranks")
print("PASS: isolated currencies, level points, fixed tool stats, distinct worker skills, single-device assignments and level scaling")
g.reset_shift();g.start_game();g.set_process(false);w=g.workshop;dev=g.development
check(g.souls.is_empty(),"new shift starts without souls or apparatus")
w.update(30);g.spawn_soul()
check(g.souls.is_empty() and w.spawn_clock==0 and not w.spawn(),"empty workshop blocks every spawn path and holds the timer")
w.add_station(0,Vector3(0,0,0))
w.update(4.99);check(g.souls.is_empty(),"first apparatus starts a fresh five-second countdown")
w.update(.02);check(g.souls.size()==1,"first soul arrives five seconds after construction")
w.toggle_build();var clock=w.spawn_clock;w.update(20)
check(g.souls.size()==1 and is_equal_approx(clock,w.spawn_clock),"construction freezes arrivals")
w.toggle_build()
g.coins=100;g.essence=20;dev.xp=210;dev.points=2
dev.action_level=1
w.update_pressure(120,7)
check(g.coins==100 and g.essence==20,"old escalating overflow fees are replaced by per-soul losses")
check(dev.xp==210 and dev.points==2 and dev.action_level==1,"idle loss mechanics preserve experience and character skills")
print("PASS: queue UI does not double-charge the new fixed soul-loss penalties")
w.add_station(0,Vector3(0,0,0));w.add_helper();w.automation=true;w.helper_diligence=2;w.helper_speed=1
dev.leadership=1;g.coins=123;g.essence=45
var snap=g.progress_snapshot();snap.workshop["tool_ranks"]=[3,3,3,3,3,3];var path="user://qa_economy_v019.json"
check(g.Progression.write_save(path,snap)==OK,"save written")
var saved=g.Progression.read_save(path,g.build_id)
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
check(saved.coins==123 and saved.essence==45 and saved.development.leadership==1 and saved.development.xp==210,"wallet and heroine save round trip")
w.reset();w.restore(saved.workshop)
check(w.helpers.size()==1 and w.helper_diligence==2 and w.helper_speed==1 and w.automation,"assistant skills restored")
check(w.pressure_time==0 and w.stations.size()==1,"penalty pressure and layout restored")
check(not w.snapshot().has("tool_ranks"),"legacy tool ranks removed on save migration")
check(is_equal_approx(w.action_rate(w.stations[0]),1.2*1.08/1.36),"old saved upgrades give no hidden speed bonus")
g.reset_shift();check(g.essence==0 and g.coins==240 and dev.xp==0 and dev.leadership==0 and w.pressure_time==0,"new game reset")
print("PASS: save/load of wallets, levels, apparatus purchases, helper upgrades and pressure; new game reset")
g.game_started=true;g.paused=false;g.menu.show_page("")
var cash=g.coins
for physical_only in [false,true]:
for down in [true,false]:
var key=InputEventKey.new();key.keycode=0 if physical_only else KEY_F5;key.physical_keycode=KEY_F5;key.pressed=down
Input.parse_input_event(key)
await g.get_tree().process_frame
check(g.coins==cash+2000,"F5 adds exactly 1000 per key press")
check(g.essence==2000 and dev.xp==210 and E.level(dev.xp)==3,"two F5 presses add 2000 souls and exactly two levels")
check(dev.points==2,"one skill point granted per gained level")
w.upgrade("speed");w.upgrade("power")
check(dev.points==0,"learned skills consume earned points")
g.essence=12;cash=g.coins;dev.xp=250;dev.test_boost()
check(g.coins==cash+1000 and g.essence==1012 and dev.xp==370 and dev.points==1,"partial-level progress advances to next level; souls are added")
w.upgrade("leadership")
for i in range(10):dev.test_boost()
check(E.level(dev.xp)==10 and dev.points==6,"repeated boosts stop at maximum level without duplicate points")
var soul_cash=g.essence;cash=g.coins;dev.test_boost()
check(g.coins==cash+1000 and g.essence==soul_cash+1000 and dev.points==6,"at level cap both wallets still gain 1000 and points stay fixed")
var repeat=InputEventKey.new();repeat.keycode=KEY_F5;repeat.physical_keycode=KEY_F5;repeat.pressed=true;repeat.echo=true
cash=g.coins;Input.parse_input_event(repeat);await g.get_tree().process_frame
check(g.coins==cash,"holding F5 does not repeatedly grant gold")
snap=g.progress_snapshot();path="user://qa_f5_v019.json"
check(g.Progression.write_save(path,snap)==OK,"F5 bonus save written")
saved=g.Progression.read_save(path,g.build_id);DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
check(saved.essence==g.essence and saved.development.xp==E.XP_THRESHOLDS.back() and saved.development.points==6,"added souls, experience and remaining points survive save reload")
check(g.gold_value.text==str(g.coins) and g.souls_value.text==str(g.essence),"F5 refreshes both resource counters")
print("PASS: F5 +1000 gold, +1000 souls, +one level per press, level cap, no duplicate skill points, held-key protection and save round trip")
print("ALL ECONOMY TESTS PASSED — DEMON 0.19 (%d checks)"%checks)
g.get_tree().quit()