update: character

This commit is contained in:
Vick Scarlet
2026-08-16 20:06:16 +08:00
committed by 神戸小鳥
parent ad4e83fc47
commit f4204601ee
22 changed files with 495 additions and 101 deletions
+5 -6
View File
@@ -1,5 +1,5 @@
import { expect, test, describe } from 'bun:test'
import { pullCharacter, uniqueGenerate } from './character'
import { pullChara, uniqueGenerate } from './character'
import { enableMapSet } from 'immer'
enableMapSet()
@@ -7,7 +7,7 @@ describe('Character', () => {
const sum = (map: Map<any, number>) =>
Array.from(map.values()).reduce((acc, val) => acc + val, 0)
test('pull', () => {
let result = pullCharacter(
let result = pullChara(
{ count: 10, knife: 10 },
{ times: 0, drawns: new Map() },
)
@@ -15,17 +15,17 @@ describe('Character', () => {
expect(result.characters.length).toBe(10)
expect(result.times.times).toBe(10)
expect(result.times.drawns.size).toBe(10)
result = pullCharacter({ count: 3, knife: 10 }, result.times)
result = pullChara({ count: 3, knife: 10 }, result.times)
expect(result.characters).not.toContainValue(null)
expect(result.characters.length).toBe(3)
expect(result.times.times).toBe(13)
expect(sum(result.times.drawns)).toBe(13)
result = pullCharacter({ count: 3, knife: 10 }, result.times)
result = pullChara({ count: 3, knife: 10 }, result.times)
expect(result.characters).not.toContainValue(null)
expect(result.characters.length).toBe(3)
expect(result.times.times).toBe(16)
expect(sum(result.times.drawns)).toBe(16)
result = pullCharacter({ count: 20, knife: 1 }, result.times)
result = pullChara({ count: 20, knife: 1 }, result.times)
expect(result.characters).not.toContainValue(null)
expect(result.characters.length).toBe(20)
expect(result.times.times).toBe(36)
@@ -56,6 +56,5 @@ describe('Character', () => {
expect(unique.property.STR).toBeLessThanOrEqual(10)
expect(unique.property.MNY).toBeLessThanOrEqual(10)
expect(unique.talent.length).toBeLessThanOrEqual(5)
console.debug(unique)
})
})
+39 -5
View File
@@ -1,7 +1,10 @@
import { type Character, type Talent, characters, talents } from '@remake/data'
import type { Character, CharacterProperty, Talent } from '@remake/data'
import { characters, talents } from '@remake/data'
import { type RNG, type WeightItem, pick, pickWeight } from '@remake/vitex'
import type { Allocation } from './state'
export type UniqueChara = Omit<Character, 'id' | 'name'>
export type BaseChara = Omit<Character, 'id' | 'name'>
export type BaseAlloc = Omit<Allocation, 'spirit'>
export interface UniqueGenCfg {
prop: WeightItem<number>[]
talent: WeightItem<number>[]
@@ -22,7 +25,7 @@ export function uniqueGenerate(config: UniqueGenCfg, rng?: RNG) {
picked.add(t)
count--
}
return { property, talent: Array.from(picked) } satisfies UniqueChara
return { property, talent: Array.from(picked) } satisfies BaseChara
}
export interface PullCharaOpt {
@@ -37,9 +40,9 @@ export interface PullCharaRet {
characters: Character['id'][]
times: PullCharaTms
}
export function pullCharacter(
export function pullChara(
opt: PullCharaOpt,
tms: PullCharaTms,
tms: PullCharaTms = { times: 0, drawns: new Map() },
rng?: RNG,
): PullCharaRet {
const { count, knife } = opt
@@ -69,3 +72,34 @@ function deriveWeightMap(
Array.from(characters.keys(), id => [id, base - (drawns.get(id) ?? 0)]),
)
}
export function charaPropToBaseAlloc(props: CharacterProperty): BaseAlloc {
return {
charm: props.CHR,
intelligence: props.INT,
strength: props.STR,
money: props.MNY,
}
}
function charaPropToAlloc(
props: CharacterProperty,
spirit: number,
): Allocation {
return { ...charaPropToBaseAlloc(props), spirit }
}
function convert(chara: BaseChara, spirit: number) {
return {
allocation: charaPropToAlloc(chara.property, spirit),
talents: chara.talent,
}
}
export function startChara(id: Character['id'], spirit: number) {
return convert(characters.get(id)!, spirit)
}
export function startUnique(chara: BaseChara, spirit: number) {
return convert(chara, spirit)
}
+3 -2
View File
@@ -1,10 +1,11 @@
export type { RNG } from '@remake/vitex'
export type { GameState, ProfileState, Properties, Allocation } from './state'
export type { PullOptions, ReplacementResult } from './talent'
export type { AdditionalPoint, AdditionalPoints } from './talent'
export type { PullCharaOpt, PullCharaTms, PullCharaRet } from './character'
export type { UniqueChara, UniqueGenCfg } from './character'
export type { BaseChara, UniqueGenCfg } from './character'
export type { PickResult, StartResult } from './game'
export type { NextResult, SummaryResult, EndResult } from './game'
export { pull, exclude } from './talent'
export { uniqueGenerate, pullChara, charaPropToBaseAlloc } from './character'
export { startUnique, startChara } from './character'
export { pick, start, next, summary, end } from './game'