Skip to content

Commit

Permalink
2p effect
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc committed Jan 14, 2025
1 parent 24467c1 commit b634f15
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 24 deletions.
3 changes: 3 additions & 0 deletions libs/common/util/src/lib/numDisplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export type Unit = '' | '%' | 's'
/**
* Print out a number in percent with fixed decimal places
*/
export function valueString(
value: number,
unit: Unit = '',
Expand Down
1 change: 1 addition & 0 deletions libs/zzz/consts/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { allDiscMainStatKeys, allDiscSubStatKeys } from './disc'
export const otherStatKeys = [
'impact', // flat impact on character
'anomMas', // flat Anomally Mastery on character
'shield_', // Shield Effect
] as const

export const allStatKeys = Array.from(
Expand Down
29 changes: 28 additions & 1 deletion libs/zzz/consts/src/disc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { StatKey } from './common'

export const allDiscSlotKeys = ['1', '2', '3', '4', '5', '6'] as const
export type DiscSlotKey = (typeof allDiscSlotKeys)[number]

Expand Down Expand Up @@ -97,7 +99,7 @@ export const allDiscMainSubStatKeys = Array.from(
export type DiscMainSubStatKey = (typeof allDiscMainSubStatKeys)[number]

// TODO: use dm values
const subData = {
const _subData = {
hp: { B: 39, A: 79, S: 112 },
atk: { B: 7, A: 15, S: 19 },
def: { B: 5, A: 10, S: 15 },
Expand Down Expand Up @@ -142,3 +144,28 @@ export function getDiscMainStatVal(
): number {
return (mainData as any)[mainStatKey][rarity] ?? 0
}

/**
* TODO: use dm pipeline
*/
export const disc2pEffect: Record<
DiscSetKey,
Partial<Record<StatKey, number>>
> = {
AstralVoice: { atk: 0.1 },
BranchBladeSong: { crit_dmg_: 0.16 },
ChaosJazz: { anomProf: 30 },
ChaoticMetal: { ether_dmg_: 10 },
FangedMetal: { physical_dmg_: 0.1 },
FreedomBlues: { anomProf: 30 },
HormonePunk: { atk: 0.1 },
InfernoMetal: { fire_dmg_: 0.1 },
PolarMetal: { ice_dmg_: 0.1 },
ProtoPunk: { shield_: 0.15 },
PufferElectro: { pen_: 0.08 },
ShockstarDisco: { impact_: 0.06 },
SoulRock: { def_: 0.16 },
SwingJazz: { enerRegen_: 0.2 },
ThunderMetal: { electric_dmg_: 0.1 },
WoodpeckerElectro: { crit_: 0.08 },
}
30 changes: 30 additions & 0 deletions libs/zzz/db/src/Database/DataEntry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DBLocalStorage } from '@genshin-optimizer/common/database'
import { ZzzDatabase } from './Database'

const dbStorage = new DBLocalStorage(localStorage, 'sro')
const dbIndex = 1
let database = new ZzzDatabase(dbIndex, dbStorage)

describe('Database', () => {
beforeEach(() => {
dbStorage.clear()
database = new ZzzDatabase(dbIndex, dbStorage)
})
test('initialValue', () => {
expect(database.dbMeta.get().lastEdit).toEqual(0)
})
test('DataEntry.set', () => {
expect(database.dbMeta.get().name).toEqual('Database 1')

database.dbMeta.set({ name: 'test' })
expect(database.dbMeta.get().name).toEqual('test')

database.dbMeta.set((dbMeta) => {
dbMeta.name = `test ${dbMeta.name}`
})
expect(database.dbMeta.get().name).toEqual('test test')

database.dbMeta.set(({ name }) => ({ name: `test ${name}` }))
expect(database.dbMeta.get().name).toEqual('test test test')
})
})
15 changes: 10 additions & 5 deletions libs/zzz/page-optimize/src/BuildsDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { CardThemed } from '@genshin-optimizer/common/ui'
import { getUnitStr, notEmpty, toPercent } from '@genshin-optimizer/common/util'
import {
getUnitStr,
notEmpty,
objMap,
toDecimal,
valueString,
} from '@genshin-optimizer/common/util'
import { useDatabaseContext, useDisc } from '@genshin-optimizer/zzz/db-ui'
import type { BaseStats, BuildResult } from '@genshin-optimizer/zzz/solver'
import { convertDiscToStats, getSum } from '@genshin-optimizer/zzz/solver'
Expand Down Expand Up @@ -27,7 +33,7 @@ function Build({
const { database } = useDatabaseContext()
const sum = useMemo(() => {
const sum = getSum(
baseStats,
objMap(baseStats, (v, k) => toDecimal(v, k)),
Object.values(build.discIds)
.map((d) => database.discs.get(d))
.filter(notEmpty)
Expand All @@ -39,9 +45,8 @@ function Build({
<CardThemed>
<CardContent>
{Object.entries(sum).map(([k, v]) => (
<Typography>
{k}: {toPercent(v, k)}
{getUnitStr(k)}
<Typography key={k}>
{k}: {valueString(v, getUnitStr(k))}
</Typography>
))}
<Box display="flex" gap={1}>
Expand Down
5 changes: 3 additions & 2 deletions libs/zzz/page-optimize/src/StatFilterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
NumberInputLazy,
} from '@genshin-optimizer/common/ui'
import { getUnitStr } from '@genshin-optimizer/common/util'
import { allAttributeDamageKeys, StatKey } from '@genshin-optimizer/zzz/consts'
import { Constraints } from '@genshin-optimizer/zzz/solver'
import type { StatKey } from '@genshin-optimizer/zzz/consts'
import { allAttributeDamageKeys } from '@genshin-optimizer/zzz/consts'
import type { Constraints } from '@genshin-optimizer/zzz/solver'
import DeleteForeverIcon from '@mui/icons-material/DeleteForever'
import {
Box,
Expand Down
7 changes: 7 additions & 0 deletions libs/zzz/solver/src/calc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DiscSetKey } from '@genshin-optimizer/zzz/consts'
import { disc2pEffect } from '@genshin-optimizer/zzz/consts'
import type { BaseStats, DiscStats } from './common'

export function getSum(baseStats: BaseStats, discs: DiscStats[]) {
Expand All @@ -7,6 +9,11 @@ export function getSum(baseStats: BaseStats, discs: DiscStats[]) {
sum[key] = (sum[key] || 0) + d.stats[key]
}
}
for (const [key, value] of Object.entries(sum)) {
if (value > 2 && disc2pEffect[key as DiscSetKey])
for (const [k, v] of Object.entries(disc2pEffect[key as DiscSetKey]))
sum[k] = (sum[k] || 0) + v
}
// Rudimentary Calculations
sum['hp'] = (sum['hp_base'] || 0) * (1 + (sum['hp_'] || 0)) + (sum['hp'] || 0)
sum['atk'] = (sum['atk_base'] || 0) * (1 + (sum['atk_'] || 0))
Expand Down
3 changes: 1 addition & 2 deletions libs/zzz/ui/src/Disc/DiscEditor/SubstatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function SubstatInput({
setSubstat: (index: number, substat?: ISubstat) => void
}) {
const { t } = useTranslation('disc')
const { mainStatKey = '', rarity = 5 } = disc ?? {}
const { mainStatKey = '' } = disc ?? {}
const { key = '', value = 0, rolls = 0 } = disc?.substats[index] ?? {}
// const accurateValue = rolls.reduce((a, b) => a + b, 0)
const rollNum = rolls
Expand All @@ -57,7 +57,6 @@ export default function SubstatInput({
allowedRolls = maxRollNum - rollNum
rollData = 0 //key ? getSubstatValuesPercent(key, rarity) : []
}
const rollOffset = 7 - rollData

// if (!rollNum && key && value) error = error || t('editor.substat.error.noCalc')
if (allowedRolls < 0)
Expand Down
28 changes: 14 additions & 14 deletions libs/zzz/ui/src/Settings/UploadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { CardThemed } from '@genshin-optimizer/common/ui'
import type {
ImportResult,
ImportResultCounter,
} from '@genshin-optimizer/sr/db'
import { SroDatabase } from '@genshin-optimizer/sr/db'
} from '@genshin-optimizer/zzz/db'
import { ZzzDatabase } from '@genshin-optimizer/zzz/db'
import { useDatabaseContext } from '@genshin-optimizer/zzz/db-ui'
import { CheckBox, CheckBoxOutlineBlank, FileOpen } from '@mui/icons-material'
import ArrowBackIcon from '@mui/icons-material/ArrowBack'
Expand Down Expand Up @@ -60,11 +60,11 @@ export function UploadCard({
// Parse as SROD format
const copyStorage = new SandboxStorage(undefined, 'sro')
copyStorage.copyFrom(database.storage)
const importedDatabase = new SroDatabase(
const importedDatabase = new ZzzDatabase(
(index + 1) as 1 | 2 | 3 | 4,
copyStorage
)
const importResult = importedDatabase.importSROD(
const importResult = importedDatabase.importZOD(
parsed,
keepNotInImport,
ignoreDups
Expand Down Expand Up @@ -210,7 +210,7 @@ export function UploadCard({
onChange={(e) => setData(e.target.value)}
/>
{importResult && importedDatabase ? (
<SRODUploadInfo
<ZODUploadInfo
importResult={importResult}
importedDatabase={importedDatabase}
/>
Expand All @@ -227,12 +227,12 @@ export function UploadCard({
)
}

function SRODUploadInfo({
importResult: { source, relics, characters, lightCones },
function ZODUploadInfo({
importResult: { source, discs },
importedDatabase,
}: {
importResult: ImportResult
importedDatabase: SroDatabase
importedDatabase: ZzzDatabase
}) {
const { t } = useTranslation('page_settings')
return (
Expand All @@ -249,12 +249,12 @@ function SRODUploadInfo({
<Grid container item spacing={2}>
<Grid item flexGrow={1}>
<MergeResult
result={relics}
dbTotal={importedDatabase.relics.values.length}
type="relics"
result={discs}
dbTotal={importedDatabase.discs.values.length}
type="discs"
/>
</Grid>
<Grid item flexGrow={1}>
{/* <Grid item flexGrow={1}>
<MergeResult
result={lightCones}
dbTotal={importedDatabase.lightCones.values.length}
Expand All @@ -267,7 +267,7 @@ function SRODUploadInfo({
dbTotal={importedDatabase.chars.values.length}
type="chars"
/>
</Grid>
</Grid> */}
</Grid>
</Grid>
</CardContent>
Expand Down Expand Up @@ -359,7 +359,7 @@ function SROUploadAction({
reset,
}: {
index: number
importedDatabase?: SroDatabase
importedDatabase?: ZzzDatabase
reset: () => void
}) {
const { databases, setDatabase } = useDatabaseContext()
Expand Down

0 comments on commit b634f15

Please sign in to comment.