Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions calc-sidecar/src/backends/rocalc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,22 @@ export function createShim(): ShimSession {
};
}

// Effective stat = allocation (form input) + rendered bonus (A_<STAT>p).
// The bonus reflects gear, cards, and active self-buffs after StAllCalc.
function readTotalStats(): Stats {
const one = (s: string): number =>
parseInt(String(form[`A_${s}`].value), 10) +
readStatBonus(doc, `A_${s}p`);
return {
str: one("STR"),
agi: one("AGI"),
vit: one("VIT"),
int: one("INT"),
dex: one("DEX"),
luk: one("LUK"),
};
}

function readDerivedStats(): DerivedStats {
return {
hit: readInt(doc, "A_HIT"),
Expand All @@ -1122,6 +1138,7 @@ export function createShim(): ShimSession {
maxHp: readInt(doc, "A_MaxHP"),
maxSp: readInt(doc, "A_MaxSP"),
statPointsRemaining: readInt(doc, "A_STPOINT"),
totalStats: readTotalStats(),
};
}

Expand Down Expand Up @@ -2486,6 +2503,15 @@ function readInt(doc: Document, id: string): number {
return n;
}

// A_<STAT>p holds the rendered stat bonus as " + N" or " - N" (gear + cards
// + active buffs, computed by StAllCalc). Parse it back to a signed int.
function readStatBonus(doc: Document, id: string): number {
const text = readCell(doc, id).replace(/\s+/g, "");
if (text === "") return 0;
const n = parseInt(text, 10);
return Number.isNaN(n) ? 0 : n;
}

function readFloat(doc: Document, id: string): number {
const text = readCell(doc, id);
const n = parseFloat(text);
Expand Down
6 changes: 5 additions & 1 deletion calc-sidecar/src/backends/stub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const STUB_DERIVED: DerivedStats = {
maxHp: 1000,
maxSp: 100,
statPointsRemaining: 0,
totalStats: { str: 1, agi: 1, vit: 1, int: 1, dex: 1, luk: 1 },
};

const STUB_COMBAT: CombatResults = {
Expand Down Expand Up @@ -118,7 +119,10 @@ export function createShim(): ShimSession {
state.enemy = null;
},
readDerivedStats() {
return structuredClone(STUB_DERIVED);
return {
...structuredClone(STUB_DERIVED),
totalStats: structuredClone(state.stats),
};
},
readCombatResults() {
return structuredClone(STUB_COMBAT);
Expand Down
5 changes: 5 additions & 0 deletions calc-sidecar/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export interface DerivedStats {
* over-budget (rocalc's BLVauto is disabled by the shim). Callers
* should treat negative values as "build is invalid for this level". */
statPointsRemaining: number;
/** The six primary stats after gear, cards, and self-buffs. Excludes
* external party buffs (Blessing, Poem of Bragi) because those are never
* sent to the calc. Quality gates read these instead of the build's raw
* status-point allocation. */
totalStats: Stats;
}

/** Combat-sim output. Numeric fields are `number | null` because rocalc
Expand Down
1 change: 1 addition & 0 deletions calc-sidecar/test/backends/rocalc/shim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe("shim shared session; Novice default class", () => {
maxHp: 40,
maxSp: 11,
statPointsRemaining: 48,
totalStats: { str: 1, agi: 1, vit: 1, int: 1, dex: 1, luk: 1 },
});
});

Expand Down
22 changes: 22 additions & 0 deletions calc-sidecar/test/backends/rocalc/total-stats.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { createShim } from "../../../src/backends/rocalc/index.ts";

// Orleans's Glove (iRO 2785) grants +DEX; a build wearing it must report
// effective DEX above the bare allocation.
test("rocalc totalStats reflects gear DEX bonus", () => {
const shim = createShim();
shim.setClass("high_wizard");
shim.setLevel({ base: 99, job: 70 });
shim.setStats({ str: 1, agi: 1, vit: 25, int: 99, dex: 99, luk: 1 });
const before = shim.readDerivedStats().totalStats.dex;
shim.equip("accessory1", { id: 2785, cards: [4064] }); // glove + Zerom (+DEX)
const after = shim.readDerivedStats().totalStats.dex;
// before > 99 because rocalc folds High Wizard's job-level DEX bonuses
// into A_DEXp; that is correct behavior (job bonuses are part of the
// effective stat). The only firm assertion is that gear raises it further.
assert.ok(
after > before,
`expected DEX bonus from gear: before=${before} after=${after}`,
);
});
17 changes: 17 additions & 0 deletions calc-sidecar/test/backends/stub/total-stats.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { createShim } from "../../../src/backends/stub/index.ts";

test("stub readDerivedStats echoes allocated stats as totalStats", () => {
const shim = createShim();
shim.setStats({ str: 1, agi: 1, vit: 9, int: 34, dex: 40, luk: 1 });
const d = shim.readDerivedStats();
assert.deepEqual(d.totalStats, {
str: 1,
agi: 1,
vit: 9,
int: 34,
dex: 40,
luk: 1,
});
});
2 changes: 1 addition & 1 deletion cmd/build-catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func main() {
}

out := catalogFile{
Version: 2,
Version: 3,
Mode: "pre-renewal",
Source: sourceLabel(source),
GeneratedAt: time.Now().UTC(),
Expand Down
4 changes: 2 additions & 2 deletions configs/servers/uaro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@ quality_gates:
mvp_magic_burst: 2.5

ttk_mvp_max_sec: 300 # beyond 5 minutes MVP regen / status timers undermine the kill
cast_time_warn_ms: 2000 # any allocated cast skill > 2s effective cast → warn
cast_time_fail_ms: 4000 # > 4s effective cast → fail (build can't use the skill in combat)
cast_time_warn_ms: 3000 # primary skill effective cast > 3s -> slowness warn
cast_interrupt_ms: 2000 # interruptible primary effective cast > 2s + no cast-safety -> interruption gate

# Per-scenario-type status_immunity priority. fail = build must clear
# immunity (gate emits fail severity if uncovered); warn = LLM should
Expand Down
4 changes: 3 additions & 1 deletion internal/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ var catalogJSON []byte
// v2: added JobMaxLevels (per-class base + job level caps parsed from
// Hercules job_db.conf + exp_group_db.conf), replacing the hand-rolled
// classMaxLevels table.
const expectedVersion = 2
// v3: added Skill.CastTimeByLevelMs (sparse per-level cast time for
// skills whose cast scales with level, e.g. the bolts, Storm Gust).
const expectedVersion = 3

// catalogFile mirrors the schema cmd/build-catalog writes.
type catalogFile struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/catalog/data/catalog.json

Large diffs are not rendered by default.

71 changes: 66 additions & 5 deletions internal/data/sources/hercules/skills.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ type Skill struct {

// Cast / cooldown metadata for the quality-gates evaluator. Milliseconds
// at MaxLevel. 0 means "no cast / no cooldown".
CastTimeMs int `json:"cast_time_ms,omitempty"` // variable cast (DEX-reducible in pre-re per cast = base * (150-DEX)/150)
FixedCastMs int `json:"fixed_cast_ms,omitempty"` // fixed portion (uncommon in pre-re, present on a few skills)
AfterCastMs int `json:"after_cast_ms,omitempty"` // post-cast delay (blocks all skills for X ms after the cast finishes)
CooldownMs int `json:"cooldown_ms,omitempty"` // single-skill cooldown (blocks reuse of *this* skill)
Interruptible bool `json:"interruptible,omitempty"` // cast cancellable by damage; only meaningful when CastTimeMs > 0
CastTimeMs int `json:"cast_time_ms,omitempty"` // variable cast (DEX-reducible in pre-re per cast = base * (150-DEX)/150)
FixedCastMs int `json:"fixed_cast_ms,omitempty"` // fixed portion (uncommon in pre-re, present on a few skills)
AfterCastMs int `json:"after_cast_ms,omitempty"` // post-cast delay (blocks all skills for X ms after the cast finishes)
CooldownMs int `json:"cooldown_ms,omitempty"` // single-skill cooldown (blocks reuse of *this* skill)
// CastTimeByLevelMs is the variable cast time at each level (index i =
// level i+1), populated only when the source declares per-level cast
// (the bolts, Storm Gust, Meteor, etc.). nil for flat-cast skills, which
// use the scalar CastTimeMs at every level. Kept sparse to bound the
// embedded catalog's size.
CastTimeByLevelMs []int `json:"cast_time_by_level_ms,omitempty"`
Interruptible bool `json:"interruptible,omitempty"` // cast cancellable by damage; only meaningful when CastTimeMs > 0

// StatusChange is the SC_X identifier of the status the skill applies
// when it lands ("SC_FREEZE" for WZ_STORMGUST, "SC_STUN" for
Expand Down Expand Up @@ -121,6 +127,7 @@ func skillFromMap(m map[string]any) (Skill, error) {
// Cast / cooldown numerics; flat int OR { Lv1: N, Lv2: N, ... }.
// Pick the value at MaxLevel; intAtMaxLevel handles both shapes.
s.CastTimeMs = intAtMaxLevel(m["CastTime"], s.MaxLevel)
s.CastTimeByLevelMs = intSliceByLevel(m["CastTime"], s.MaxLevel)
s.FixedCastMs = intAtMaxLevel(m["FixedCastTime"], s.MaxLevel)
s.AfterCastMs = intAtMaxLevel(m["AfterCastActDelay"], s.MaxLevel)
s.CooldownMs = intAtMaxLevel(m["CoolDown"], s.MaxLevel)
Expand All @@ -141,6 +148,60 @@ func skillFromMap(m map[string]any) (Skill, error) {
return s, nil
}

// CastAtLevelMs returns the variable cast time at the given level. Uses the
// per-level table when present; otherwise falls back to the scalar
// CastTimeMs (flat-cast skills). Level is clamped to [1, len].
func (s Skill) CastAtLevelMs(level int) int {
if len(s.CastTimeByLevelMs) == 0 {
return s.CastTimeMs
}
if level < 1 {
level = 1
}
if level > len(s.CastTimeByLevelMs) {
level = len(s.CastTimeByLevelMs)
}
return s.CastTimeByLevelMs[level-1]
}

// intSliceByLevel resolves a Hercules skill_db numeric field to a per-level
// slice (index i = level i+1) when it is a grouped object
// (`{ Lv1: 700, Lv2: 1400, ... }`). Returns nil for a flat int or absent
// field, signaling "no per-level variation; use the scalar".
func intSliceByLevel(v any, maxLevel int) []int {
t, ok := v.(map[string]any)
if !ok {
return nil
}
n := maxLevel
// Defensive: grow to the highest LvN present if it exceeds maxLevel.
for k := range t {
if !strings.HasPrefix(k, "Lv") {
continue
}
if lv, err := strconv.Atoi(k[2:]); err == nil && lv > n {
n = lv
}
}
if n <= 0 {
return nil
}
out := make([]int, n)
populated := false
for i := 0; i < n; i++ {
if iv, ok := t[fmt.Sprintf("Lv%d", i+1)].(int); ok {
out[i] = iv
populated = true
} else if i > 0 {
out[i] = out[i-1] // carry forward sparse gaps
}
}
if !populated {
return nil
}
return out
}

// stringAtMaxLevel mirrors intAtMaxLevel for string-typed fields
// (specifically Element, which can be flat "Ele_Fire" or grouped
// {Lv1: "Ele_Fire", Lv2: "Ele_Wind", ...}). Returns "" when absent or
Expand Down
50 changes: 49 additions & 1 deletion internal/data/sources/hercules/skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hercules

import (
"os"
"reflect"
"testing"
)

Expand Down Expand Up @@ -43,7 +44,7 @@ func TestLoadSkillDB_PreReKnownEntries(t *testing.T) {
t.Errorf("skill %d (%s) missing", want.ID, want.AegisName)
continue
}
if got != want {
if !reflect.DeepEqual(got, want) {
t.Errorf("skill %d mismatch:\nwant %+v\ngot %+v", want.ID, want, got)
}
}
Expand Down Expand Up @@ -111,6 +112,53 @@ func TestLoadSkillDB_PreReCastMetadata(t *testing.T) {
}
}

func TestCastTimeByLevel_BoltScales(t *testing.T) {
m := map[string]any{
"Id": 14, "Name": "MG_COLDBOLT", "Description": "Cold Bolt", "MaxLevel": 10,
"CastTime": map[string]any{
"Lv1": 700, "Lv2": 1400, "Lv3": 2100, "Lv4": 2800, "Lv5": 3500,
"Lv6": 4200, "Lv7": 4900, "Lv8": 5600, "Lv9": 6300, "Lv10": 7000,
},
}
s, err := skillFromMap(m)
if err != nil {
t.Fatal(err)
}
want := []int{700, 1400, 2100, 2800, 3500, 4200, 4900, 5600, 6300, 7000}
if got := s.CastTimeByLevelMs; len(got) != 10 || got[3] != 2800 || got[9] != 7000 {
t.Fatalf("CastTimeByLevelMs = %v, want %v", got, want)
}
if got := s.CastAtLevelMs(4); got != 2800 {
t.Errorf("CastAtLevelMs(4) = %d, want 2800", got)
}
if got := s.CastAtLevelMs(10); got != 7000 {
t.Errorf("CastAtLevelMs(10) = %d, want 7000", got)
}
}

func TestCastTimeByLevel_FlatIsNil(t *testing.T) {
m := map[string]any{
"Id": 254, "Name": "CR_GRANDCROSS", "Description": "Grand Cross",
"MaxLevel": 10, "CastTime": 2000,
}
s, err := skillFromMap(m)
if err != nil {
t.Fatal(err)
}
if s.CastTimeByLevelMs != nil {
t.Errorf("flat-cast skill should have nil CastTimeByLevelMs, got %v", s.CastTimeByLevelMs)
}
if got := s.CastAtLevelMs(3); got != 2000 {
t.Errorf("CastAtLevelMs(3) on flat skill = %d, want 2000 (scalar fallback)", got)
}
}

func TestIntSliceByLevel_EmptyMapIsNil(t *testing.T) {
if got := intSliceByLevel(map[string]any{}, 10); got != nil {
t.Errorf("empty grouped object should yield nil, got %v", got)
}
}

func TestIntAtMaxLevel(t *testing.T) {
cases := []struct {
name string
Expand Down
48 changes: 43 additions & 5 deletions internal/data/sources/rathena/skills.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,54 @@ func LoadSkillDB(rathenaRoot, modeDir string) ([]Skill, error) {
// comparison is direct.
Element: normalizeElement(element),

CastTimeMs: intAtMaxLevel(raw.CastTime, raw.MaxLevel),
FixedCastMs: intAtMaxLevel(raw.FixedCastTime, raw.MaxLevel),
AfterCastMs: intAtMaxLevel(raw.AfterCastActDelay, raw.MaxLevel),
CooldownMs: intAtMaxLevel(raw.Cooldown, raw.MaxLevel),
Interruptible: interruptible,
CastTimeMs: intAtMaxLevel(raw.CastTime, raw.MaxLevel),
CastTimeByLevelMs: castSliceByLevel(raw.CastTime, raw.MaxLevel),
FixedCastMs: intAtMaxLevel(raw.FixedCastTime, raw.MaxLevel),
AfterCastMs: intAtMaxLevel(raw.AfterCastActDelay, raw.MaxLevel),
CooldownMs: intAtMaxLevel(raw.Cooldown, raw.MaxLevel),
Interruptible: interruptible,
})
}
return out, nil
}

// castSliceByLevel resolves a rAthena per-level numeric field
// (`[{Level: 1, Time: 700}, ...]`) to a per-level slice (index i = level
// i+1). Returns nil for a flat int or absent field.
func castSliceByLevel(v any, maxLevel int) []int {
seq, ok := v.([]any)
if !ok {
return nil
}
byLevel := map[int]int{}
n := maxLevel
for _, raw := range seq {
lv, time, ok := levelTimeEntry(raw)
if !ok {
continue
}
byLevel[lv] = time
if lv > n {
n = lv
}
}
if len(byLevel) == 0 {
return nil
}
if n <= 0 {
return nil
}
out := make([]int, n)
for i := 0; i < n; i++ {
if t, ok := byLevel[i+1]; ok {
out[i] = t
} else if i > 0 {
out[i] = out[i-1]
}
}
return out
}

// intAtMaxLevel resolves a rAthena skill_db numeric field to its MaxLevel
// value. rAthena uses two shapes: a flat int (`CastTime: 2000`) or a
// sequence of objects (`CastTime: [{Level: 1, Time: 6000}, ...]`).
Expand Down
6 changes: 6 additions & 0 deletions internal/data/sources/rathena/skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func TestLoadSkillDB_PreReCastMetadata(t *testing.T) {
}
}

func TestCastSliceByLevel_EmptySeqIsNil(t *testing.T) {
if got := castSliceByLevel([]any{}, 10); got != nil {
t.Errorf("empty sequence should yield nil, got %v", got)
}
}

func TestIntAtMaxLevel(t *testing.T) {
cases := []struct {
name string
Expand Down
Loading
Loading