add: character

This commit is contained in:
Vick Scarlet
2026-08-14 00:57:02 +08:00
parent 9c8478c102
commit d0f7dbb464
18 changed files with 194 additions and 79 deletions
+2 -4
View File
@@ -1,10 +1,8 @@
import { useCallback } from 'react'
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
import { useConfig } from './config'
import { useReplaced } from './talent'
import { useConfig, useReplaced } from '.'
import type { Allocation } from '@remake/core'
import type { RNG } from '@remake/vitex'
import { keys, shuffle, random as frandom } from '@remake/vitex'
import { keys, shuffle, random as frandom, type RNG } from '@remake/vitex'
export type UserAllocation = Omit<Allocation, 'spirit'>
const init: UserAllocation = {
+5 -4
View File
@@ -1,7 +1,6 @@
import { useCallback } from 'react'
import { atom, useSetAtom, useAtomValue } from 'jotai'
import type { PullOptions } from '@remake/core'
import type { PullOptions, PullCharaOpt } from '@remake/core'
export interface Config {
/** 游戏锁定天赋数量 */
lock: number
@@ -9,8 +8,6 @@ export interface Config {
max: number
/** 游戏最少选择天赋数量 */
min: number
/** 天赋抽取个数 */
pull: PullOptions
/** 初始属性点 */
points: number
/** 单项属性点最大限制 */
@@ -19,6 +16,10 @@ export interface Config {
spirit: number
/** 模式选择限制 */
mode: number
/** 天赋抽取个数 */
pull: PullOptions
/** 名人模式配置 */
chara: PullCharaOpt
}
export const configAtom = atom<Config | null>(null)
+3 -5
View File
@@ -1,12 +1,10 @@
import { useCallback, useRef, useState } from 'react'
import { atom, useSetAtom, useAtomValue, useAtom } from 'jotai'
import { useConfig } from './config'
import { useProfile } from './profile'
import { useReplaced, useTalentReset } from './talent'
import { useAlloc, useAllocReset } from './alloc'
import { useConfig, useProfile, useReplaced, useAlloc } from '.'
import { useTalentReset, useAllocReset } from '.'
import { start, next, summary, end } from '@remake/core'
import type { GameState, Properties, NextResult } from '@remake/core'
import type { Talent } from '@remake/data/talent'
import type { Talent } from '@remake/data'
export enum Step {
Idle = 'idle',
+13 -24
View File
@@ -1,14 +1,12 @@
import { useState, useCallback } from 'react'
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
import { useConfig } from './config'
import { useProfile } from './profile'
import { useSetStep } from './play'
import { pull, exclude, talentsPicked } from '@remake/core'
import type { TalentsPickedResult, RNG } from '@remake/core'
import type { Talent } from '@remake/data/talent'
import { useConfig, useProfile, useSetStep } from '.'
import { pull, exclude, pick, type PickResult } from '@remake/core'
import type { Talent } from '@remake/data'
import type { RNG } from '@remake/vitex'
export const pickedAtom = atom(new Set<Talent['id']>())
export const replacedAtom = atom<TalentsPickedResult | null>(null)
export const replacedAtom = atom<PickResult | null>(null)
export const useTalentReset = () => {
const setPicked = useSetAtom(pickedAtom)
@@ -41,25 +39,16 @@ export const useTalentPuller = () => {
return [pulled, puller] as const
}
export type TalentPickerResult =
| {
type: 'ok'
talent?: never
}
| {
type: 'not-enough'
talent?: never
}
| {
type: 'exclude'
talent: Talent['id']
}
export type PickOk = { type: 'ok'; talent?: never }
export type PickNe = { type: 'ne'; talent?: never }
export type PickEx = { type: 'ex'; talent: Talent['id'] }
export type PickerResult = PickOk | PickNe | PickEx
export const useTalentPicker = () => {
const { max } = useConfig()
const [picked, setPicked] = useAtom(pickedAtom)
const picker = useCallback(
(talent: Talent['id']): TalentPickerResult => {
(talent: Talent['id']): PickerResult => {
if (!picked) {
setPicked(new Set([talent]))
return { type: 'ok' }
@@ -70,9 +59,9 @@ export const useTalentPicker = () => {
setPicked(next)
return { type: 'ok' }
}
if (picked.size >= max) return { type: 'not-enough' }
if (picked.size >= max) return { type: 'ne' }
const e = exclude(talent, picked)
if (e) return { type: 'exclude', talent: e }
if (e) return { type: 'ex', talent: e }
const next = new Set([...picked, talent])
setPicked(next)
return { type: 'ok' }
@@ -97,7 +86,7 @@ export const useTalentSubmit = () => {
return useCallback(
(rng?: RNG) => {
if (!enabled) throw new Error('Not enough talents picked')
setReplaced(talentsPicked(picked, rng))
setReplaced(pick(picked, rng))
setStep(Step.Alloc)
},
[enabled, picked, setReplaced, setStep],