mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-08-29 10:04:43 +08:00
feature: spirit allocation
This commit is contained in:
@@ -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: {
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user