// ==================== 死亡引擎 ==================== import { applyEffect } from './effectApplier.js'; export function checkDeath(state) { // 1. age >= 100 → 寿终正寝 if (state.age >= 100) { applyEffect({ type: 'die', reason: '寿终正寝' }, state); return true; } // 2. age >= 60 && Math.random() < 0.1 → 年老体衰 if (state.age >= 60 && Math.random() < 0.1) { applyEffect({ type: 'die', reason: '年老体衰' }, state); return true; } // 3. stats.body <= 0 → 体弱身亡 if (state.stats.body <= 0) { applyEffect({ type: 'die', reason: '体弱身亡' }, state); return true; } // 4. age >= 45 && !invasion_military_resisted && Math.random() < 0.05 → 死于蛮族入侵 if (state.age >= 45 && !state.worldFlags.invasion_military_resisted && Math.random() < 0.05) { applyEffect({ type: 'die', reason: '死于蛮族入侵' }, state); return true; } // 5. age >= 50 && !invasion_spiritual_resisted && Math.random() < 0.05 → 被天魔吞噬 if (state.age >= 50 && !state.worldFlags.invasion_spiritual_resisted && Math.random() < 0.05) { applyEffect({ type: 'die', reason: '被天魔吞噬' }, state); return true; } // 6. age >= 55 && !invasion_political_resisted && Math.random() < 0.05 → 死于战乱 if (state.age >= 55 && !state.worldFlags.invasion_political_resisted && Math.random() < 0.05) { applyEffect({ type: 'die', reason: '死于战乱' }, state); return true; } return false; } export function processDeath(state, careerConfig) { const metaGains = {}; for (const [careerId, career] of Object.entries(state.careers)) { const cfg = careerConfig.careers.find(c => c.id === careerId); if (!cfg) continue; let totalExp = career.exp; for (let i = 0; i < career.level; i++) { totalExp += Math.floor(cfg.expCurve.base * Math.pow(cfg.expCurve.factor, i)); } const gain = Math.floor(totalExp * 0.1); state.metaExp[careerId] = (state.metaExp[careerId] || 0) + gain; metaGains[careerId] = gain; } return { metaGains }; }