Skip to content
Draft
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
40 changes: 19 additions & 21 deletions ui/packages/ui/src/Pages/Simulator/Components/Enka/EnkaToGOOD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,50 +129,48 @@ function extractArtifactSet(

function extractArtifactStats(
equipList: (GenshinItemWeapon | GenshinItemReliquary)[],
): number[] {
//TODO: using this here so we can in future return main + sub on sep lines
): [number, number][] {
// Define stats as a list of tuples
let stats: [number, number][] = [];

//track total
let total = stats_base.slice();
//we'll want to use labels for the other stuff (although doesn't do anything atm)
equipList.forEach((e) => {
if (e.flat.itemType != 'ITEM_RELIQUARY') {
return;
}

// Add Main Stat as a tuple (ms_idx, ms)
const ms = extractMainStat(e as GenshinItemReliquary);
//TODO: we really shouldn't be doing this so roundabout...
const ms_idx =
GOODStatToIndexMap[
fightPropToGOODKey(e.flat.reliquaryMainstat.mainPropId)
];
total[ms_idx] += ms;
//TODO: in future this should go into a diff slice
//add sub stats
stats.push([ms_idx, ms]);

// Add Sub Stats returned as tuples
const subs = extractSubStats(e as GenshinItemReliquary);
subs.forEach((v, i) => {
total[i] += v;
});
stats.push(...subs);
});
return total;
return stats;
}

function extractSubStats(e: GenshinItemReliquary): number[] {
let total = stats_base.slice();
function extractSubStats(e: GenshinItemReliquary): [number, number][] {
let subStats: [number, number][] = [];

for (const sub of e.flat.reliquarySubstats) {
const key = fightPropToGOODKey(sub.appendPropId);
if (!(key in GOODStatToIndexMap)) {
continue;
}
const idx = GOODStatToIndexMap[key];
let val = sub.statValue;
//this corrects for percentages
// Correct for percentages
if (key.includes('_')) {
val = val / 100.0;
}
total[idx] += val;
subStats.push([idx, val]);
}
console.log('substats extracted', total);
return total;
console.log('substats extracted', subStats);
return subStats;
}

function extractMainStat(e: GenshinItemReliquary): number {
Expand Down Expand Up @@ -227,7 +225,7 @@ export default function EnkaToGOOD(enkaData: EnkaData): {
return;
}

let stats: number[];
let stats: [number, number][];
try {
stats = extractArtifactStats(equipList);
} catch (e) {
Expand Down Expand Up @@ -259,7 +257,7 @@ export default function EnkaToGOOD(enkaData: EnkaData): {
characters.push(result);

console.log(
`succesfully imported ${result.name} (id: ${avatarId}, name: ${name})`,
`successfully imported ${result.name} (id: ${avatarId}, name: ${name})`,
);
},
);
Expand Down
68 changes: 40 additions & 28 deletions ui/packages/ui/src/Pages/Simulator/helper.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { Character } from "@gcsim/types";
import {Character} from '@gcsim/types';

const statKeys = [
"n/a",
"def%",
"def",
"hp",
"hp%",
"atk",
"atk%",
"er",
"em",
"cr",
"cd",
"heal",
"pyro%",
"hydro%",
"cryo%",
"electro%",
"anemo%",
"geo%",
"dendro%",
"phys%",
"atkspd%",
"dmg%",
'n/a',
'def%',
'def',
'hp',
'hp%',
'atk',
'atk%',
'er',
'em',
'cr',
'cd',
'heal',
'pyro%',
'hydro%',
'cryo%',
'electro%',
'anemo%',
'geo%',
'dendro%',
'phys%',
'atkspd%',
'dmg%',
];

export function charToCfg(char: Character): string {
let str = "";
let str = '';
// prettier-ignore
str += `${char.name} char lvl=${char.level}/${char.max_level} cons=${char.cons} talent=${char.talents.attack},${char.talents.skill},${char.talents.burst};\n`;
// prettier-ignore
Expand All @@ -42,12 +42,24 @@ export function charToCfg(char: Character): string {
//add stats
let count = 0;
let statStr = `${char.name} add stats`;
char.stats.forEach((v, i) => {
if (v === 0) return;
char.stats.forEach(([index, value], i) => {
if (value === 0) return;
count++;
statStr += ` ${statKeys[i]}=${v.toPrecision()}`;
statStr += ` ${statKeys[index]}=${value.toPrecision()}`;

// Add ";\n" after main stats, then "\n" after every artifact piece substats
if (i === 4) {
str += statStr + '; # main stats\n';
statStr = `${char.name} add stats`;
} else if ((count - 5) % 4 === 0 && i > 4) {
str += statStr + ';\n';
statStr = `${char.name} add stats`;
}
});
if (count > 0) {

// \n delimiting is under assumption that each artifact has 4 subs.
// If that's not the case, add to the end.
if (count > 0 && (count - 5) % 4 !== 0) {
str += statStr + `;\n`;
}

Expand Down