refactor(0.1.14-P1): 内核归位——game/ 按引擎架构重排(零行为漂移)
结构(旧 game/core+engine → 新 engine/ 域): - engine/kernel/ 时钟/随机/插件协议/fxqueue/timesense/format/urgency/guide/names(原 core) - engine/narrative/ legacy/报告/列传/谱系/年轴(原 core 叙事族) - engine/runtime/ World/creation/pcgen/ApiFacade/capabilities/pluginManager/boot/clocks + Systems/*(12 系统) - engine/sim/ Market(未来 WorldSim 同行) - 旧 game/core、engine/systems、engine/world.ts 等路径全部废弃(无 re-export 兼容层) 验证:35 套件/967 测试全绿(金钟罩三档零漂移=纯搬迁无行为变化) typecheck 0 error
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import type { World } from '../runtime/World'
|
||||
import { pack } from '../../data/registry'
|
||||
import { traitBonuses } from '../runtime/pcgen'
|
||||
|
||||
export function marketPrice(w: World, itemId: string): number {
|
||||
const item = pack().items[itemId]
|
||||
if (!item) return 0
|
||||
const base = item.basePrice
|
||||
const fam = w.state.family
|
||||
const mult = typeof fam.flag['priceMult'] === 'number' ? (fam.flag['priceMult'] as number) : 1
|
||||
const mood = fam.reputation >= 40 ? 1.06 : fam.reputation >= 20 ? 1.02 : 0.98
|
||||
// 利己(priceMult)与信誉修正
|
||||
const sellers = w.aliveMembers().filter((c) => traitBonuses(c).priceMult > 0).length
|
||||
const liarPct = Math.min(0.2, sellers * 0.04)
|
||||
return Math.max(1, Math.round(base * mult * mood * (1 - liarPct)))
|
||||
}
|
||||
|
||||
export function buyItem(w: World, itemId: string, count: number): boolean {
|
||||
const fam = w.state.family
|
||||
if (!pack().items[itemId]) return false
|
||||
const total = marketPrice(w, itemId) * count
|
||||
if (total > fam.stones) return false
|
||||
fam.stones -= total
|
||||
fam.inventory[itemId] = (fam.inventory[itemId] ?? 0) + count
|
||||
return true
|
||||
}
|
||||
|
||||
export function sellItem(w: World, itemId: string, count: number): boolean {
|
||||
const fam = w.state.family
|
||||
if (!pack().items[itemId]) return false
|
||||
const have = fam.inventory[itemId] ?? 0
|
||||
if (have < count) return false
|
||||
fam.inventory[itemId] = have - count
|
||||
fam.stones += marketPrice(w, itemId) * count
|
||||
return true
|
||||
}
|
||||
|
||||
export function buyTechnique(w: World, techId: string, price: number): boolean {
|
||||
const fam = w.state.family
|
||||
if (fam.techniques.includes(techId)) return false
|
||||
if (fam.stones < price) return false
|
||||
fam.stones -= price
|
||||
fam.techniques.push(techId)
|
||||
return true
|
||||
}
|
||||
|
||||
export function techniquePrice(techId: string): number {
|
||||
return TECH_GRADE_BASE[techId] ?? 200
|
||||
}
|
||||
|
||||
import { TECHNIQUES } from '../../data/techniques'
|
||||
|
||||
const TECHNIQUE_GRADE_PRICE: Record<number, number> = { 1: 120, 2: 300, 3: 700, 4: 1600 }
|
||||
const TECH_GRADE_BASE: Record<string, number> = Object.fromEntries(
|
||||
TECHNIQUES.map((t) => [t.id, TECHNIQUE_GRADE_PRICE[t.grade] ?? 300])
|
||||
)
|
||||
Reference in New Issue
Block a user