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.
109 lines
3.0 KiB
GDScript
109 lines
3.0 KiB
GDScript
class_name CfFormulas
|
|
extends RefCounted
|
|
|
|
## GDScript mirror of tools/fullgame/cf_formulas.py. CH formula families + CF
|
|
## source tables, so Windroost numbers trace to a CH source. Parity gated.
|
|
|
|
const 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,
|
|
}
|
|
const TABLES_PATH := "res://data/cf_reference/numeric_tables.json"
|
|
|
|
|
|
static func bonus_at(family: String, level: float, params: String = "0,0") -> float:
|
|
var fam := family.to_lower()
|
|
if LINEAR_COEFF.has(fam):
|
|
return float(LINEAR_COEFF[fam]) * level
|
|
if fam.begins_with("linear"):
|
|
var suffix := fam.substr(6).replace("_", ".")
|
|
return suffix.to_float() * level
|
|
if fam == "diminishingreturns" or fam == "diminishing":
|
|
var p := params.split(",")
|
|
var a := 1.0
|
|
var b := -0.01
|
|
if p.size() >= 2:
|
|
a = float(p[0]); b = float(p[1])
|
|
return a * (1.0 - exp(b * level))
|
|
if fam == "percent5":
|
|
return 5.0 * level
|
|
return 0.0
|
|
|
|
|
|
static func cost_at(family: String, level: float, params: String = "1") -> float:
|
|
var fam := family.to_lower()
|
|
if fam == "linear":
|
|
return 0.5 * params.to_float() * level * (level + 1.0)
|
|
if fam == "one":
|
|
return level
|
|
if fam == "exponential":
|
|
return pow(2.0, level + 1.0) - 2.0
|
|
if fam == "polynomial1_5":
|
|
if level <= 0.0:
|
|
return 0.0
|
|
return 0.4 * pow(level, 2.5) - 0.5 * pow(level, 1.5) \
|
|
+ 0.125 * sqrt(level) - 0.00052 / pow(level, 1.5)
|
|
return level
|
|
|
|
|
|
static func tables() -> Dictionary:
|
|
var f := FileAccess.open(TABLES_PATH, FileAccess.READ)
|
|
if f == null:
|
|
return {}
|
|
var parsed = JSON.parse_string(f.get_as_text())
|
|
f.close()
|
|
return parsed if parsed is Dictionary else {}
|
|
|
|
|
|
static func relic_family(relic_id: int) -> String:
|
|
for r in tables().get("relics", []):
|
|
var row: Dictionary = r
|
|
if int(row.get("id", 0)) == relic_id:
|
|
return str(row.get("levelAmountFormula", "linear1"))
|
|
return "linear1"
|
|
|
|
|
|
static func daily_target(task_kind: String) -> int:
|
|
for t in tables().get("daily_tasks", []):
|
|
var row: Dictionary = t
|
|
if str(row.get("kind", "")) == task_kind:
|
|
return int(row.get("target", 0))
|
|
return 0
|
|
|
|
|
|
static func daily_rubies(task_kind: String) -> int:
|
|
for t in tables().get("daily_tasks", []):
|
|
var row: Dictionary = t
|
|
if str(row.get("kind", "")) == task_kind:
|
|
return int(row.get("rubies", 0))
|
|
return 0
|
|
|
|
|
|
static func nearest_family(value: float) -> String:
|
|
if value <= 0.0:
|
|
return "linear01"
|
|
var best := ""
|
|
var best_diff := 1e9
|
|
for k in LINEAR_COEFF.keys():
|
|
var diff := absf(float(LINEAR_COEFF[k]) - value)
|
|
if diff < best_diff:
|
|
best_diff = diff
|
|
best = str(k)
|
|
return best
|
|
|
|
|
|
static func monster_hp_mult(tier: int, boss: bool = false) -> float:
|
|
var rate := 1.145 if tier > 10 else 1.6
|
|
var t := mini(tier, 12)
|
|
var m := pow(rate, float(t)) / pow(rate, 4.0)
|
|
if boss:
|
|
m *= 1.5
|
|
return snappedf(m, 0.0001)
|
|
|
|
|
|
static func skill_duration_scale(seconds: float) -> float:
|
|
return snappedf(seconds / 6.0, 0.0001)
|