Skip to content

Commit

Permalink
feat: improved fetch of newbie gacha pool
Browse files Browse the repository at this point in the history
  • Loading branch information
lgou2w committed Jan 27, 2024
1 parent 18201e3 commit 0be041f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/components/gacha/toolbar/GachaActionFetch.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import { useImmer } from 'use-immer'
import { resolveCurrency } from '@/interfaces/account'
import { AccountFacet, resolveCurrency } from '@/interfaces/account'
import { useUpdateAccountGachaUrlFn, useUpdateAccountPropertiesFn } from '@/hooks/useStatefulAccount'
import { GachaRecords, useRefetchGachaRecordsFn } from '@/hooks/useGachaRecordsQuery'
import { GachaRecords, NamedGachaRecords, useRefetchGachaRecordsFn } from '@/hooks/useGachaRecordsQuery'
import { useGachaLayoutContext } from '@/components/gacha/GachaLayoutContext'
import useGachaRecordsFetcher from '@/hooks/useGachaRecordsFetcher'
import Box from '@mui/material/Box'
Expand Down Expand Up @@ -36,13 +36,14 @@ export default function GachaActionFetch () {
const { facet, uid, gachaUrl } = selectedAccount
try {
const { namedValues: { character, weapon, permanent, newbie } } = gachaRecords
const pullNewbie = shouldPullNewbie(facet, newbie)
await pull(facet, uid, {
gachaUrl,
gachaTypeAndLastEndIdMappings: {
[character.gachaType]: character.lastEndId ?? null,
[weapon.gachaType]: weapon.lastEndId ?? null,
[permanent.gachaType]: permanent.lastEndId ?? null,
[newbie.gachaType]: newbie.lastEndId ?? null
...(pullNewbie || {})
},
eventChannel: 'gachaRecords-fetcher-event-channel',
saveToStorage: true
Expand Down Expand Up @@ -131,3 +132,21 @@ function stringifyFragment (
return `Unknown fragment: ${JSON.stringify(fragment)}`
}
}

function shouldPullNewbie (
facet: AccountFacet,
newbie: NamedGachaRecords
): Record<string, string | null> | null {
// HACK:
// Genshin Impact : Newbie Gacha Pool = 20 times
// Honkai: Star Rail : = 50 times
if (facet === AccountFacet.Genshin && newbie.total >= 20) {
return null
} else if (facet === AccountFacet.StarRail && newbie.total >= 50) {
return null
} else {
return {
[newbie.gachaType]: newbie.lastEndId ?? null
}
}
}

0 comments on commit 0be041f

Please sign in to comment.