feature: spirit allocation

This commit is contained in:
Vick Scarlet
2026-08-11 14:12:17 +08:00
parent 88536c7934
commit 5d50a4ea37
3 changed files with 18 additions and 6 deletions
+1
View File
@@ -31,6 +31,7 @@ export const config: Config = {
pick: 3, pick: 3,
points: BasePoints, points: BasePoints,
allocate: 10, allocate: 10,
spirit: 5,
pull: { pull: {
count: 10, count: 10,
rate: { rate: {
+2 -2
View File
@@ -18,9 +18,9 @@ export interface HLProperties {
lowest: Properties // 历史最低属性 lowest: Properties // 历史最低属性
} }
export type Allocation = Omit<Properties, 'age' | 'spirit'> export type Allocation = Omit<Properties, 'age'>
export function createProperties(allocation: Allocation) { export function createProperties(allocation: Allocation) {
return { ...allocation, age: -1, spirit: 0 } return { ...allocation, age: -1 }
} }
export function createHLProperties(allocation: Allocation) { export function createHLProperties(allocation: Allocation) {
+15 -4
View File
@@ -6,12 +6,23 @@ import type { Allocation } from '@remake/core'
import type { RNG } from '@remake/vitex' import type { RNG } from '@remake/vitex'
import { keys, shuffle, random as frandom } from '@remake/vitex' import { keys, shuffle, random as frandom } from '@remake/vitex'
const init: Allocation = { charm: 0, intelligence: 0, strength: 0, money: 0 } export type UserAllocation = Omit<Allocation, 'spirit'>
const allocAtom = atom<Allocation>(init) const init: UserAllocation = {
charm: 0,
intelligence: 0,
strength: 0,
money: 0,
}
const allocAtom = atom<UserAllocation>({ ...init })
const alloced = (alloc: Allocation) => const alloced = (alloc: UserAllocation) =>
Object.values(alloc).reduce((a, b) => a + b, 0) 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 = () => { export const usePoints = () => {
const { points } = useConfig() const { points } = useConfig()
const { additionalPoints } = useReplaced() const { additionalPoints } = useReplaced()
@@ -29,7 +40,7 @@ export const useAllocator = () => {
const total = usePoints() const total = usePoints()
const [alloc, setAlloc] = useAtom(allocAtom) const [alloc, setAlloc] = useAtom(allocAtom)
const allocator = useCallback( const allocator = useCallback(
(key: keyof Allocation, value: number) => { (key: keyof UserAllocation, value: number) => {
setAlloc(prev => { setAlloc(prev => {
const left = total - alloced(prev) + prev[key] const left = total - alloced(prev) + prev[key]
const max = Math.min(left, allocate) const max = Math.min(left, allocate)