import { World } from '../world' import { MAJORS } from '../../data/realms' import { calcLifespan } from '../pcgen' export function lifespanOf(w: World, c: { realm: { major: keyof typeof MAJORS }; physique: number }): number { return calcLifespan(c.realm.major, c.physique) } export function deathTick(w: World): void { for (const c of Object.values(w.state.members)) { if (!c.alive) continue const age = w.ageOf(c) const span = lifespanOf(w, c) const softCap = span * 0.85 let p = 0 if (age >= span) p = 0.35 else if (age >= softCap) { const t = (age - softCap) / (span - softCap) p = Math.min(0.3, Math.pow(t, 5) * 0.9) } if (c.health < 30) p += 0.18 if (age < 2) p = Math.max(p, 0.02) if (p > 0 && w.rng.chance(p)) { c.alive = false c.deathYear = w.state.year const cause = age < 2 ? '幼夭' : c.health < 30 ? '伤势不治' : '寿元将尽' c.deathCause = cause w.state.yearStats.deaths += 1 w.chronicle('death', `${c.name} 辞世,年 ${age}。${age < 2 ? '族人无不痛惜。' : c.health < 30 ? '临终前仍在牵挂家族。' : '族人焚香送别。'}`, c.id, true) w.log('bad', `${c.name}(${age}岁)${cause}。`) } } } export function woundHealTick(w: World): void { for (const c of Object.values(w.state.members)) { if (!c.alive) continue if (c.state === 'wounded') { c.health = Math.min(100, c.health + 12 + c.physique) if (c.health >= 95) { c.state = 'idle' w.log('info', `${c.name} 伤势痊愈。`) } } else if (c.health < 100) { c.health = Math.min(100, c.health + 2 + c.physique * 0.5) } } }