From 25bd9ce2b78a4a9cf441eb7dabf7ff33688daca3 Mon Sep 17 00:00:00 2001 From: Vick Scarlet Date: Tue, 11 Aug 2026 14:12:17 +0800 Subject: [PATCH] feature: spirit allocation --- apps/web/src/config.ts | 1 + packages/core/src/state.ts | 4 ++-- packages/hooks/src/alloc.ts | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/web/src/config.ts b/apps/web/src/config.ts index 1ec358b..33efc52 100644 --- a/apps/web/src/config.ts +++ b/apps/web/src/config.ts @@ -31,6 +31,7 @@ export const config: Config = { pick: 3, points: BasePoints, allocate: 10, + spirit: 5, pull: { count: 10, rate: { diff --git a/packages/core/src/state.ts b/packages/core/src/state.ts index c9962e4..ad314e8 100644 --- a/packages/core/src/state.ts +++ b/packages/core/src/state.ts @@ -18,9 +18,9 @@ export interface HLProperties { lowest: Properties // 历史最低属性 } -export type Allocation = Omit +export type Allocation = Omit export function createProperties(allocation: Allocation) { - return { ...allocation, age: -1, spirit: 0 } + return { ...allocation, age: -1 } } export function createHLProperties(allocation: Allocation) { diff --git a/packages/hooks/src/alloc.ts b/packages/hooks/src/alloc.ts index 6476a4f..f4b45c4 100644 --- a/packages/hooks/src/alloc.ts +++ b/packages/hooks/src/alloc.ts @@ -6,12 +6,23 @@ import type { Allocation } from '@remake/core' import type { RNG } from '@remake/vitex' import { keys, shuffle, random as frandom } from '@remake/vitex' -const init: Allocation = { charm: 0, intelligence: 0, strength: 0, money: 0 } -const allocAtom = atom(init) +export type UserAllocation = Omit +const init: UserAllocation = { + charm: 0, + intelligence: 0, + strength: 0, + money: 0, +} +const allocAtom = atom({ ...init }) -const alloced = (alloc: Allocation) => +const alloced = (alloc: UserAllocation) => Object.values(alloc).reduce((a, b) => a + b, 0) +export const useAllocReset = () => { + const setAlloc = useSetAtom(allocAtom) + return useCallback(() => setAlloc({ ...init }), [setAlloc]) +} +export const useAlloc = () => useAtomValue(allocAtom) export const usePoints = () => { const { points } = useConfig() const { additionalPoints } = useReplaced() @@ -29,7 +40,7 @@ export const useAllocator = () => { const total = usePoints() const [alloc, setAlloc] = useAtom(allocAtom) const allocator = useCallback( - (key: keyof Allocation, value: number) => { + (key: keyof UserAllocation, value: number) => { setAlloc(prev => { const left = total - alloced(prev) + prev[key] const max = Math.min(left, allocate)