mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-26 14:45:44 +00:00
fix regex node change
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { init } from "@/assets/data";
|
||||
import { ItemCategory } from "@/parser";
|
||||
import { ParsedModifier } from "@/parser/advanced-mod-desc";
|
||||
import { ModifierType } from "@/parser/modifiers";
|
||||
import { ModifierType, StatCalculated } from "@/parser/modifiers";
|
||||
import { __testExports } from "@/parser/Parser";
|
||||
import { createTestItem, makeCalcStat } from "@specs/helper";
|
||||
import { setupTests } from "@specs/vitest.setup";
|
||||
@@ -42,6 +42,160 @@ describe("determineAugments", () => {
|
||||
|
||||
expect(result.map((augment) => augment.refName)).toEqual(expectedRef);
|
||||
});
|
||||
|
||||
it("handles range mods correctly", () => {
|
||||
const mod = {
|
||||
info: {
|
||||
type: "rune",
|
||||
tags: [],
|
||||
},
|
||||
stats: [
|
||||
{
|
||||
stat: {
|
||||
ref: "Adds # to # Lightning Damage",
|
||||
better: 1,
|
||||
matchers: [
|
||||
{
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
],
|
||||
trade: {
|
||||
ids: {
|
||||
explicit: ["explicit.stat_3336890334"],
|
||||
fractured: ["fractured.stat_3336890334"],
|
||||
enchant: ["enchant.stat_3336890334"],
|
||||
rune: ["rune.stat_3336890334"],
|
||||
desecrated: ["desecrated.stat_3336890334"],
|
||||
crafted: ["crafted.stat_3336890334"],
|
||||
},
|
||||
},
|
||||
id: "local_minimum_added_lightning_damage",
|
||||
},
|
||||
translation: {
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
roll: {
|
||||
unscalable: false,
|
||||
dp: false,
|
||||
value: 15.5,
|
||||
min: 15.5,
|
||||
max: 15.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
} as unknown as ParsedModifier;
|
||||
|
||||
const statCalcs = [
|
||||
{
|
||||
stat: {
|
||||
ref: "Adds # to # Lightning Damage",
|
||||
better: 1,
|
||||
matchers: [
|
||||
{
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
],
|
||||
trade: {
|
||||
ids: {
|
||||
explicit: ["explicit.stat_3336890334"],
|
||||
fractured: ["fractured.stat_3336890334"],
|
||||
enchant: ["enchant.stat_3336890334"],
|
||||
rune: ["rune.stat_3336890334"],
|
||||
desecrated: ["desecrated.stat_3336890334"],
|
||||
crafted: ["crafted.stat_3336890334"],
|
||||
},
|
||||
},
|
||||
id: "local_minimum_added_lightning_damage",
|
||||
},
|
||||
type: "rune",
|
||||
sources: [
|
||||
{
|
||||
modifier: {
|
||||
info: {
|
||||
type: "rune",
|
||||
tags: [],
|
||||
},
|
||||
stats: [
|
||||
{
|
||||
stat: {
|
||||
ref: "Adds # to # Lightning Damage",
|
||||
better: 1,
|
||||
matchers: [
|
||||
{
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
],
|
||||
trade: {
|
||||
ids: {
|
||||
explicit: ["explicit.stat_3336890334"],
|
||||
fractured: ["fractured.stat_3336890334"],
|
||||
enchant: ["enchant.stat_3336890334"],
|
||||
rune: ["rune.stat_3336890334"],
|
||||
desecrated: ["desecrated.stat_3336890334"],
|
||||
crafted: ["crafted.stat_3336890334"],
|
||||
},
|
||||
},
|
||||
id: "local_minimum_added_lightning_damage",
|
||||
},
|
||||
translation: {
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
roll: {
|
||||
unscalable: false,
|
||||
dp: false,
|
||||
value: 15.5,
|
||||
min: 15.5,
|
||||
max: 15.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
stat: {
|
||||
stat: {
|
||||
ref: "Adds # to # Lightning Damage",
|
||||
better: 1,
|
||||
matchers: [
|
||||
{
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
],
|
||||
trade: {
|
||||
ids: {
|
||||
explicit: ["explicit.stat_3336890334"],
|
||||
fractured: ["fractured.stat_3336890334"],
|
||||
enchant: ["enchant.stat_3336890334"],
|
||||
rune: ["rune.stat_3336890334"],
|
||||
desecrated: ["desecrated.stat_3336890334"],
|
||||
crafted: ["crafted.stat_3336890334"],
|
||||
},
|
||||
},
|
||||
id: "local_minimum_added_lightning_damage",
|
||||
},
|
||||
translation: {
|
||||
string: "Adds # to # Lightning Damage",
|
||||
},
|
||||
roll: {
|
||||
unscalable: false,
|
||||
dp: false,
|
||||
value: 15.5,
|
||||
min: 15.5,
|
||||
max: 15.5,
|
||||
},
|
||||
},
|
||||
contributes: {
|
||||
value: 15.5,
|
||||
min: 15.5,
|
||||
max: 15.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] as unknown as StatCalculated[];
|
||||
const result = __testExports.determineAugments(mod, statCalcs);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].refName).toEqual("Greater Storm Rune");
|
||||
});
|
||||
});
|
||||
|
||||
describe("BFS", () => {
|
||||
@@ -73,6 +227,18 @@ describe("BFS", () => {
|
||||
expect(result).toEqual(expected);
|
||||
},
|
||||
);
|
||||
|
||||
it("should not infinite loop", () => {
|
||||
const result = __testExports.modifiedBfs(100, [], Array(100).fill(0));
|
||||
|
||||
expect(result).toHaveLength(0);
|
||||
}, 50);
|
||||
|
||||
it("should not infinite loop2", () => {
|
||||
const result = __testExports.modifiedBfs(15.5, [], Array(4).fill(1));
|
||||
|
||||
expect(result).toHaveLength(0);
|
||||
}, 50);
|
||||
});
|
||||
|
||||
describe("parseAugmentSockets", () => {
|
||||
|
||||
@@ -44,7 +44,7 @@ import { calcPropPercentile, QUALITY_STATS } from "./calc-q20";
|
||||
import { AppConfig } from "@/web/Config";
|
||||
import { buildEditorItems, getSavedAugments } from "./augment-builder";
|
||||
import { useAugment } from "@/web/price-check/item-editor/augment";
|
||||
import { combinations } from "./utils";
|
||||
import { avg, combinations } from "./utils";
|
||||
|
||||
type SectionParseResult =
|
||||
| "SECTION_PARSED"
|
||||
@@ -2116,6 +2116,7 @@ function modifiedBfs(
|
||||
available: number[],
|
||||
): number[] | null {
|
||||
if (remaining === 0) return [...combo];
|
||||
if (combo.length >= 7 || available.length > 8) return [];
|
||||
|
||||
let best: number[] | null = null;
|
||||
for (const augValue of available) {
|
||||
@@ -2209,7 +2210,7 @@ function determineAugments(
|
||||
if (augment.values.length === 1) return augment.values[0];
|
||||
|
||||
// stats like "# to # added Lightning Damage"
|
||||
if ((augment.baseStat.match(/#/) || []).length > 1) {
|
||||
if ((augment.baseStat.match(/#/g) || []).length > 1) {
|
||||
const sum = augment.values.reduce((a, b) => a + b, 0);
|
||||
return sum / augment.values.length || 0;
|
||||
}
|
||||
@@ -2224,8 +2225,9 @@ function determineAugments(
|
||||
modifiedBfs(augmentAppliedValue[0], [], availableAugmentValues) ?? [];
|
||||
|
||||
return likelyValues.map((v) => {
|
||||
const augment = possibleAugments.find((aug) =>
|
||||
aug.values.some((augVal) => augVal === v),
|
||||
const augment = possibleAugments.find(
|
||||
(aug) =>
|
||||
aug.values.some((augVal) => augVal === v) || avg(aug.values) === v,
|
||||
)!;
|
||||
return ITEM_BY_REF("ITEM", augment.refName)![0];
|
||||
});
|
||||
|
||||
@@ -4,3 +4,7 @@ export function combinations<T>(arr: T[]): T[][] {
|
||||
[[]],
|
||||
);
|
||||
}
|
||||
|
||||
export function avg(arr: number[]): number {
|
||||
return arr.reduce((a, b) => a + b, 0) / arr.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user