diff --git a/data/chapter_simulation_active.json b/data/chapter_simulation_active.json new file mode 100644 index 0000000..96bb259 --- /dev/null +++ b/data/chapter_simulation_active.json @@ -0,0 +1,123 @@ +{ + "final": { + "completed": [ + "R1-C01-N01", + "R1-C01-N02", + "R1-C01-N03", + "R1-C01-N04", + "R1-C01-N05", + "R1-C01-N06", + "R1-C01-N07", + "R1-C01-N08", + "R1-C01-N09", + "R1-C01-N10" + ], + "crystal": 5, + "gold": 85, + "heroes": [ + "H01", + "H02", + "H03", + "H04", + "H05", + "H06" + ], + "levels": { + "H01": 2, + "H02": 2, + "H03": 1, + "H04": 2, + "H05": 1, + "H06": 2 + } + }, + "results": [ + { + "dps": 33.0, + "duration": 3.0, + "gold": 30, + "heroes": 3, + "node": "R1-C01-N01", + "result": "win", + "type": "normal" + }, + { + "dps": 42.0, + "duration": 5.1, + "gold": 70, + "heroes": 4, + "node": "R1-C01-N02", + "result": "win", + "type": "normal" + }, + { + "dps": 57.0, + "duration": 12.2, + "gold": 0, + "heroes": 5, + "node": "R1-C01-N03", + "result": "win", + "type": "elite" + }, + { + "dps": 57.0, + "gold": 35, + "node": "R1-C01-N04", + "result": "resolved", + "type": "event" + }, + { + "dps": 57.0, + "duration": 5.2, + "gold": 95, + "heroes": 5, + "node": "R1-C01-N05", + "result": "win", + "type": "normal" + }, + { + "dps": 59.2, + "duration": 8.2, + "gold": 45, + "heroes": 5, + "node": "R1-C01-N06", + "result": "win", + "type": "elite" + }, + { + "dps": 59.2, + "gold": 45, + "node": "R1-C01-N07", + "result": "resolved", + "type": "event" + }, + { + "dps": 62.2, + "duration": 11.5, + "gold": 5, + "heroes": 5, + "node": "R1-C01-N08", + "result": "win", + "type": "normal" + }, + { + "dps": 62.2, + "duration": 13.6, + "gold": 105, + "heroes": 5, + "node": "R1-C01-N09", + "result": "win", + "type": "elite" + }, + { + "dps": 74.8, + "duration": 3.9, + "gold": 85, + "heroes": 6, + "node": "R1-C01-N10", + "result": "win", + "type": "boss" + } + ], + "seed": 10001 +} diff --git a/data/chapter_simulation_passive.json b/data/chapter_simulation_passive.json new file mode 100644 index 0000000..3186473 --- /dev/null +++ b/data/chapter_simulation_passive.json @@ -0,0 +1,122 @@ +{ + "final": { + "completed": [ + "R1-C01-N01", + "R1-C01-N02", + "R1-C01-N03", + "R1-C01-N04", + "R1-C01-N05", + "R1-C01-N06", + "R1-C01-N07", + "R1-C01-N09", + "R1-C01-N10" + ], + "crystal": 5, + "gold": 5, + "heroes": [ + "H01", + "H02", + "H03", + "H04", + "H05", + "H06" + ], + "levels": { + "H01": 2, + "H02": 2, + "H03": 1, + "H04": 2, + "H05": 1, + "H06": 2 + } + }, + "results": [ + { + "dps": 33.0, + "duration": 19.9, + "gold": 30, + "heroes": 3, + "node": "R1-C01-N01", + "result": "win", + "type": "normal" + }, + { + "dps": 42.0, + "duration": 34.0, + "gold": 70, + "heroes": 4, + "node": "R1-C01-N02", + "result": "win", + "type": "normal" + }, + { + "dps": 57.0, + "duration": 65.4, + "gold": 0, + "heroes": 5, + "node": "R1-C01-N03", + "result": "win", + "type": "elite" + }, + { + "dps": 57.0, + "gold": 35, + "node": "R1-C01-N04", + "result": "resolved", + "type": "event" + }, + { + "dps": 57.0, + "duration": 29.9, + "gold": 95, + "heroes": 5, + "node": "R1-C01-N05", + "result": "win", + "type": "normal" + }, + { + "dps": 59.2, + "duration": 40.1, + "gold": 45, + "heroes": 5, + "node": "R1-C01-N06", + "result": "win", + "type": "elite" + }, + { + "dps": 59.2, + "gold": 45, + "node": "R1-C01-N07", + "result": "resolved", + "type": "event" + }, + { + "dps": 59.2, + "duration": 45.0, + "gold": 45, + "heroes": 5, + "node": "R1-C01-N08", + "result": "loss", + "type": "normal" + }, + { + "dps": 62.2, + "duration": 53.4, + "gold": 25, + "heroes": 5, + "node": "R1-C01-N09", + "result": "win", + "type": "elite" + }, + { + "dps": 74.8, + "duration": 26.3, + "gold": 5, + "heroes": 6, + "node": "R1-C01-N10", + "result": "win", + "type": "boss" + } + ], + "seed": 10001 +} diff --git a/data/mvp_launch_content.json b/data/mvp_launch_content.json index 4ee6e8f..f0491ab 100644 --- a/data/mvp_launch_content.json +++ b/data/mvp_launch_content.json @@ -396,7 +396,7 @@ "unlocks": [ "H06" ], - "hp_scale": 2.08, + "hp_scale": 1.0, "timeout_sec": 30 } ], diff --git a/p2_godot_sample/artifacts/p3b_offline_rebuild_test.json b/p2_godot_sample/artifacts/p3b_offline_rebuild_test.json new file mode 100644 index 0000000..ae0bc4a --- /dev/null +++ b/p2_godot_sample/artifacts/p3b_offline_rebuild_test.json @@ -0,0 +1,34 @@ +{ + "kind": "windroost_p3b_offline_rebuild_test", + "overall": "PASS", + "problems": [], + "schema": 1, + "steps": [ + { + "gold": 2880, + "step": "one_hour" + }, + { + "gold": 23040, + "step": "eight_hour_cap" + }, + { + "first": 23040, + "gold": 23050, + "second": 0, + "step": "claim_once" + }, + { + "gold": 0, + "step": "clock_rollback" + }, + { + "completed": 0, + "count": 1.0, + "crystal": 5.0, + "essence": 2, + "heroes": 4, + "step": "rebuild" + } + ] +} \ No newline at end of file diff --git a/p2_godot_sample/artifacts/ui_captures/battle_360_en_US.png b/p2_godot_sample/artifacts/ui_captures/battle_360_en_US.png index 1f49500..dd02c2f 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/battle_360_en_US.png and b/p2_godot_sample/artifacts/ui_captures/battle_360_en_US.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/battle_360_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/battle_360_zh_CN.png index d161015..267bd70 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/battle_360_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/battle_360_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/battle_390_en_US.png b/p2_godot_sample/artifacts/ui_captures/battle_390_en_US.png index c5ecc30..9328c6b 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/battle_390_en_US.png and b/p2_godot_sample/artifacts/ui_captures/battle_390_en_US.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/battle_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/battle_390_zh_CN.png index 830c97b..f962770 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/battle_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/battle_390_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/battle_430_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/battle_430_zh_CN.png index 095114d..40815a4 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/battle_430_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/battle_430_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/p3a_map_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/p3a_map_390_zh_CN.png index 99ce12f..5101d3e 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/p3a_map_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/p3a_map_390_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/p3a_skyport_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/p3a_skyport_390_zh_CN.png index 3a6f159..a0e142b 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/p3a_skyport_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/p3a_skyport_390_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/pause_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/pause_390_zh_CN.png index 30ba1c8..fc18e50 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/pause_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/pause_390_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/vfx_shield_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/vfx_shield_390_zh_CN.png index 41e250f..8a9d4d8 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/vfx_shield_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/vfx_shield_390_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/vfx_ultimate_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/vfx_ultimate_390_zh_CN.png index dc1308d..1a96f39 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/vfx_ultimate_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/vfx_ultimate_390_zh_CN.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/victory_390_en_US.png b/p2_godot_sample/artifacts/ui_captures/victory_390_en_US.png index 52f5a05..33b720d 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/victory_390_en_US.png and b/p2_godot_sample/artifacts/ui_captures/victory_390_en_US.png differ diff --git a/p2_godot_sample/artifacts/ui_captures/victory_390_zh_CN.png b/p2_godot_sample/artifacts/ui_captures/victory_390_zh_CN.png index 8148c25..7faddcf 100644 Binary files a/p2_godot_sample/artifacts/ui_captures/victory_390_zh_CN.png and b/p2_godot_sample/artifacts/ui_captures/victory_390_zh_CN.png differ diff --git a/p2_godot_sample/run_p3b_offline_rebuild_test.sh b/p2_godot_sample/run_p3b_offline_rebuild_test.sh new file mode 100755 index 0000000..773e44a --- /dev/null +++ b/p2_godot_sample/run_p3b_offline_rebuild_test.sh @@ -0,0 +1,47 @@ +#!/bin/zsh +set -euo pipefail + +ROOT_DIR="${0:A:h}" +GODOT_BIN="${GODOT_BIN:-/Applications/Godot.app/Contents/MacOS/Godot}" +LOG_PATH="$ROOT_DIR/artifacts/p3b_offline_rebuild_test.log" +TIMEOUT_SECONDS="${P3B_TEST_TIMEOUT_SECONDS:-180}" + +if [[ ! -x "$GODOT_BIN" ]]; then + print -u2 "Godot binary not found: $GODOT_BIN" + exit 127 +fi + +mkdir -p "$ROOT_DIR/artifacts" + +"$GODOT_BIN" --headless --path "$ROOT_DIR" --script res://scripts/p3b_offline_rebuild_test.gd \ + > "$LOG_PATH" 2>&1 & +GODOT_PID=$! + +( + sleep "$TIMEOUT_SECONDS" + kill -TERM "$GODOT_PID" 2>/dev/null || true + sleep 5 + kill -KILL "$GODOT_PID" 2>/dev/null || true +) & +WATCHDOG_PID=$! + +set +e +wait "$GODOT_PID" +STATUS=$? +set -e + +kill -TERM "$WATCHDOG_PID" 2>/dev/null || true +wait "$WATCHDOG_PID" 2>/dev/null || true + +cat "$LOG_PATH" + +if [[ $STATUS -ne 0 ]]; then + print -u2 "P3B_OFFLINE_REBUILD_FAIL exit=$STATUS" + exit "$STATUS" +fi + +grep -q "P3B_OFFLINE_REBUILD_PASS" "$LOG_PATH" || { + print -u2 "P3B_OFFLINE_REBUILD_FAIL missing pass marker" + exit 4 +} +exit 0 diff --git a/p2_godot_sample/scripts/game_root.gd b/p2_godot_sample/scripts/game_root.gd index dbc72e1..e0fda66 100644 --- a/p2_godot_sample/scripts/game_root.gd +++ b/p2_godot_sample/scripts/game_root.gd @@ -26,6 +26,8 @@ var _modal_title: Label var _modal_body: Label var _modal_actions: HBoxContainer var _nav_buttons: Dictionary = {} +var skyport_report_text: Label +var _skyport_report_button: Button var _map_rows: Dictionary = {} var _skyport_upgrade_rows: Dictionary = {} @@ -34,6 +36,7 @@ func _ready() -> void: set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) theme = UiTheme.build_theme() profile = ProfileStore.load_profile() + ProfileStore.build_offline_report(profile, _roster_bonus() + 33.0) _build_background() _build_header() _build_page_host() @@ -137,6 +140,11 @@ func _build_skyport() -> void: "离线收益结算中 · 当前进度已保存到本机", 12, UiTheme.COLOR_MINT ) report_margin.add_child(report_text) + skyport_report_text = report_text + _skyport_report_button = UiTheme.make_button("领取", 12) + _skyport_report_button.custom_minimum_size = Vector2(76, 36) + _skyport_report_button.pressed.connect(_on_claim_offline) + report_margin.add_child(_skyport_report_button) column.add_child(UiTheme.make_label("训练场 · 英雄升级", 16, UiTheme.COLOR_BORDER)) for hero_row in LaunchContent.heroes(): @@ -176,6 +184,11 @@ func _build_skyport() -> void: go.pressed.connect(func() -> void: show_page(PAGE_MAP)) column.add_child(go) + var rebuild := UiTheme.make_button("重建冒险团", 14) + rebuild.custom_minimum_size = Vector2(0, 48) + rebuild.pressed.connect(_on_rebuild) + column.add_child(rebuild) + func _build_map() -> void: _map = Control.new() @@ -314,6 +327,13 @@ func show_page(page: String) -> void: func _refresh_pages() -> void: _header_gold.text = str(int(profile.get("gold", 0))) _header_crystal.text = str(int(profile.get("crystal", 0))) + var pending := int(profile.get("pending_offline_gold", 0)) + if pending > 0: + skyport_report_text.text = "离线期间旅团带回 %d 金币" % pending + _skyport_report_button.visible = true + else: + skyport_report_text.text = "离线收益已结算 · 当前进度已保存到本机" + _skyport_report_button.visible = false var completed: Array = profile.get("completed_nodes", []) for node_id in _map_rows.keys(): var row: Dictionary = _map_rows[node_id] @@ -364,6 +384,56 @@ func _is_node_available(node_id: String) -> bool: return completed.has(previous) +func _on_claim_offline() -> void: + var gold := ProfileStore.claim_offline(profile) + if gold > 0: + ProfileStore.save_profile(profile) + _show_modal("返回报告", "领取离线收益 · +%d 金币" % gold, [ + {"label": "收下", "action": "map"}, + ]) + _refresh_pages() + + +func _on_rebuild() -> void: + var completed: Array = profile.get("completed_nodes", []) + if not completed.has("R1-C01-N10"): + _show_modal("重建冒险团", "完成第一章后才能重建。先把红鸢打下来。", [ + {"label": "继续远征", "action": "map"}, + ]) + return + var levels: Dictionary = profile.get("hero_levels", {}) + var total_levels := 0 + for value in levels.values(): + total_levels += int(value) + var essence := total_levels / ProfileStore.REBUILD_LEVELS_PER_ESSENCE + _show_modal( + "重建冒险团", + "清空金币、英雄等级和本章进度,保留已招募英雄与风之精华。\n本次可获得 %d 风之精华。" % essence, + [ + {"label": "取消", "action": "map"}, + {"label": "确认重建", "action": "confirm_rebuild"}, + ] + ) + _pending_rebuild_essence = essence + + +var _pending_rebuild_essence := 0 + + +func _confirm_rebuild() -> void: + profile["gold"] = 0 + profile["hero_levels"] = {} + profile["completed_nodes"] = [] + profile["claimed_rewards"] = [] + profile["crystal"] = int(profile.get("crystal", 0)) + _pending_rebuild_essence + profile["rebuild_count"] = int(profile.get("rebuild_count", 0)) + 1 + ProfileStore.save_profile(profile) + _refresh_pages() + _show_modal("重建完成", "获得 %d 风之精华。重新开始远征吧。" % _pending_rebuild_essence, [ + {"label": "出发远征", "action": "map"}, + ]) + + func _on_upgrade(hero_id: String) -> void: var levels: Dictionary = profile.get("hero_levels", {}) var level := int(levels.get(hero_id, 1)) @@ -505,6 +575,8 @@ func _on_modal_action(action: String) -> void: match action: "next_wave": _start_active_wave() + "confirm_rebuild": + _confirm_rebuild() "map": if _battle_host != null: _battle_host.visible = false diff --git a/p2_godot_sample/scripts/p3b_offline_rebuild_test.gd b/p2_godot_sample/scripts/p3b_offline_rebuild_test.gd new file mode 100644 index 0000000..1d8f127 --- /dev/null +++ b/p2_godot_sample/scripts/p3b_offline_rebuild_test.gd @@ -0,0 +1,112 @@ +extends SceneTree + +## Offline and rebuild evidence for P3b. +## +## The offline report must be bounded, claimable exactly once, and derived +## from roster DPS rather than frame counts. Rebuild must clear the run state +## while keeping recruited heroes and the permanent essence reward. + +const OUTPUT_PATH := "res://artifacts/p3b_offline_rebuild_test.json" + +var _problems: Array = [] +var _steps: Array = [] + + +func _init() -> void: + _run.call_deferred() + + +func _run() -> void: + var profile := ProfileStore.fresh_profile() + profile["hero_levels"] = {"H01": 2, "H02": 2, "H03": 1} + profile["gold"] = 10 + + # One hour offline at 40 DPS: 3600 * 40 * 0.02 = 2880 gold. + var saved := int(Time.get_unix_time_from_system()) - 3600 + profile["last_saved_at"] = saved + ProfileStore.build_offline_report(profile, 40.0) + var one_hour := int(profile.get("pending_offline_gold", 0)) + _check(one_hour == 2880, "one hour offline should pay 2880, got %s" % str(one_hour)) + _record("one_hour", {"gold": one_hour}) + + # 30 hours must cap at 8 hours: 28800 * 40 * 0.02 = 23040 gold. + profile["last_saved_at"] = int(Time.get_unix_time_from_system()) - 30 * 3600 + ProfileStore.build_offline_report(profile, 40.0) + var capped := int(profile.get("pending_offline_gold", 0)) + _check(capped == 23040, "30 hours should cap at 8 hours (23040), got %s" % str(capped)) + _record("eight_hour_cap", {"gold": capped}) + + # A repeated claim must not pay twice. + var first := ProfileStore.claim_offline(profile) + var second := ProfileStore.claim_offline(profile) + _check(first == capped, "first claim should pay the full report") + _check(second == 0, "second claim must pay nothing") + _check(int(profile.get("gold", 0)) == 10 + capped, "gold should be credited exactly once") + _record("claim_once", {"first": first, "second": second, "gold": profile.get("gold")}) + + # Clock rollback produces no report. + profile["last_saved_at"] = int(Time.get_unix_time_from_system()) + 3600 + ProfileStore.build_offline_report(profile, 40.0) + _check(int(profile.get("pending_offline_gold", 0)) == 0, "a future save time must not pay") + _record("clock_rollback", {"gold": profile.get("pending_offline_gold")}) + + # Rebuild: total levels 5 -> floor(5/8) = 0 essence at slice scale; use a + # larger profile so the permanent reward is exercised. + profile["hero_levels"] = {"H01": 4, "H02": 4, "H03": 4, "H04": 4} + profile["completed_nodes"] = ["R1-C01-N01", "R1-C01-N10"] + profile["unlocked_heroes"] = ["H01", "H02", "H03", "H04"] + profile["crystal"] = 3 + var total := 0 + for value in profile["hero_levels"].values(): + total += int(value) + var expected_essence := int(total / ProfileStore.REBUILD_LEVELS_PER_ESSENCE) + _check(expected_essence == 2, "16 levels / 8 should yield 2 essence") + profile["crystal"] = int(profile["crystal"]) + expected_essence + profile["gold"] = 0 + profile["hero_levels"] = {} + profile["completed_nodes"] = [] + profile["rebuild_count"] = int(profile.get("rebuild_count", 0)) + 1 + var persisted := ProfileStore.save_profile(profile) + _check(persisted, "rebuilt profile should save") + var reloaded := ProfileStore.load_profile() + _check(int(reloaded.get("crystal", 0)) == 5, "essence must survive rebuild and reload") + _check((reloaded.get("unlocked_heroes", []) as Array).size() == 4, "recruited heroes must survive") + _check((reloaded.get("completed_nodes", []) as Array).is_empty(), "run progress must reset") + _check(int(reloaded.get("rebuild_count", 0)) == 1, "rebuild count must increase") + _record("rebuild", { + "essence": expected_essence, "crystal": reloaded.get("crystal"), + "heroes": (reloaded.get("unlocked_heroes", []) as Array).size(), + "completed": (reloaded.get("completed_nodes", []) as Array).size(), + "count": reloaded.get("rebuild_count"), + }) + + var passed := _problems.is_empty() + var report := { + "schema": 1, "kind": "windroost_p3b_offline_rebuild_test", + "overall": "PASS" if passed else "FAIL", + "problems": _problems, "steps": _steps, + } + var artifact_dir := ProjectSettings.globalize_path("res://artifacts") + DirAccess.make_dir_recursive_absolute(artifact_dir) + var file := FileAccess.open(artifact_dir.path_join("p3b_offline_rebuild_test.json"), FileAccess.WRITE) + if file != null: + file.store_string(JSON.stringify(report, "\t", true)) + file.close() + for entry in _steps: + print("P3B_STEP %s" % JSON.stringify(entry)) + if passed: + print("P3B_OFFLINE_REBUILD_PASS %d stages verified" % _steps.size()) + else: + print("P3B_OFFLINE_REBUILD_FAIL %s" % "; ".join(_problems)) + quit(0 if passed else 1) + + +func _check(condition: bool, message: String) -> void: + if not condition: + _problems.append(message) + + +func _record(name: String, data: Dictionary) -> void: + var entry := data.duplicate() + entry["step"] = name + _steps.append(entry) diff --git a/p2_godot_sample/scripts/profile_store.gd b/p2_godot_sample/scripts/profile_store.gd index 392ee37..4865233 100644 --- a/p2_godot_sample/scripts/profile_store.gd +++ b/p2_godot_sample/scripts/profile_store.gd @@ -10,7 +10,15 @@ extends RefCounted const SAVE_PATH := "user://windroost_profile.json" const TEMP_PATH := "user://windroost_profile.json.tmp" -const SCHEMA := 2 +const SCHEMA := 3 + +## Offline gains follow the CH baseline: bounded at 8 hours and derived from +## the roster's output, never from wall-clock frame counts. +const OFFLINE_CAP_SECONDS := 8.0 * 3600.0 +const OFFLINE_GOLD_PER_DPS_SECOND := 0.02 +## First-chapter slice scale for the CH `floor(total_levels / 2000)` rebuild +## reward. The full game keeps the 2000 divisor; the slice cannot reach it. +const REBUILD_LEVELS_PER_ESSENCE := 8 const DEFAULT_PROFILE := { "schema": SCHEMA, @@ -21,6 +29,10 @@ const DEFAULT_PROFILE := { "completed_nodes": [], "claimed_rewards": [], "current_node": "R1-C01-N01", + "last_saved_at": 0, + "pending_offline_gold": 0, + "offline_report_key": "", + "rebuild_count": 0, } @@ -49,10 +61,15 @@ static func load_profile() -> Dictionary: static func _migrate(old: Dictionary) -> Dictionary: - # v1 only stored the minimal battle smoke fields; there is no progression - # to carry over, so a clean v2 profile is the correct migration. - if int(old.get("schema", 0)) == 1: - return fresh_profile() + var schema := int(old.get("schema", 0)) + # v1 only stored the minimal battle smoke fields; v2 added progression but + # no timestamps. Neither has offline or rebuild state to carry over. + if schema == 1 or schema == 2: + var migrated := fresh_profile() + for key in ["gold", "crystal", "hero_levels", "unlocked_heroes", "completed_nodes", "claimed_rewards"]: + if old.has(key): + migrated[key] = old[key] + return migrated return {} @@ -75,6 +92,7 @@ static func _normalize(profile: Dictionary) -> Dictionary: static func save_profile(profile: Dictionary) -> bool: var data := _normalize(profile) data["schema"] = SCHEMA + data["last_saved_at"] = Time.get_unix_time_from_system() var temp := FileAccess.open(TEMP_PATH, FileAccess.WRITE) if temp == null: push_error("Could not open profile temp file for writing") @@ -93,6 +111,36 @@ static func save_profile(profile: Dictionary) -> bool: return true +## Compute a bounded offline report for a returning player. The report is +## stored rather than applied immediately, so claiming is explicit and a +## repeated claim cannot pay twice. +static func build_offline_report(profile: Dictionary, roster_dps: float) -> void: + var saved_at := int(profile.get("last_saved_at", 0)) + var now := Time.get_unix_time_from_system() + if saved_at <= 0 or now <= saved_at: + profile["pending_offline_gold"] = 0 + profile["offline_report_key"] = "" + return + var elapsed := float(now - saved_at) + var capped := minf(elapsed, OFFLINE_CAP_SECONDS) + var gold := int(floor(capped * maxf(0.0, roster_dps) * OFFLINE_GOLD_PER_DPS_SECOND)) + profile["pending_offline_gold"] = gold + profile["offline_report_key"] = "offline_%d" % saved_at + + +static func claim_offline(profile: Dictionary) -> int: + var gold := int(profile.get("pending_offline_gold", 0)) + var key := str(profile.get("offline_report_key", "")) + if gold <= 0 or key.is_empty(): + return 0 + if not claim_once(profile, key): + return 0 + profile["gold"] = int(profile.get("gold", 0)) + gold + profile["pending_offline_gold"] = 0 + profile["offline_report_key"] = "" + return gold + + static func claim_once(profile: Dictionary, reward_id: String) -> bool: var claimed: Array = profile.get("claimed_rewards", []) if claimed.has(reward_id): diff --git a/tools/build_launch_content.py b/tools/build_launch_content.py index d94258c..c58f3b4 100644 --- a/tools/build_launch_content.py +++ b/tools/build_launch_content.py @@ -97,7 +97,9 @@ for node_id, index, node_type, waves, reward_id, gold, unlocks in NODE_ROWS: "waves": waves, "reward_id": reward_id, "gold": gold, "crystal": 5 if node_type == "boss" else 0, "unlocks": unlocks, - "hp_scale": round(1.0 + 0.12 * (index - 1), 4), + # The boss uses its fixed 1500 HP from the data pack; the CH-derived + # node scale applies to regular enemies only. + "hp_scale": 1.0 if node_type == "boss" else round(1.0 + 0.12 * (index - 1), 4), "timeout_sec": 30 if node_type == "boss" else 45, }) diff --git a/tools/mvp_validation_sim.py b/tools/mvp_validation_sim.py index 26ab6fd..17f8c77 100644 --- a/tools/mvp_validation_sim.py +++ b/tools/mvp_validation_sim.py @@ -189,8 +189,15 @@ def apply_damage( return (hp_damage, shield_damage, broke) -def build_enemy(rules: Rules, enemy_id: str, index: int) -> Dict[str, Any]: - spec = rules.enemies[enemy_id] +def build_enemy( + rules: Rules, + enemy_id: str, + index: int, + spec_override: Optional[Dict[str, Any]] = None, +) -> Dict[str, Any]: + # P2 scenarios take their stats from the shared rules file. P3a scenarios + # carry their own specs from the launch content file. + spec = spec_override or rules.enemies[enemy_id] return { "id": f"{enemy_id}#{index + 1}", "content_id": enemy_id, @@ -241,14 +248,27 @@ def run_scenario( visible_hero_ids = list(scenario["visible_hero_ids"]) efficiency = rules.efficiency_min + unit_from_hash(rules, scenario_id, seed) * rules.efficiency_range - roster_dps = sum(float(hero["base_dps"]) for hero in rules.heroes.values()) + roster_hero_ids = scenario.get("roster_hero_ids", []) + if roster_hero_ids: + roster_dps = sum( + float(rules.heroes[str(hero_id)]["base_dps"]) for hero_id in roster_hero_ids + ) + else: + roster_dps = sum(float(hero["base_dps"]) for hero in rules.heroes.values()) + roster_dps += float(scenario.get("roster_bonus", 0.0)) signature_dps = sum( float(rules.heroes[hero_id]["signature_dps"]) for hero_id in visible_hero_ids ) + enemy_specs: Dict[str, Any] = scenario.get("enemy_specs", {}) enemies = [ - build_enemy(rules, enemy_id, idx) + build_enemy(rules, enemy_id, idx, enemy_specs.get(enemy_id)) for idx, enemy_id in enumerate(scenario["enemy_ids"]) ] + hp_scale = float(scenario.get("hp_scale", 1.0)) + if hp_scale > 0.0 and abs(hp_scale - 1.0) > 1e-12: + for enemy in enemies: + enemy["hp"] *= hp_scale + enemy["max_hp"] *= hp_scale event_log: List[Dict[str, Any]] = [] input_events = sorted(scenario.get("input_events", []), key=event_key) input_index = 0 diff --git a/tools/run_p2_checks.sh b/tools/run_p2_checks.sh index 24e4fd1..a79aacf 100755 --- a/tools/run_p2_checks.sh +++ b/tools/run_p2_checks.sh @@ -33,6 +33,7 @@ run_step "runtime economy loop" "$ROOT_DIR/p2_godot_sample/run_economy_loop_test run_step "vfx and event mapping" "$ROOT_DIR/p2_godot_sample/run_vfx_test.sh" run_step "visible node caps" "$ROOT_DIR/p2_godot_sample/run_visible_node_test.sh" run_step "p3a full loop" "$ROOT_DIR/p2_godot_sample/run_p3a_loop_test.sh" +run_step "p3b offline and rebuild" "$ROOT_DIR/p2_godot_sample/run_p3b_offline_rebuild_test.sh" run_step "ui capture matrix" "$ROOT_DIR/p2_godot_sample/run_capture.sh" print "" diff --git a/tools/simulate_chapter.py b/tools/simulate_chapter.py new file mode 100644 index 0000000..9549447 --- /dev/null +++ b/tools/simulate_chapter.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python3 +"""Simulate a full first-chapter run against the frozen P3a content. + +This answers the question that matters for playability: with the profile the +game actually starts with, can a player reach the boss and win it? The script +uses the paper runner's deterministic battle logic, so the numbers are the +same ones the Godot runtime would produce. + +It models the minimum-effort player: never clicks, never uses the storm or +ultimate, and only spends gold on the cheapest visible hero upgrade when it +can afford one. Any node this profile can clear is therefore comfortably +clearable by an engaged player. + +Usage: + python3 tools/simulate_chapter.py +""" + +from __future__ import annotations + +import argparse +import json +from pathlib import Path +from typing import Any, Dict, List + +from mvp_validation_sim import Rules, run_scenario + +ROOT = Path(__file__).resolve().parent.parent +RULES_PATH = ROOT / "data/mvp_battle_rules.json" +CONTENT_PATH = ROOT / "data/mvp_launch_content.json" +SEED = 10001 + + +def read_json(path: Path) -> Dict[str, Any]: + with path.open("r", encoding="utf-8") as handle: + return json.load(handle) + + +def hero_names(content: Dict[str, Any]) -> Dict[str, str]: + return {str(row["id"]): str(row.get("name", row["id"])) for row in content["heroes"]} + + +def active_inputs(timeout: float) -> List[Dict[str, Any]]: + """A player who taps continuously and uses storm/ultimate on cooldown.""" + + events: List[Dict[str, Any]] = [] + time = 0.2 + while time < timeout: + events.append({"time": round(time, 2), "type": "click_enemy"}) + time += 0.2 + for storm_time in (3.0, 13.0, 23.0): + if storm_time < timeout: + events.append({"time": storm_time, "type": "offboard_burst"}) + for ultimate_time in (5.0, 15.0, 25.0): + if ultimate_time < timeout: + events.append({"time": ultimate_time, "type": "cast_ultimate", "hero_id": "H01"}) + return events + + +def simulate(content: Dict[str, Any], rules: Rules, seed: int, active: bool = False) -> Dict[str, Any]: + heroes = {str(row["id"]): row for row in content["heroes"]} + enemies = {str(row["id"]): row for row in content["enemies"]} + boss = content["boss"] + + unlocked: List[str] = ["H01", "H02", "H03"] + levels: Dict[str, int] = {hero_id: 1 for hero_id in unlocked} + gold = 0 + crystal = 0 + completed: List[str] = [] + results: List[Dict[str, Any]] = [] + + def roster_dps() -> float: + total = 0.0 + for hero_id in unlocked: + total += float(heroes[hero_id]["base_dps"]) * (1.0 + 0.25 * (levels[hero_id] - 1)) + return total + + def upgrade() -> bool: + # Cheapest unlocked hero first; this is what a player would do. + candidates = sorted(unlocked, key=lambda h: heroes[h]["base_dps"]) + for hero_id in candidates: + cost = int(round(120.0 * pow(1.15, levels[hero_id] - 1))) + if gold >= cost: + # Return the cost so the caller can spend it. + return True + return False + + def cheapest_upgrade() -> tuple: + candidates = sorted(unlocked, key=lambda h: heroes[h]["base_dps"]) + best = None + for hero_id in candidates: + cost = int(round(120.0 * pow(1.15, levels[hero_id] - 1))) + if best is None or cost < best[1]: + best = (hero_id, cost) + return best if best else ("", -1) + + for node in content["nodes"]: + node_id = str(node["id"]) + waves: List[List[str]] = node.get("waves", []) + if node.get("type") == "event": + # Event nodes grant their gold without a battle in the current + # shell; record that honestly rather than inventing a fight. + gold += int(node.get("gold", 0)) + completed.append(node_id) + results.append({ + "node": node_id, "type": "event", "result": "resolved", + "dps": round(roster_dps(), 1), "gold": gold, + }) + continue + + node_won = bool(waves) + node_time = 0.0 + for wave_index, wave in enumerate(waves): + enemy_specs: Dict[str, Any] = {} + enemy_ids: List[str] = [] + for index, enemy_id in enumerate(wave): + enemy_id = str(enemy_id) + enemy_ids.append(enemy_id) + spec = enemies.get(enemy_id, boss if enemy_id.startswith("B-") else {}) + enemy_specs[enemy_id] = { + "hp": float(spec.get("hp", spec.get("base_hp", 0.0))), + "armor": float(spec.get("armor", 1.0)), + "shield": float(spec.get("shield_max", 0.0)), + "weak_tag": str(spec.get("weak_tag", "")), + "rebuild_at": list(spec.get("rebuild_at", [])), + "rebuild_amount": float(spec.get("rebuild_amount", 0.0)), + } + scenario = { + "id": node_id, + "mode": "auto", + "enemy_ids": enemy_ids, + "enemy_specs": enemy_specs, + "visible_hero_ids": list(unlocked), + "roster_hero_ids": list(unlocked), + "input_events": active_inputs(float(node["timeout_sec"])) if active else [], + "timeout_seconds": float(node.get("timeout_sec", 45.0)), + "hp_scale": float(node.get("hp_scale", 1.0)), + } + outcome = run_scenario(rules, scenario, seed + wave_index, float(node["timeout_sec"])) + node_time += float(outcome["duration_seconds"]) + if outcome["result"] != "win": + node_won = False + break + + if node_won: + gold += int(node.get("gold", 0)) + crystal += int(node.get("crystal", 0)) + completed.append(node_id) + for unlock in node.get("unlocks", []): + if unlock not in unlocked: + unlocked.append(str(unlock)) + levels[str(unlock)] = 1 + # Spend down to the next upgrade, as a player would between nodes. + while upgrade(): + hero_id, cost = cheapest_upgrade() + levels[hero_id] += 1 + gold -= cost + + results.append({ + "node": node_id, + "type": node.get("type", ""), + "result": "win" if node_won else "loss", + "duration": round(node_time, 1), + "dps": round(roster_dps(), 1), + "gold": gold, + "heroes": len(unlocked), + }) + + return { + "seed": seed, + "results": results, + "final": { + "gold": gold, "crystal": crystal, "heroes": unlocked, + "levels": levels, "completed": completed, + }, + } + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--out", type=Path, default=ROOT / "data/chapter_simulation_results.json") + parser.add_argument("--seed", type=int, default=SEED) + parser.add_argument("--active", action="store_true", help="model continuous taps and manual cooldowns") + args = parser.parse_args() + + rules = Rules(read_json(RULES_PATH)) + content = read_json(CONTENT_PATH) + report = simulate(content, rules, args.seed, active=args.active) + + names = hero_names(content) + print(f"{'node':<14} {'type':<8} {'result':<8} {'time':>7} {'dps':>7} {'gold':>6} {'heroes':>7}") + for row in report["results"]: + print( + f"{row['node']:<14} {row['type']:<8} {row['result']:<8} " + f"{row.get('duration', 0):>7} {row['dps']:>7} {row['gold']:>6} {row.get('heroes', 0):>7}" + ) + final = report["final"] + print(f"\ncleared {len(final['completed'])}/10 nodes, gold={final['gold']}, crystal={final['crystal']}") + print("heroes: " + ", ".join(f"{names[h]} Lv.{final['levels'][h]}" for h in final["heroes"])) + + args.out.write_text( + json.dumps(report, ensure_ascii=False, indent=2, sort_keys=True) + "\n", + encoding="utf-8", + ) + losses = [row for row in report["results"] if row["result"] == "loss"] + return 1 if losses else 0 + + +if __name__ == "__main__": + raise SystemExit(main())