update: talent, state props

This commit is contained in:
Vick Scarlet
2026-08-02 17:36:04 +08:00
parent f60e279f62
commit b4177d7657
12 changed files with 534 additions and 192 deletions
+21 -27
View File
@@ -1,23 +1,10 @@
import type { EventEffect, Event } from '@remake/data/event'
import type { Event } from '@remake/data/event'
import events from '@remake/data/event'
import type { Properties, Effect } from '@/state'
import type { Properties } from '@/state'
import type { GameState, ProfileState } from '@/state'
import { stateEffect, createFlatState } from '@/state'
import { propsEffect, createFlatState } from '@/state'
import { check } from '@remake/condition'
export function convertEffect(effect: EventEffect): Effect {
const converted = {} as Effect
const properties = [] as [keyof Properties, number][]
if (effect.CHR) properties.push(['charm', effect.CHR])
if (effect.INT) properties.push(['intelligence', effect.INT])
if (effect.STR) properties.push(['strength', effect.STR])
if (effect.MNY) properties.push(['money', effect.MNY])
if (effect.SPR) properties.push(['spirit', effect.SPR])
if (properties.length > 0)
converted.properties = Object.fromEntries(properties)
if (effect.LIF) converted.life = effect.LIF
return converted
}
import { produce } from 'immer'
export interface TriggerResult {
state: GameState
@@ -29,17 +16,24 @@ export function trigger(
state: GameState,
profile: ProfileState,
): TriggerResult {
const event = events.get(eventId)
if (!event)
throw new Error(`[@remake/core][event] id:${eventId} not found.`)
const effect = event.effect ? convertEffect(event.effect) : {}
effect.events = [eventId]
const newState = stateEffect(state, effect)
const { effect, branch } = events.get(eventId)!
const newState = produce(state, draft => {
draft.events.add(eventId)
if (!effect) return
if (effect.LIF) draft.life += effect.LIF
const pe = {} as Partial<Properties>
if (effect.CHR) pe.charm = effect.CHR
if (effect.INT) pe.intelligence = effect.INT
if (effect.STR) pe.strength = effect.STR
if (effect.MNY) pe.money = effect.MNY
if (effect.SPR) pe.spirit = effect.SPR
draft.props = propsEffect(draft.props, pe)
})
const flatState = createFlatState(newState, profile)
if (event.branch) {
for (const branch of event.branch) {
if (check(flatState, branch.condition)) {
const result = trigger(branch.event, newState, profile)
if (branch) {
for (const { condition, event } of branch) {
if (check(flatState, condition)) {
const result = trigger(event, newState, profile)
return {
state: result.state,
events: [eventId, ...result.events],