User: "数值应该都可以有对应关系." Completed the numeric provenance: - cf_formulas.py/.gd: added nearest_family(v) (which CH linear family a tuned coefficient maps to), monster_hp_mult(tier,boss) (CH monster_growth 1.6^L / 1.145^L + boss 1.5x), skill_duration_scale (CH skills.json duration 30s -> 5s combat timebase). CF_FORMULA_PARITY_PASS 41 cases py==gd. - edict_rules.py now reads coefficients from CH LINEAR_COEFF (D02=linear10 0.10, D03/D05=linear15 0.15, D04=linear20 0.20, D06=linear25 0.25) instead of hardcoded values; only interval/cooldown remain new-game tuning. - PRODUCTION/52 documents every remaining number's CH correspondence: skill damage -> nearest linear family, buff/debuff 5s -> CH 30s/6, stun 1.5s -> 5s*0.3, enemy multipliers -> CH monster curve. Honest boundary: values that are new-game tuned (interval multipliers, exact skill damage coefficients) are documented as CH-family-derived + tuning, not passed off as exact CH numbers. Full P2_CHECKS_PASS (93 gates). prototype/ untracked.
161 lines
5.9 KiB
Python
161 lines
5.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Authoritative CF/CH numeric migration layer.
|
|
|
|
Per CF_REFERENCE_AND_ORIGINALIZATION_CONTRACT.md 2.2: Windroost inherits CH's
|
|
*formula families and magnitude*, then tunes parameters for its own content.
|
|
This module implements CH's real formulas (from ancient_book.gd / outsider_book
|
|
logic) and reads the CF source tables copied into data/cf_reference/, so every
|
|
number used by Windroost's systems can be traced to a CH source formula.
|
|
|
|
Formula families (CH ancient_book.gd bonus_at / _cumulative_value):
|
|
linear01/linear1/linear5/linear10/linear15/linear25 -> coefficient * level
|
|
diminishingReturns -> params[0] * (1 - e^(params[1]*level))
|
|
exponential (cost) -> 2^(level+1) - 2
|
|
polynomial1_5 (cost) -> 0.4 L^2.5 - 0.5 L^1.5 + 0.125 sqrt(L) - ...
|
|
linear (cost) -> 0.5 * param * L * (L+1)
|
|
|
|
Mirrored by p2_godot_sample/scripts/cf_formulas.gd (parity gated).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import math
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
TABLES_PATH = ROOT / "data" / "cf_reference" / "numeric_tables.json"
|
|
|
|
# linear family name -> coefficient (CH: coefficient = float(name minus "linear");
|
|
# "linear01" is the 0.01 special case; "linear0_25" uses underscore for decimal).
|
|
LINEAR_COEFF = {
|
|
"linear01": 0.01, "linear0_25": 0.0025, "linear0.25": 0.0025,
|
|
"linear1": 0.01, "linear5": 0.05, "linear10": 0.10,
|
|
"linear15": 0.15, "linear25": 0.25, "linear30": 0.30,
|
|
"linear50": 0.50, "linear75": 0.75, "linear100": 1.00,
|
|
"linear11": 0.11, "linear12_5": 0.125, "linear20": 0.20,
|
|
}
|
|
|
|
|
|
def bonus_at(family: str, level: float, params: str = "0,0") -> float:
|
|
"""CH bonus value at `level` for a levelAmountFormula family."""
|
|
fam = family.lower()
|
|
if fam in LINEAR_COEFF:
|
|
return LINEAR_COEFF[fam] * level
|
|
if fam.startswith("linear"):
|
|
suffix = fam[len("linear"):].replace("_", ".")
|
|
try:
|
|
return float(suffix) * level
|
|
except ValueError:
|
|
return 0.0
|
|
if fam == "diminishingreturns" or fam == "diminishing":
|
|
p = [float(x) for x in params.split(",")]
|
|
a, b = (p[0], p[1]) if len(p) >= 2 else (1.0, -0.01)
|
|
return a * (1.0 - math.exp(b * level))
|
|
if fam == "percent5":
|
|
return 5.0 * level
|
|
return 0.0 # special/relic-specific families (solomonRewards, libAndSiy...)
|
|
|
|
|
|
def cost_at(family: str, level: float, params: str = "1") -> float:
|
|
"""CH cumulative cost at `level` for a levelCostFormula family."""
|
|
fam = family.lower()
|
|
if fam == "linear":
|
|
try:
|
|
param = float(params)
|
|
except ValueError:
|
|
param = 1.0
|
|
return 0.5 * param * level * (level + 1.0)
|
|
if fam == "one":
|
|
return level
|
|
if fam == "exponential":
|
|
return 2.0 ** (level + 1.0) - 2.0
|
|
if fam == "polynomial1_5":
|
|
L = level
|
|
return (0.4 * L ** 2.5 - 0.5 * L ** 1.5 + 0.125 * math.sqrt(L)
|
|
- (0.00052 / (L ** 1.5)) if L > 0 else 0.0)
|
|
return level # unknown -> linear identity
|
|
|
|
|
|
def tables() -> Dict[str, Any]:
|
|
return json.loads(TABLES_PATH.read_text(encoding="utf-8"))
|
|
|
|
|
|
def relic_family(relic_id: int) -> str:
|
|
for r in tables()["relics"]:
|
|
if int(r["id"]) == relic_id:
|
|
return str(r.get("levelAmountFormula", "linear1"))
|
|
return "linear1"
|
|
|
|
|
|
def ancient_cost_family(ancient_id: int) -> str:
|
|
for a in tables()["ancients"]:
|
|
if int(a.get("id", -1)) == ancient_id:
|
|
return str(a.get("levelCostFormula", "linear"))
|
|
return "linear"
|
|
|
|
|
|
def outsider_cost_family(outsider_id: int) -> str:
|
|
for o in tables()["outsiders"]:
|
|
if int(o.get("id", -1)) == outsider_id:
|
|
return str(o.get("levelCostFormula", "linear1"))
|
|
return "linear1"
|
|
|
|
|
|
def daily_target(task_kind: str) -> int:
|
|
"""CH/CF daily_tasks target by task kind (the board is CF-original)."""
|
|
for t in tables()["daily_tasks"]:
|
|
if str(t.get("kind", "")) == task_kind:
|
|
return int(t.get("target", 0))
|
|
return 0
|
|
|
|
|
|
def daily_rubies(task_kind: str) -> int:
|
|
for t in tables()["daily_tasks"]:
|
|
if str(t.get("kind", "")) == task_kind:
|
|
return int(t.get("rubies", 0))
|
|
return 0
|
|
|
|
|
|
def nearest_family(value: float) -> str:
|
|
"""Which CH linear family is closest to `value`? For provenance lookup:
|
|
a tuned coefficient can be traced to its CH formula-family origin."""
|
|
if value <= 0:
|
|
return "linear01"
|
|
best = min(LINEAR_COEFF.items(), key=lambda kv: abs(kv[1] - value))
|
|
return best[0]
|
|
|
|
|
|
def monster_hp_mult(tier: int, boss: bool = False) -> float:
|
|
"""CH monster_growth health curve: 1.6^early, later RATE=1.145.
|
|
Returns a bounded multiplier for a tier (used as enemy mechanic provenance)."""
|
|
rate = 1.145 if tier > 10 else 1.6
|
|
m = rate ** min(tier, 12) / (rate ** 4) # normalize so tier 4 -> 1.0
|
|
if boss:
|
|
m *= 1.5 # CH boss health multiplier
|
|
return round(m, 4)
|
|
|
|
|
|
def skill_duration_scale(seconds: float) -> float:
|
|
"""CH skills.json duration is 30s (idle game); Windroost combat is ~6x
|
|
shorter. Scale a CH duration into the combat timebase (30 -> 5s)."""
|
|
return round(seconds / 6.0, 4)
|
|
|
|
|
|
def validate() -> List[str]:
|
|
problems = []
|
|
t = tables()
|
|
for key in ("relics", "ancients", "outsiders", "daily_tasks", "skills"):
|
|
if not t.get(key):
|
|
problems.append(f"missing CF source table: {key}")
|
|
# CH formula sanity: linear10 at level 10 must be 1.0 (=+100%, the CH magnitude)
|
|
if abs(bonus_at("linear10", 10.0) - 1.0) > 1e-9:
|
|
problems.append("linear10(10) must equal 1.0")
|
|
if abs(cost_at("exponential", 1.0) - 2.0) > 1e-9:
|
|
problems.append("exponential(1) must equal 2.0")
|
|
if nearest_family(0.5) != "linear50":
|
|
problems.append("nearest_family(0.5) must be linear50")
|
|
if abs(skill_duration_scale(30.0) - 5.0) > 1e-9:
|
|
problems.append("skill_duration_scale(30) must be 5.0")
|
|
return problems
|