| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- // 成就与引导:成就定义与条件判定(纯函数)。署名:FmodeCode
- import { PLANETS } from '../data/planets.js';
- import { LIFE } from '../data/lives.js';
- import { ALL_EVENT_IDS } from '../data/events.js';
- const cleared = (s) => s.planets.filter((p) => p.rem <= 0).length;
- const lifeTotal = (s) => s.lives.reduce((a, p) => a + Object.keys(p).length, 0);
- const lifeLevel = (s) => s.lives.reduce((a, p) => a + Object.values(p).reduce((x, y) => x + y, 0), 0);
- /** 成就:条件为纯函数,测试可逐个验证 */
- export const ACHIEVEMENTS = [
- { id: 'first_root', icon: 'root', name: '第一缕根须', desc: '把根系升到 2 级', cond: (s) => s.rootLv >= 2 },
- { id: 'first_life', icon: 'sprout', name: '生命的第一声呼吸', desc: '种下第一种生命', cond: (s) => lifeTotal(s) >= 1 },
- { id: 'earth_clear', icon: 'earth', name: '蓝色星球的春天', desc: '让地球生态复苏到 100%', cond: (s) => s.planets[0].rem <= 0 },
- { id: 'moon_clear', icon: 'moon', name: '静海上的绿色', desc: '让月球焕新', cond: (s) => s.planets[1] && s.planets[1].rem <= 0 },
- { id: 'mars_clear', icon: 'mars', name: '赤色回绿', desc: '让火星焕新', cond: (s) => s.planets[2] && s.planets[2].rem <= 0 },
- { id: 'jupiter_clear', icon: 'planet', name: '风暴之眼熄灭', desc: '让木星焕新', cond: (s) => s.planets[3] && s.planets[3].rem <= 0 },
- { id: 'saturn_clear', icon: 'ring', name: '星环之歌', desc: '让土星焕新', cond: (s) => s.planets[4] && s.planets[4].rem <= 0 },
- { id: 'outer_clear', icon: 'star', name: '冰巨星的低语', desc: '让天王星与海王星都焕新', cond: (s) => s.planets[5] && s.planets[5].rem <= 0 && s.planets[6].rem <= 0 },
- { id: 'kuiper_clear', icon: 'comet', name: '边缘的光', desc: '让柯伊伯带焕新', cond: (s) => s.planets[7] && s.planets[7].rem <= 0 },
- { id: 'solar_clear', icon: 'sun', name: '太阳系复苏者', desc: '完成《太阳系篇》全部九章', cond: (s) => s.planets.every((p) => p.rem <= 0) },
- { id: 'collector5', icon: 'book', name: '生命图谱·初', desc: '收集 5 种生命', cond: (s) => lifeTotal(s) >= 5 },
- { id: 'collector10', icon: 'book', name: '生命图谱·中', desc: '收集 10 种生命', cond: (s) => lifeTotal(s) >= 10 },
- { id: 'collector_all', icon: 'book', name: '万物有灵', desc: '收集图鉴中的全部 18 种生命', cond: (s) => lifeTotal(s) >= LIFE.length },
- { id: 'root10', icon: 'root', name: '扎根十级', desc: '世界树扎根 10 级', cond: (s) => s.rootLv >= 10 },
- { id: 'root25', icon: 'root', name: '根系如海', desc: '世界树扎根 25 级', cond: (s) => s.rootLv >= 25 },
- { id: 'era1', icon: 'hourglass', name: '第一个纪元', desc: '第一次进入新纪元', cond: (s) => s.eras >= 1 },
- { id: 'era5', icon: 'hourglass', name: '五个纪元', desc: '进入第 5 个纪元', cond: (s) => s.eras >= 5 },
- { id: 'stems12', icon: 'seed', name: '基因园丁', desc: '种下 12 颗基因之种', cond: (s) => Object.values(s.stems).reduce((a, b) => a + b, 0) >= 12 },
- { id: 'events5', icon: 'wind', name: '星海行吟', desc: '经历 5 个不同的星海事件', cond: (s) => Object.keys(s.scene.events || {}).length >= 5 },
- { id: 'events_all', icon: 'wind', name: '旅者的手记', desc: '收集全部星海事件', cond: (s) => Object.keys(s.scene.events || {}).length >= ALL_EVENT_IDS.length },
- { id: 'tap100', icon: 'hand', name: '指尖的星火', desc: '点击世界树 100 次', cond: (s) => s.stats.taps >= 100 },
- { id: 'explore20', icon: 'compass', name: '勘探者', desc: '累计勘探 20 次', cond: (s) => s.stats.explores >= 20 },
- { id: 'curio3', icon: 'spark', name: '星辰抉择', desc: '完成 3 次星辰洗礼', cond: (s) => s.stats.curios >= 3 },
- ];
- export function newlyUnlocked(state) {
- return ACHIEVEMENTS.filter((a) => !state.ach[a.id] && safe(() => a.cond(state))).map((a) => a.id);
- }
- export function achById(id) { return ACHIEVEMENTS.find((a) => a.id === id); }
- export function achCount(state) { return ACHIEVEMENTS.filter((a) => !!state.ach[a.id]).length; }
- function safe(fn) { try { return !!fn(); } catch (e) { return false; } }
- /** 星球章的称号(完成时的庆祝标题) */
- export const PLANET_TITLES = PLANETS.map((p) => `${p.chapterNo} · ${p.chapterTitle}`);
|