mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-28 01:06:49 +08:00
update: achievement
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { useCallback } from 'react'
|
||||
import { events, talents, achievements } from '@remake/data'
|
||||
import { useProfile, useSetStep, Step } from '.'
|
||||
|
||||
const TotalEvents = events.size
|
||||
const TotalTalents = talents.size
|
||||
|
||||
export const useAchv = () => {
|
||||
const [profile] = useProfile()
|
||||
const o = new Map(Array.from(profile.achievements, (id, i) => [id, i]))
|
||||
const sorted = Array.from(achievements.keys())
|
||||
.sort((a, b) => {
|
||||
if (o.has(a) && o.has(b)) return o.get(b)! - o.get(a)!
|
||||
if (o.has(a)) return -1
|
||||
if (o.has(b)) return 1
|
||||
const { hide: ha, grade: ga } = achievements.get(a)!
|
||||
const { hide: hb, grade: gb } = achievements.get(b)!
|
||||
if (ha == hb) return gb - ga
|
||||
return ha ? 1 : -1
|
||||
})
|
||||
.map(id => ({ id, colled: o.has(id) }))
|
||||
const stats = {
|
||||
times: profile.times,
|
||||
achv: profile.achievements.size,
|
||||
event: (profile.events.size / TotalEvents) * 100,
|
||||
talent: (profile.talents.size / TotalTalents) * 100,
|
||||
}
|
||||
return [stats, sorted] as const
|
||||
}
|
||||
|
||||
export const useGoAchv = () => {
|
||||
const setStep = useSetStep()
|
||||
return useCallback(() => setStep(Step.Achv), [setStep])
|
||||
}
|
||||
@@ -42,12 +42,11 @@ export const usePoints = () => {
|
||||
const isClassic = useIsClassic()
|
||||
const { additionalPoints } = useReplaced()
|
||||
const additional = additionalPoints.points
|
||||
if (!isClassic) {
|
||||
const base = useAtomValue(baseAllocAtom)
|
||||
return { base: alloced(base), total: additional, additional }
|
||||
}
|
||||
const ba = useAtomValue(baseAllocAtom)
|
||||
const { points } = useConfig()
|
||||
return { base: points, total: points + additional, additional }
|
||||
const base = isClassic ? points : alloced(ba)
|
||||
const total = isClassic ? points + additional : additional
|
||||
return { base, total, additional }
|
||||
}
|
||||
|
||||
export const useLeftPoints = () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
|
||||
import { pickedAtom, replacedAtom, baseAllocAtom } from '.'
|
||||
import { useConfig, useProfile, useSetStep, Step } from '.'
|
||||
import { useConfig, useSetStep, Step } from '.'
|
||||
import { uniqueGenerate, startUnique, startChara } from '@remake/core'
|
||||
import { pullChara, pick } from '@remake/core'
|
||||
import type { BaseChara, PullCharaTms } from '@remake/core'
|
||||
@@ -72,7 +72,6 @@ export const useCharaPicker = () => {
|
||||
}
|
||||
|
||||
export const useCharaSubmit = () => {
|
||||
const [profile] = useProfile()
|
||||
const unique = useAtomValue(uniqueAtom)
|
||||
const setStep = useSetStep()
|
||||
const setPicked = useSetAtom(pickedAtom)
|
||||
@@ -93,7 +92,7 @@ export const useCharaSubmit = () => {
|
||||
setBaseAlloc(result.allocation)
|
||||
setStep(Step.Alloc)
|
||||
},
|
||||
[profile, unique, setPicked, setReplaced, setStep],
|
||||
[unique, setPicked, setReplaced, setBaseAlloc, setStep],
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ export * from './talent'
|
||||
export * from './play'
|
||||
export * from './alloc'
|
||||
export * from './character'
|
||||
export * from './achievement'
|
||||
export type * from '@remake/core'
|
||||
|
||||
@@ -14,6 +14,7 @@ export enum Step {
|
||||
Alloc = 'alloc',
|
||||
Play = 'play',
|
||||
Summary = 'summary',
|
||||
Achv = 'achv',
|
||||
}
|
||||
|
||||
export enum Mode {
|
||||
@@ -168,7 +169,7 @@ export const useEnd = () => {
|
||||
return next
|
||||
})
|
||||
},
|
||||
[lock, setLocked],
|
||||
[lock, isClassic, setLocked],
|
||||
)
|
||||
const ender = useCallback(() => {
|
||||
if (!state)
|
||||
@@ -183,6 +184,11 @@ export const useEnd = () => {
|
||||
setProfile(result.profile)
|
||||
reset()
|
||||
return result.achievements
|
||||
}, [state, profile, locked, setStep, setProfile, reset])
|
||||
}, [state, profile, locked, isClassic, setStep, setProfile, reset])
|
||||
return [locked, picker, ender] as const
|
||||
}
|
||||
|
||||
export const useGoHome = () => {
|
||||
const setStep = useSetAtom(stepAtom)
|
||||
return useCallback(() => setStep(Step.Idle), [setStep])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user