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
33 changes: 29 additions & 4 deletions calc-sidecar/test/backends/rocalc/alchemist_buffs.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "node:test";
import { test, before } from "node:test";
import assert from "node:assert/strict";
import { createShim } from "../../../src/shim.ts";

Expand All @@ -15,7 +15,29 @@ const AXE_2H = 1360; // Two-Handed Axe (W_2HAXE)
const DAGGER = 1207; // Main Gauche (W_DAGGER) -- non-axe negative
const MACE = 1501; // Club (W_MACE) -- non-axe negative

function alShim(weaponId: number, className = "alchemist") {
// The shim (jsdom + class load) is the expensive part, so it is created once in
// before() and reused for the Alchemist tests. reset() preserves the class but
// clears the buff banks and rolls level / stats / equipment back to baseline, so
// fresh(weaponId) re-applies the build for a clean, leak-free baseline without
// re-paying createShim+setClass. The Creator case keeps its own session because
// reset() does not roll back rocalc's class globals (that needs the expensive
// class change).
let shim: ReturnType<typeof createShim>;
before(() => {
shim = createShim();
shim.setClass("alchemist");
});
function fresh(weaponId: number) {
shim.reset();
shim.setLevel({ base: 99, job: 70 });
shim.setStats({ str: 90, agi: 40, vit: 40, int: 40, dex: 90, luk: 20 });
shim.equip("weapon", { id: weaponId });
return shim;
}

// Creator (and any non-Alchemist) needs its own session: reset() preserves the
// class, so the shared Alchemist shim cannot stand in for it.
function otherClassShim(weaponId: number, className: string) {
const s = createShim();
s.setClass(className);
s.setLevel({ base: 99, job: 70 });
Expand Down Expand Up @@ -44,7 +66,10 @@ function aveWith(
buffs: Buff[],
className = "alchemist",
): number {
const s = alShim(weaponId, className);
const s =
className === "alchemist"
? fresh(weaponId)
: otherClassShim(weaponId, className);
if (buffs.length) s.setBuffs(buffs);
s.setEnemyInline(ENEMY);
const ave = s.readCombatResults().damage.ave;
Expand Down Expand Up @@ -98,7 +123,7 @@ test("axe_mastery raises damage.ave for Creator too (identical bank)", () => {

test("reset() clears axe_mastery (no damage.ave leak)", () => {
const plain = aveWith(AXE_2H, []);
const s = alShim(AXE_2H);
const s = fresh(AXE_2H);
s.setBuffs([{ name: "axe_mastery", level: 10 }]);
s.setEnemyInline(ENEMY);
s.readCombatResults();
Expand Down
104 changes: 53 additions & 51 deletions calc-sidecar/test/backends/rocalc/attack_skills.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
import { test } from "node:test";
import { test, before, beforeEach } from "node:test";
import assert from "node:assert/strict";
import { createShim } from "../../../src/shim.ts";

const PORING = 1002; // iRO mob id; translates to rocalc m_Monster index 272

function tkBare(s: ReturnType<typeof createShim>) {
s.setClass("taekwon_kid");
s.setLevel({ base: 99, job: 70 });
s.setStats({ str: 90, agi: 80, vit: 40, int: 1, dex: 70, luk: 1 });
// The shim (jsdom + class load) is created once and reused; reset() preserves
// the class but clears pending attack skills and the last breakdown, so
// reset()+reconfigure in beforeEach gives every test a clean baseline without
// re-paying the ~4s createShim+setClass per test.
let shim: ReturnType<typeof createShim>;

// reset() rolls level / stats back to the class baseline; re-apply the bare TK
// build (no weapon) after each reset. The class itself survives reset().
function reconfig(): void {
shim.setLevel({ base: 99, job: 70 });
shim.setStats({ str: 90, agi: 80, vit: 40, int: 1, dex: 70, luk: 1 });
}

before(() => {
shim = createShim();
shim.setClass("taekwon_kid");
});

beforeEach(() => {
shim.reset();
reconfig();
});

test("primary attack skill drives top-level damage above auto-attack", () => {
const s = createShim();
tkBare(s);
s.setEnemy(PORING);
const auto = s.readCombatResults().damage.ave;

s.reset();
tkBare(s);
s.setAttackSkills([{ name: "roundhouse", level: 7, primary: true }]);
s.setEnemy(PORING);
const c = s.readCombatResults();
shim.setEnemy(PORING);
const auto = shim.readCombatResults().damage.ave;

shim.reset();
reconfig();
shim.setAttackSkills([{ name: "roundhouse", level: 7, primary: true }]);
shim.setEnemy(PORING);
const c = shim.readCombatResults();
assert.ok(c.damage.ave !== null && auto !== null);
assert.ok(
c.damage.ave > auto,
Expand All @@ -31,14 +46,12 @@ test("primary attack skill drives top-level damage above auto-attack", () => {
});

test("breakdown reports each declared skill with hit counts; primary drives top-level", () => {
const s = createShim();
tkBare(s);
s.setAttackSkills([
shim.setAttackSkills([
{ name: "tornado_kick", level: 7, primary: true },
{ name: "counter_kick", level: 7 },
]);
s.setEnemy(PORING);
const c = s.readCombatResults();
shim.setEnemy(PORING);
const c = shim.readCombatResults();
const byName = Object.fromEntries((c.skills ?? []).map((k) => [k.name, k]));
assert.ok(byName["tornado_kick"] && byName["counter_kick"]);
assert.equal(byName["counter_kick"].hits, 3); // confirmed in Task 1
Expand All @@ -47,41 +60,34 @@ test("breakdown reports each declared skill with hit counts; primary drives top-
});

test("absent attack_skills leaves auto-attack behavior unchanged (no skills field)", () => {
const s = createShim();
tkBare(s);
s.setEnemy(PORING);
const c = s.readCombatResults();
shim.setEnemy(PORING);
const c = shim.readCombatResults();
assert.equal(c.skills, undefined);
});

test("unknown attack-skill name throws", () => {
const s = createShim();
tkBare(s);
assert.throws(() =>
s.setAttackSkills([{ name: "fireball", level: 1, primary: true }]),
shim.setAttackSkills([{ name: "fireball", level: 1, primary: true }]),
);
});

test("zero primaries throws (top-level damage would be undefined)", () => {
const s = createShim();
tkBare(s);
assert.throws(() => s.setAttackSkills([{ name: "tornado_kick", level: 7 }]));
assert.throws(() =>
shim.setAttackSkills([{ name: "tornado_kick", level: 7 }]),
);
});

test("two primaries throws (ambiguous top-level damage)", () => {
const s = createShim();
tkBare(s);
assert.throws(() =>
s.setAttackSkills([
shim.setAttackSkills([
{ name: "tornado_kick", level: 7, primary: true },
{ name: "roundhouse", level: 7, primary: true },
]),
);
});

test("supportedAttackSkills returns the binding keys", () => {
const s = createShim();
const names = s.supportedAttackSkills();
const names = shim.supportedAttackSkills();
assert.ok(
names && names.includes("tornado_kick") && names.includes("roundhouse"),
);
Expand All @@ -101,26 +107,22 @@ const INLINE = {
};

test("breakdown is computed against an inline mob (before m_Monster restore)", () => {
const s = createShim();
tkBare(s);
s.setAttackSkills([{ name: "roundhouse", level: 7, primary: true }]);
s.setEnemyInline(INLINE);
const c = s.readCombatResults();
shim.setAttackSkills([{ name: "roundhouse", level: 7, primary: true }]);
shim.setEnemyInline(INLINE);
const c = shim.readCombatResults();
assert.equal(c.skills?.length, 1);
assert.ok(c.skills?.[0].damage.ave !== null && c.skills[0].damage.ave > 0);
assert.equal(c.damage.ave, c.skills?.[0].damage.ave); // primary drives top-level
});

test("reset clears a scored skill: next auto-attack request is unbuffed baseline", () => {
const s = createShim();
tkBare(s);
s.setEnemy(PORING);
const auto = s.readCombatResults().damage.ave;
s.setAttackSkills([{ name: "roundhouse", level: 7, primary: true }]);
s.setEnemy(PORING);
assert.ok(s.readCombatResults().damage.ave! > auto!);
s.reset();
tkBare(s);
s.setEnemy(PORING);
assert.equal(s.readCombatResults().damage.ave, auto); // back to auto-attack
shim.setEnemy(PORING);
const auto = shim.readCombatResults().damage.ave;
shim.setAttackSkills([{ name: "roundhouse", level: 7, primary: true }]);
shim.setEnemy(PORING);
assert.ok(shim.readCombatResults().damage.ave! > auto!);
shim.reset();
reconfig();
shim.setEnemy(PORING);
assert.equal(shim.readCombatResults().damage.ave, auto); // back to auto-attack
});
24 changes: 19 additions & 5 deletions calc-sidecar/test/backends/rocalc/buff_controls.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { test } from "node:test";
import { test, before } from "node:test";
import assert from "node:assert/strict";
import { createShim } from "../../../src/shim.ts";

// createShim (jsdom + calc engine) + setClass is the expensive part, so it runs
// once in before() and is reused. reset() preserves the class but clears the
// buff/debuff/land/music banks and rolls level/stats/equipment back to the class
// baseline, so fresh() = reset()+reconfigure yields a clean, leak-free shim
// without re-paying the createShim+setClass cost.
let shim: ReturnType<typeof createShim>;
before(() => {
shim = createShim();
shim.setClass("high_priest");
});
function fresh() {
shim.reset();
shim.setLevel({ base: 99, job: 70 });
shim.setStats({ str: 40, agi: 80, vit: 60, int: 80, dex: 60, luk: 30 });
return shim;
}

// The injected banks must exist and, with the section gates off (default),
// have no effect on a baseline High Priest. setSkills/setStats path proves the
// controls are present (no "Cannot read properties of undefined").
test("buff control banks are injected and inert until driven", () => {
const s = createShim();
s.setClass("high_priest");
s.setLevel({ base: 99, job: 70 });
s.setStats({ str: 40, agi: 80, vit: 60, int: 80, dex: 60, luk: 30 });
const s = fresh();
// Reading derived stats forces a full StAllCalc; if any A2_Skill*/B_debuf*
// referenced by a gated read were missing, rocalc would throw here once the
// gate is on. With gates off it must simply succeed.
Expand Down
Loading
Loading