Files
windroost/p2_godot_sample/scripts/prestige_test.gd
T
wushenghua 9ed728aa1d feat: L2 two-tier prestige engine — rebuild + new sky (FULL_GAME_GOAL)
Continued FULL_GAME_GOAL. Implemented the complete game-cycle prestige layer
from FINAL_GAME_DESIGN 8.1/8.2:
- prestige.py (authoritative) + prestige.gd (runtime mirror): rebuild formula
  floor((node/10)^0.85)+chapters*2+region-boss, new-sky formula
  floor(5*log10(essence+1))+regions*2+final-boss; design reset/retain rules for
  both tiers. Previews + apply functions.
- check_prestige_parity.py: 3 cases (incl. full 600-node/60-chapter scale),
  python==gd on all preview/apply fields.
- GameRoot apply hooks + persistence; prestige_test verifies essence/marks gain,
  gold/levels reset, stars/relics/edicts retained, oaths reset at new sky,
  counters increment, and reload normalization (gold 0, empty levels).

Test caught a real bug: edicts were dropped at rebuild though design retains
them until new sky — fixed in both engines. Live slice rebuild flow untouched
(uses its smaller formula); full-game prestige is available as API for the
600-node build + verified now.

2 new gates; full P2_CHECKS_PASS. prototype/ untracked.
2026-11-18 13:50:47 +08:00

106 lines
4.2 KiB
GDScript

extends SceneTree
## L2 two-tier prestige evidence through the real GameRoot profile path.
const OUTPUT_PATH := "res://artifacts/prestige_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _check(cond: bool, msg: String) -> void:
if not cond:
_problems.append(msg)
func _record(name: String, data: Dictionary) -> void:
var e := data.duplicate()
e["step"] = name
_steps.append(e)
func _run() -> void:
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
root.add_child(shell)
await process_frame
await process_frame
shell.reset_profile_for_test()
var gp := shell.get_profile()
# full-game progress snapshot
gp["highest_node"] = 300
gp["completed_chapters"] = 30
gp["region_boss_first_clears"] = 5
gp["total_essence_earned"] = 120
gp["completed_regions"] = 3
gp["final_boss_first_clears"] = 1
gp["gold"] = 9999
gp["star_levels"] = {"H01": 5}
gp["relics"] = {"L01": true}
gp["oaths"] = {"O01": true}
gp["edicts"] = {"D01": true}
gp["essence"] = 40
gp["sky_marks"] = 7
ProfileStore.save_profile(gp)
shell.refresh_pages_for_test()
# preview must match the design formula (mirrors prestige.py, parity tested)
var pv := shell.prestige_preview_for_test()
var reb: Dictionary = pv["rebuild"]
var sky: Dictionary = pv["new_sky"]
_check(int(reb.get("essence", 0)) > 0, "rebuild should preview positive essence")
_check(int(sky.get("sky_marks", 0)) > 0, "new sky should preview positive marks")
_record("preview", {"rebuild": reb, "new_sky": sky})
# apply rebuild: essence rises, gold reset, stars/relics/oaths retained
var before_essence := int(shell.get_profile().get("essence", 0))
var after := shell.apply_full_rebuild_for_test()
_check(int(after.get("essence", 0)) > before_essence, "rebuild must grant essence")
_check(int(after.get("gold", 0)) == 0, "rebuild must reset gold")
_check((after.get("star_levels", {}) as Dictionary).has("H01"), "rebuild must retain stars")
_check((after.get("relics", {}) as Dictionary).has("L01"), "rebuild must retain relics")
_check((after.get("oaths", {}) as Dictionary).has("O01"), "rebuild must retain oaths")
_check(int(after.get("rebuild_count", 0)) == 1, "rebuild_count must increment")
var reloaded := ProfileStore.load_profile()
_check(int(reloaded.get("essence", 0)) == int(after["essence"]), "rebuild must persist")
_check(int(reloaded.get("gold", 0)) == 0, "reload must normalize reset gold to 0")
_check((reloaded.get("hero_levels", {}) as Dictionary).is_empty(), "reload must normalize reset levels")
_record("rebuild", {"essence": after.get("essence"), "gold": after.get("gold"), "count": after.get("rebuild_count")})
# apply new sky: sky_marks rise, essence/oaths reset, edicts/stars/relics retained
var before_marks := int(shell.get_profile().get("sky_marks", 0))
var after2 := shell.apply_new_sky_for_test()
_check(int(after2.get("sky_marks", 0)) > before_marks, "new sky must grant marks")
_check(int(after2.get("essence", 0)) == 0, "new sky must reset essence")
_check((after2.get("oaths", {}) as Dictionary).is_empty(), "new sky must reset oaths")
_check((after2.get("edicts", {}) as Dictionary).has("D01"), "new sky must retain edicts")
_check((after2.get("star_levels", {}) as Dictionary).has("H01"), "new sky must retain stars")
_check((after2.get("relics", {}) as Dictionary).has("L01"), "new sky must retain relics")
_check(int(after2.get("new_sky_count", 0)) == 1, "new_sky_count must increment")
_record("new_sky", {"marks": after2.get("sky_marks"), "essence": after2.get("essence"), "count": after2.get("new_sky_count")})
root.remove_child(shell)
shell.free()
_finish()
func _finish() -> void:
var passed := _problems.is_empty()
var report := {"schema": 1, "kind": "windroost_prestige_test",
"overall": "PASS" if passed else "FAIL", "problems": _problems, "steps": _steps}
var dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(dir)
var f := FileAccess.open(dir.path_join("prestige_test.json"), FileAccess.WRITE)
if f != null:
f.store_string(JSON.stringify(report, "\t", true)); f.close()
for e in _steps:
print("PRESTIGE_STEP %s" % JSON.stringify(e))
if passed:
print("PRESTIGE_PASS")
else:
print("PRESTIGE_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)