Skip to content

Commit

Permalink
dynamic lightcone stats in solver
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc committed Nov 9, 2024
1 parent ea29eed commit 68cdb54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
9 changes: 9 additions & 0 deletions libs/pando/engine/src/node/optimization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ function dedupMapArray<I, O>(x: I[], map: (_: I) => O): O[] {
return x.every((x, i) => (x as any) === newX[i]) ? (x as any) : newX
}

/**
* Generates a custom function, "cuz speed".
* NOTE: `slotCount` should be `n.length` for optimization reaons. the size of `n` should not change when fed into the resulting custom function.
* @param n
* @param dynTagCategory
* @param slotCount
* @param initial
* @param header
*/
export function compile(
n: NumTagFree[],
dynTagCategory: string,
Expand Down
2 changes: 1 addition & 1 deletion libs/sr/solver/src/childWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function init({
compiledCalcFunction = compile(
combinedNodes,
'q', // Tag category for object key
6, // Number of slots
7, // Number of slots
{} // Initial values
// Header; includes custom formulas, such as `res`
)
Expand Down
14 changes: 3 additions & 11 deletions libs/sr/solver/src/parentWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import {
type RelicSlotKey,
} from '@genshin-optimizer/sr/consts'
import type { ICachedLightCone, ICachedRelic } from '@genshin-optimizer/sr/db'
import {
lightConeData,
own,
srCalculatorWithEntries,
} from '@genshin-optimizer/sr/formula'
import { getRelicMainStatVal } from '@genshin-optimizer/sr/util'
import type { ChildCommandInit, ChildMessage } from './childWorker'
import { MAX_BUILDS } from './common'
Expand Down Expand Up @@ -230,15 +225,12 @@ function convertRelicToStats(relic: ICachedRelic): RelicStats {
}

function convertLightConeToStats(lightCone: ICachedLightCone): LightConeStats {
const calc = srCalculatorWithEntries(lightConeData(lightCone))

return {
id: lightCone.id,
stats: {
...objKeyMap(
['hp', 'atk', 'def'] as const,
(stat) => calc.compute(own.base[stat].with('sheet', 'lightCone')).val
),
lvl: lightCone.level,
superimpose: lightCone.superimpose,
ascension: lightCone.ascension,
[lightCone.key]: 1,
},
}
Expand Down
11 changes: 10 additions & 1 deletion libs/sr/solver/src/solver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { detach, sum } from '@genshin-optimizer/pando/engine'
import type { CharacterKey, RelicSlotKey } from '@genshin-optimizer/sr/consts'
import { allRelicSetKeys } from '@genshin-optimizer/sr/consts'
import { allLightConeKeys, allRelicSetKeys } from '@genshin-optimizer/sr/consts'
import type {
ICachedLightCone,
ICachedRelic,
Expand Down Expand Up @@ -128,6 +128,7 @@ export class Solver {
private detachNodes() {
// Step 2: Detach nodes from Calculator
const relicSetKeys = new Set(allRelicSetKeys)
const lightConeKeys = new Set(allLightConeKeys)
const detachedNodes = detach(
[
// team
Expand All @@ -148,6 +149,14 @@ export class Solver {
return { q: tag['q']! } // Relic stat bonus
if (tag['q'] === 'count' && relicSetKeys.has(tag['sheet'] as any))
return { q: tag['sheet']! } // Relic set counter
if (
tag['qt'] == 'lightCone' &&
['lvl', 'ascension', 'superimpose'].includes(tag['q'] as string)
)
return { q: tag['q']! } // Light cone bonus
if (tag['q'] === 'count' && lightConeKeys.has(tag['sheet'] as any))
return { q: tag['sheet']! } // Relic set counter

return undefined
}
)
Expand Down

0 comments on commit 68cdb54

Please sign in to comment.