dsh-hsr 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -23
- package/dsh-hsr-ico.png +0 -0
- package/experience/team-base.md +22 -3
- package/lib/help.js +178 -0
- package/lib/index.js +305 -71
- package/lib/source.js +73 -3
- package/lib/stage.js +689 -0
- package/lib/text.js +10 -0
- package/lib/tool.js +160 -17
- package/package.json +5 -3
- package/rules/game.md +146 -2
- package/rules/rules.md +33 -20
- package/config/safety.macro +0 -0
package/lib/stage.js
ADDED
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 深渊关卡:忘却之庭、虚构叙事、末日幻影、异相仲裁。
|
|
3
|
+
*
|
|
4
|
+
* 取数分三步:
|
|
5
|
+
* 1. 读每个玩法的索引(`maze.json` / `maze_extra.json` / `maze_boss.json` / `maze_peak.json`),
|
|
6
|
+
* 按 `live_begin` ~ `live_end` 选出当前生效的那一期;
|
|
7
|
+
* 2. 读关卡详情:忘却之庭、虚构叙事、末日幻影取三间(星启模式那一间,加上它前面
|
|
8
|
+
* 那关的上下两间);异相仲裁取当前一期(id 最大的一关;测试模式下数据比稳定版
|
|
9
|
+
* 多一条,取倒数第二);
|
|
10
|
+
* 3. 从关卡的波次里找出主怪(一般是第二波),再查怪物详情拿弱点与技能特点。
|
|
11
|
+
*
|
|
12
|
+
* 怪物技能只留「机制」,不列技能名:把描述里「对指定我方单体造成 X 属性伤害」这类
|
|
13
|
+
* 纯伤害句去掉,剩下的机制句标成「技能特点」。
|
|
14
|
+
*
|
|
15
|
+
* 图片索引、掉落、关卡配置、关卡 id 一律不输出。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { normalizeName } from './match.js';
|
|
19
|
+
import { plainText } from './text.js';
|
|
20
|
+
|
|
21
|
+
/** 四个玩法的定义:索引文件名、详情目录名、中英文名与别名。 */
|
|
22
|
+
export const STAGE_MODES = [
|
|
23
|
+
{
|
|
24
|
+
key: 'maze',
|
|
25
|
+
index: 'maze',
|
|
26
|
+
folder: 'maze',
|
|
27
|
+
zh: '忘却之庭',
|
|
28
|
+
en: 'Memory of Chaos',
|
|
29
|
+
aliases: ['忘却之庭', '混沌回忆', '记忆之庭', 'memory of chaos', 'moc'],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: 'story',
|
|
33
|
+
index: 'maze_extra',
|
|
34
|
+
folder: 'story',
|
|
35
|
+
zh: '虚构叙事',
|
|
36
|
+
en: 'Unknowable Domain',
|
|
37
|
+
aliases: ['虚构叙事', '不可知领域', 'unknowable domain', 'ud'],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: 'boss',
|
|
41
|
+
index: 'maze_boss',
|
|
42
|
+
folder: 'boss',
|
|
43
|
+
zh: '末日幻影',
|
|
44
|
+
en: 'Apocalyptic Shadow',
|
|
45
|
+
aliases: ['末日幻影', '历战余影', 'apocalyptic shadow', 'as'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: 'peak',
|
|
49
|
+
index: 'maze_peak',
|
|
50
|
+
folder: 'peak',
|
|
51
|
+
zh: '异相仲裁',
|
|
52
|
+
en: 'Peak Arbitration',
|
|
53
|
+
aliases: ['异相仲裁', '异象仲裁', '仲裁', 'peak arbitration', 'pa'],
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/** 标签。 */
|
|
58
|
+
const LABELS = {
|
|
59
|
+
zh: {
|
|
60
|
+
title: '当前深渊关卡',
|
|
61
|
+
starLaunch: '星启模式',
|
|
62
|
+
limit: '限时',
|
|
63
|
+
enemyTypes: '敌方属性',
|
|
64
|
+
goals: '目标',
|
|
65
|
+
starGoal: '额外目标',
|
|
66
|
+
wave: '第 {n} 波',
|
|
67
|
+
mainMonster: '主怪',
|
|
68
|
+
weakness: '弱点(可削韧属性)',
|
|
69
|
+
resist: '抗性',
|
|
70
|
+
laterWaves: '第一波小怪',
|
|
71
|
+
noMonster: '这一关没有查到主怪。',
|
|
72
|
+
inactive: '(当前不在开放期,显示最近的一期)',
|
|
73
|
+
more: '等 {n} 条',
|
|
74
|
+
traits: '技能特点',
|
|
75
|
+
effects: '关卡增益',
|
|
76
|
+
options: '增益选项',
|
|
77
|
+
tags: '关卡词条',
|
|
78
|
+
bossLevel: '首领关',
|
|
79
|
+
nothing: '(没有查到进行中的深渊关卡。)',
|
|
80
|
+
only: '只查',
|
|
81
|
+
chamber: '第 {n} 间',
|
|
82
|
+
},
|
|
83
|
+
en: {
|
|
84
|
+
title: 'Current Challenge Stages',
|
|
85
|
+
starLaunch: 'Star Launch',
|
|
86
|
+
limit: 'Time limit',
|
|
87
|
+
enemyTypes: 'Enemy types',
|
|
88
|
+
goals: 'Goals',
|
|
89
|
+
starGoal: 'Extra goal',
|
|
90
|
+
wave: 'Wave {n}',
|
|
91
|
+
mainMonster: 'Main enemy',
|
|
92
|
+
weakness: 'Weakness (elements that break its toughness)',
|
|
93
|
+
resist: 'Resistances',
|
|
94
|
+
laterWaves: 'First-wave enemies',
|
|
95
|
+
noMonster: 'No main enemy found for this stage.',
|
|
96
|
+
inactive: ' (not currently open, showing the closest one)',
|
|
97
|
+
more: 'and {n} more',
|
|
98
|
+
traits: 'Skill traits',
|
|
99
|
+
effects: 'Stage buffs',
|
|
100
|
+
options: 'Buff options',
|
|
101
|
+
tags: 'Stage tags',
|
|
102
|
+
bossLevel: 'Boss stage',
|
|
103
|
+
nothing: '(no challenge stage found.)',
|
|
104
|
+
only: 'only',
|
|
105
|
+
chamber: 'Part {n}',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** 一个技能描述里,最多保留多少条机制。 */
|
|
110
|
+
const TRAIT_LIMIT = 6;
|
|
111
|
+
|
|
112
|
+
/** 描述里出现这些词,说明这句在讲机制,不只是打伤害。 */
|
|
113
|
+
const MECHANIC_HINT =
|
|
114
|
+
/(降低|提高|减少|提升|增加|无视|减免|额外|抗性|回复|恢复|获得|失去|陷入|状态|层|削韧|韧性|护盾|召唤|施放|释放|行动|回合|能量|战技点|抵抗|击破|弱点|增益|减益|标记|嘲讽|持续|概率|受到攻击|抵消|免疫|封锁|减速|加速|延后|提前|冻结|缴械|沉默|禁锢|蓄力|承受)/;
|
|
115
|
+
|
|
116
|
+
/** 英文描述里的机制词。 */
|
|
117
|
+
const MECHANIC_HINT_EN =
|
|
118
|
+
/(reduce|increas|lessen|ignores|resist|recover|restore|gain|lose|enter|stagger|toughness|shield|summon|perform|release|action|turn|energy|skill point|break|weakness|buff|debuff|mark|taunt|duration|chance|immune|seal|slow|speed up|delay|advance|freeze|disarm|silence|charge|additional turn)/i;
|
|
119
|
+
|
|
120
|
+
/** 句首的纯伤害描述:整段去掉,只留后面的机制。 */
|
|
121
|
+
const DAMAGE_LEAD_ZH = /^[^,,。;;]{0,24}对[^,,]{0,24}?造成[^,,]{0,24}?伤害[,,]?\s*/;
|
|
122
|
+
const DAMAGE_LEAD_EN = /^[^,.]{0,80}?(?:deals|damage|inflicts)[^,.]{0,80}?(?:damage|dmg)[^,.]{0,24}[,.]?\s*/i;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 解析时间窗口字符串(形如 `2026-11-02 04:00:00`)。
|
|
126
|
+
* @param {unknown} text 原始字符串。
|
|
127
|
+
* @returns {Date|null} 解析结果。
|
|
128
|
+
*/
|
|
129
|
+
function parseWindow(text) {
|
|
130
|
+
if (typeof text !== 'string' || text.trim().length === 0) return null;
|
|
131
|
+
const normalized = text.trim().replace(' ', 'T');
|
|
132
|
+
const value = new Date(normalized);
|
|
133
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 从索引里挑当前生效的条目。
|
|
138
|
+
* @param {Record<string, object>} index 索引。
|
|
139
|
+
* @param {number} now 当前时间戳。
|
|
140
|
+
* @returns {{id: string, entry: object, active: boolean}|null} 命中的条目。
|
|
141
|
+
*/
|
|
142
|
+
export function pickLiveEntry(index, now = Date.now()) {
|
|
143
|
+
const withWindow = [];
|
|
144
|
+
for (const [id, entry] of Object.entries(index || {})) {
|
|
145
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
146
|
+
const begin = parseWindow(entry.live_begin);
|
|
147
|
+
const end = parseWindow(entry.live_end);
|
|
148
|
+
if (!begin || !end) continue;
|
|
149
|
+
withWindow.push({ id, entry, begin, end });
|
|
150
|
+
}
|
|
151
|
+
if (withWindow.length === 0) return null;
|
|
152
|
+
const active = withWindow.find((item) => item.begin.getTime() <= now && now <= item.end.getTime());
|
|
153
|
+
if (active) return { id: active.id, entry: active.entry, active: true };
|
|
154
|
+
// 不在开放期时,取最近的一期:已经开始的里最近的那个,没有就从最早的开始。
|
|
155
|
+
const started = withWindow.filter((item) => item.begin.getTime() <= now);
|
|
156
|
+
const pool = started.length > 0 ? started : withWindow;
|
|
157
|
+
pool.sort((a, b) => Math.abs(a.begin.getTime() - now) - Math.abs(b.begin.getTime() - now));
|
|
158
|
+
return { id: pool[0].id, entry: pool[0].entry, active: false };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 从关卡详情里挑出要展示的关卡。
|
|
163
|
+
* @param {string} mode 玩法 key。
|
|
164
|
+
* @param {object|object[]} detail 关卡详情。
|
|
165
|
+
* @returns {object[]} 关卡数组。
|
|
166
|
+
*/
|
|
167
|
+
export function selectLevels(mode, detail) {
|
|
168
|
+
if (!detail || typeof detail !== 'object') return [];
|
|
169
|
+
if (mode === 'peak') {
|
|
170
|
+
const levels = Array.isArray(detail.pre_level) ? detail.pre_level.slice() : [];
|
|
171
|
+
if (detail.boss_level && typeof detail.boss_level === 'object') levels.push(detail.boss_level);
|
|
172
|
+
return levels;
|
|
173
|
+
}
|
|
174
|
+
const all = mode === 'maze'
|
|
175
|
+
? (Array.isArray(detail) ? detail : [])
|
|
176
|
+
: (Array.isArray(detail?.level) ? detail.level : []);
|
|
177
|
+
if (all.length === 0) return [];
|
|
178
|
+
// 星启模式这一期一共三间:上一关的两间(上/下半),加上星启模式自己的一间。
|
|
179
|
+
// 上一关在数据里是两间(event_id_list1 / event_id_list2),星启只有一个 event_id_list,
|
|
180
|
+
// 所以取最后两关就正好是三间。
|
|
181
|
+
return all.slice(-2);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 取一关里的所有波次,按「间」分组。
|
|
185
|
+
*
|
|
186
|
+
* 一关最多两间:上半在 `event_id_list1`,下半在 `event_id_list2`;
|
|
187
|
+
* 星启模式那一关只有一间,直接放在 `event_id_list` 里。
|
|
188
|
+
* 这里保留分组,渲染时才能把两间的怪分开,不会混在一起。
|
|
189
|
+
* @param {object} level 关卡。
|
|
190
|
+
* @returns {{chamber: number, stage: object}[]} 波次列表,`chamber` 从 1 起。
|
|
191
|
+
*/
|
|
192
|
+
function collectStages(level) {
|
|
193
|
+
const rows = [];
|
|
194
|
+
let chamber = 1;
|
|
195
|
+
for (const key of ['event_id_list', 'event_id_list1', 'event_id_list2']) {
|
|
196
|
+
const list = level?.[key];
|
|
197
|
+
if (!Array.isArray(list) || list.length === 0) continue;
|
|
198
|
+
for (const stage of list) {
|
|
199
|
+
if (stage && typeof stage === 'object') rows.push({ chamber, stage });
|
|
200
|
+
}
|
|
201
|
+
chamber += 1;
|
|
202
|
+
}
|
|
203
|
+
return rows;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 从一波的怪物表里取出怪物 id。
|
|
208
|
+
* @param {object} wave 一波。
|
|
209
|
+
* @returns {string[]} 怪物 id。
|
|
210
|
+
*/
|
|
211
|
+
function monsterIdsOf(wave) {
|
|
212
|
+
if (!wave || typeof wave !== 'object') return [];
|
|
213
|
+
const ids = [];
|
|
214
|
+
for (const [key, value] of Object.entries(wave)) {
|
|
215
|
+
if (!key.startsWith('monster')) continue;
|
|
216
|
+
if (typeof value === 'number') ids.push(String(value));
|
|
217
|
+
else if (Array.isArray(value)) {
|
|
218
|
+
for (const item of value) {
|
|
219
|
+
if (typeof item === 'number') ids.push(String(item));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return ids;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 找出主怪:第一波之后的所有怪(第一波通常是小怪);只有一波时就用那一波。
|
|
228
|
+
* @param {object[]} waves 所有波次。
|
|
229
|
+
* @returns {{waveIndex: number, ids: string[]}[]} 主怪分组。
|
|
230
|
+
*/
|
|
231
|
+
export function pickMainMonsters(waves) {
|
|
232
|
+
if (!Array.isArray(waves) || waves.length === 0) return [];
|
|
233
|
+
const groups = [];
|
|
234
|
+
for (let index = 1; index < waves.length; index += 1) {
|
|
235
|
+
const ids = monsterIdsOf(waves[index]);
|
|
236
|
+
if (ids.length > 0) groups.push({ waveIndex: index, ids });
|
|
237
|
+
}
|
|
238
|
+
if (groups.length > 0) return groups;
|
|
239
|
+
const ids = monsterIdsOf(waves[0]);
|
|
240
|
+
return ids.length > 0 ? [{ waveIndex: 0, ids }] : [];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 把一段描述切成句子。
|
|
245
|
+
* @param {string} text 描述。
|
|
246
|
+
* @returns {string[]} 句子。
|
|
247
|
+
*/
|
|
248
|
+
function splitSentences(text) {
|
|
249
|
+
const parts = [];
|
|
250
|
+
const re = /[^。;;\n]+[。;;]?/g;
|
|
251
|
+
let matched;
|
|
252
|
+
while ((matched = re.exec(text)) !== null) {
|
|
253
|
+
const part = matched[0].trim();
|
|
254
|
+
if (part.length > 0) parts.push(part);
|
|
255
|
+
}
|
|
256
|
+
return parts;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 判断一句是不是「只讲打伤害」的纯伤害句。
|
|
261
|
+
* @param {string} clause 一句描述。
|
|
262
|
+
* @param {boolean} en 是否英文。
|
|
263
|
+
* @returns {boolean} 是纯伤害句时为 true。
|
|
264
|
+
*/
|
|
265
|
+
function isDamageOnly(clause, en) {
|
|
266
|
+
const damaged = en
|
|
267
|
+
? /(?:deals|damage|inflicts|causes)[^,.;]{0,40}(?:damage|dmg)/i.test(clause)
|
|
268
|
+
: /(?:造成|受到|造成|受到)[^,,。;;]{0,8}伤害/.test(clause);
|
|
269
|
+
if (!damaged) return false;
|
|
270
|
+
if (en ? MECHANIC_HINT_EN.test(clause) : MECHANIC_HINT.test(clause)) return false;
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 从技能描述里抽出「机制句」:去掉纯伤害描述,只留特殊机制。
|
|
276
|
+
*
|
|
277
|
+
* 做法是按句切,再把句子里纯打伤害的分句去掉,剩下的合起来算一条机制,
|
|
278
|
+
* 这样「召唤A,每个召唤物被消灭时,削减自身韧性」不会被拆成三条碎片。
|
|
279
|
+
* @param {unknown} desc 原始描述。
|
|
280
|
+
* @param {string} [lang] 语言。
|
|
281
|
+
* @returns {string[]} 机制句列表。
|
|
282
|
+
*/
|
|
283
|
+
export function extractTraits(desc, lang = 'zh') {
|
|
284
|
+
const text = plainText(desc, []);
|
|
285
|
+
if (text.length === 0) return [];
|
|
286
|
+
const en = lang === 'en';
|
|
287
|
+
const traits = [];
|
|
288
|
+
for (const sentence of splitSentences(text)) {
|
|
289
|
+
const clauses = sentence
|
|
290
|
+
.split(/[,,]/)
|
|
291
|
+
.map((clause) => clause.replace(/^[,,、。;;\s]+/, '').replace(/[。;;\s]+$/, '').trim())
|
|
292
|
+
.filter((clause) => clause.length > 0);
|
|
293
|
+
const kept = clauses.filter((clause) => !isDamageOnly(clause, en));
|
|
294
|
+
if (kept.length === 0) continue;
|
|
295
|
+
// 去掉句首的连接词,读起来更顺。
|
|
296
|
+
const trait = kept.join(',').replace(/^(?:并且|并且|并|且|同时|然后|接着)/, '');
|
|
297
|
+
if (trait.length === 0) continue;
|
|
298
|
+
if (!traits.includes(trait)) traits.push(trait);
|
|
299
|
+
}
|
|
300
|
+
return traits;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 已知固定取值的目标:文本里带占位符,但数据里没给 `param`。
|
|
305
|
+
* 全部历史关卡里,这类目标只要带了取值就都是这个数。
|
|
306
|
+
*/
|
|
307
|
+
const GOAL_FALLBACK_PARAMS = new Map([
|
|
308
|
+
['无法战斗角色不超过<unbreak>#1[i]</unbreak>名', 1],
|
|
309
|
+
['No more than <unbreak>#1[i]</unbreak> downed character(s)', 1],
|
|
310
|
+
]);
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 把关卡目标转成文字。
|
|
314
|
+
*
|
|
315
|
+
* 目标文本里带 `#1` 这类占位符,取值来自该目标自己的 `param`;
|
|
316
|
+
* 有些目标没带取值(例如「无法战斗角色不超过 N 名」),那就从同一份数据里
|
|
317
|
+
* 找同名且带取值的其它目标来补,补不到再退到已知的固定取值。
|
|
318
|
+
* @param {object} goal 目标。
|
|
319
|
+
* @param {Map<string, number>} [fallback] 目标文本 → 取值。
|
|
320
|
+
* @returns {string} 目标文字。
|
|
321
|
+
*/
|
|
322
|
+
function goalText(goal, fallback) {
|
|
323
|
+
const name = typeof goal?.name === 'string' ? goal.name : '';
|
|
324
|
+
if (name.length === 0) return '';
|
|
325
|
+
const raw = goal?.param;
|
|
326
|
+
if (raw !== undefined && raw !== null && Number.isFinite(Number(raw))) {
|
|
327
|
+
return plainText(name, [Number(raw)]);
|
|
328
|
+
}
|
|
329
|
+
const known = fallback?.get(name) ?? GOAL_FALLBACK_PARAMS.get(name);
|
|
330
|
+
if (Number.isFinite(known)) return plainText(name, [known]);
|
|
331
|
+
return plainText(name.replace(/#\d+\[[^\]]*\]/g, ''), []).replace(/\s{2,}/g, ' ');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* 把一关的挑战目标转成文字列表。
|
|
336
|
+
* @param {object} level 关卡。
|
|
337
|
+
* @param {Map<string, number>} [fallback] 目标文本 → 取值。
|
|
338
|
+
* @returns {string[]} 目标列表。
|
|
339
|
+
*/
|
|
340
|
+
function goalsOf(level, fallback) {
|
|
341
|
+
const lines = [];
|
|
342
|
+
for (const goal of Array.isArray(level?.challenge) ? level.challenge : []) {
|
|
343
|
+
if (!goal || typeof goal !== 'object') continue;
|
|
344
|
+
const text = goalText(goal, fallback);
|
|
345
|
+
if (text) lines.push(text);
|
|
346
|
+
}
|
|
347
|
+
return lines;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 收集一份关卡数据里所有带取值的目标,作为其它目标的取值来源。
|
|
352
|
+
* @param {object|object[]} detail 关卡详情。
|
|
353
|
+
* @returns {Map<string, number>} 目标文本 → 取值。
|
|
354
|
+
*/
|
|
355
|
+
function collectGoalParams(detail) {
|
|
356
|
+
const map = new Map();
|
|
357
|
+
const levels = Array.isArray(detail)
|
|
358
|
+
? detail
|
|
359
|
+
: Array.isArray(detail?.level)
|
|
360
|
+
? detail.level
|
|
361
|
+
: [
|
|
362
|
+
...(Array.isArray(detail?.pre_level) ? detail.pre_level : []),
|
|
363
|
+
...(detail?.boss_level ? [detail.boss_level] : []),
|
|
364
|
+
];
|
|
365
|
+
for (const level of levels) {
|
|
366
|
+
for (const goal of Array.isArray(level?.challenge) ? level.challenge : []) {
|
|
367
|
+
if (!goal || typeof goal !== 'object') continue;
|
|
368
|
+
const value = Number(goal.param);
|
|
369
|
+
if (typeof goal.name === 'string' && Number.isFinite(value) && !map.has(goal.name)) {
|
|
370
|
+
map.set(goal.name, value);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return map;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 渲染一组「名称 + 说明」的增益或词条。
|
|
379
|
+
* @param {string} title 小标题。
|
|
380
|
+
* @param {object[]} list 条目列表。
|
|
381
|
+
* @param {object} labels 标签。
|
|
382
|
+
* @returns {string[]} 文本行。
|
|
383
|
+
*/
|
|
384
|
+
function renderEffects(title, list, labels) {
|
|
385
|
+
const rows = Array.isArray(list) ? list : [];
|
|
386
|
+
if (rows.length === 0) return [];
|
|
387
|
+
const lines = [`- ${title}:`];
|
|
388
|
+
for (const row of rows) {
|
|
389
|
+
if (!row || typeof row !== 'object') continue;
|
|
390
|
+
const name = plainText(row.name, []);
|
|
391
|
+
const desc = plainText(row.desc, Array.isArray(row.param) ? row.param : []);
|
|
392
|
+
if (!name && !desc) continue;
|
|
393
|
+
lines.push(` - ${name}${desc ? `:${desc}` : ''}`);
|
|
394
|
+
}
|
|
395
|
+
return lines.length > 1 ? lines : [];
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* 主怪详情:弱点、抗性、技能特点。
|
|
400
|
+
* @param {object} child 怪物条目。
|
|
401
|
+
* @param {string} name 怪物名。
|
|
402
|
+
* @param {object} labels 标签。
|
|
403
|
+
* @param {object} config 配置。
|
|
404
|
+
* @param {string} lang 语言。
|
|
405
|
+
* @returns {string[]} 文本行。
|
|
406
|
+
*/
|
|
407
|
+
function renderMonster(child, name, labels, config, lang) {
|
|
408
|
+
const lines = [];
|
|
409
|
+
const weak = Array.isArray(child?.stance_weak_list) ? child.stance_weak_list : [];
|
|
410
|
+
if (weak.length > 0) {
|
|
411
|
+
const named = weak.map((value) => config.damageTypes?.[value]?.[lang] || value);
|
|
412
|
+
lines.push(`- ${labels.weakness}:${named.join('、')}`);
|
|
413
|
+
}
|
|
414
|
+
const resist = Array.isArray(child?.damage_type_resistance) ? child.damage_type_resistance : [];
|
|
415
|
+
const resistText = resist
|
|
416
|
+
.filter((row) => row && Number(row.value) > 0)
|
|
417
|
+
.map((row) => {
|
|
418
|
+
const element = config.damageTypes?.[row.damage_type]?.[lang] || row.damage_type;
|
|
419
|
+
return `${element} ${Math.round(Number(row.value) * 100)}%`;
|
|
420
|
+
});
|
|
421
|
+
if (resistText.length > 0) lines.push(`- ${labels.resist}:${resistText.join('、')}`);
|
|
422
|
+
|
|
423
|
+
const skills = Array.isArray(child?.skill_list) ? child.skill_list : [];
|
|
424
|
+
const traits = [];
|
|
425
|
+
for (const skill of skills) {
|
|
426
|
+
if (!skill || typeof skill !== 'object') continue;
|
|
427
|
+
for (const trait of extractTraits(skill.skill_desc, lang)) {
|
|
428
|
+
if (!traits.includes(trait)) traits.push(trait);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// 同一条机制常被不同技能重复描述,短的被长的覆盖时只留长的。
|
|
432
|
+
const keptTraits = traits.filter(
|
|
433
|
+
(trait) => !traits.some((other) => other !== trait && other.includes(trait)),
|
|
434
|
+
);
|
|
435
|
+
if (keptTraits.length > 0) {
|
|
436
|
+
lines.push(`- ${labels.traits}:`);
|
|
437
|
+
for (const trait of keptTraits.slice(0, TRAIT_LIMIT)) lines.push(` - ${trait}`);
|
|
438
|
+
if (keptTraits.length > TRAIT_LIMIT) {
|
|
439
|
+
lines.push(` - ${labels.more.replace('{n}', String(keptTraits.length - TRAIT_LIMIT))}`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (name) lines.unshift(`- ${labels.mainMonster}:${name}`);
|
|
443
|
+
return lines;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* 渲染一关。
|
|
448
|
+
* @param {object} params 参数。
|
|
449
|
+
* @returns {Promise<string[]>} 文本行。
|
|
450
|
+
*/
|
|
451
|
+
async function renderLevel(params) {
|
|
452
|
+
const { level, entryName, lang, labels, config, fetchMonster, isBoss } = params;
|
|
453
|
+
const lines = [];
|
|
454
|
+
const levelName = plainText(level?.name || '', []);
|
|
455
|
+
const suffix = level?.challenge_special !== undefined ? `(${labels.starLaunch})` : '';
|
|
456
|
+
const prefix = params.titlePrefix ? `${params.titlePrefix} · ` : '';
|
|
457
|
+
const heading = levelName ? `${prefix}${levelName}` : (entryName || '');
|
|
458
|
+
lines.push(`### ${heading}${suffix}${isBoss ? `(${labels.bossLevel})` : ''}`);
|
|
459
|
+
const countdown = Number(level?.countdown);
|
|
460
|
+
if (Number.isFinite(countdown) && countdown > 0) {
|
|
461
|
+
const seconds = countdown >= 1000 ? Math.round(countdown / 1000) : countdown;
|
|
462
|
+
lines.push(`- ${labels.limit}:${seconds} 秒`);
|
|
463
|
+
}
|
|
464
|
+
const types = Array.isArray(level?.damage_type) ? level.damage_type : [];
|
|
465
|
+
if (types.length > 0) {
|
|
466
|
+
const named = types.map((value) => config.damageTypes?.[value]?.[lang] || value);
|
|
467
|
+
lines.push(`- ${labels.enemyTypes}:${named.join('、')}`);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const goals = goalsOf(level, params.goalParams);
|
|
471
|
+
if (goals.length > 0) lines.push(`- ${labels.goals}:${goals.join(';')}`);
|
|
472
|
+
if (level?.challenge_special) {
|
|
473
|
+
const starGoal = goalText(level.challenge_special, params.goalParams);
|
|
474
|
+
if (starGoal) lines.push(`- ${labels.starGoal}:${starGoal}`);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
lines.push(...renderEffects(labels.tags, level?.tag_list, labels));
|
|
478
|
+
if (Array.isArray(params.extraTags) && params.extraTags.length > 0) {
|
|
479
|
+
lines.push(...renderEffects(labels.tags, params.extraTags, labels));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const stages = collectStages(level);
|
|
483
|
+
const chambers = [...new Set(stages.map((row) => row.chamber))];
|
|
484
|
+
const multiChamber = chambers.length > 1;
|
|
485
|
+
const shown = new Set();
|
|
486
|
+
let found = false;
|
|
487
|
+
for (const row of stages) {
|
|
488
|
+
if (multiChamber) {
|
|
489
|
+
lines.push('');
|
|
490
|
+
lines.push(`##### ${labels.chamber.replace('{n}', String(chambers.indexOf(row.chamber) + 1))}`);
|
|
491
|
+
}
|
|
492
|
+
const waves = Array.isArray(row.stage?.monster_list) ? row.stage.monster_list : [];
|
|
493
|
+
const firstWaveNames = [];
|
|
494
|
+
const groups = pickMainMonsters(waves);
|
|
495
|
+
for (const group of groups) {
|
|
496
|
+
for (const id of group.ids) {
|
|
497
|
+
if (shown.has(id)) continue;
|
|
498
|
+
const info = await fetchMonster(id);
|
|
499
|
+
if (!info) continue;
|
|
500
|
+
shown.add(id);
|
|
501
|
+
found = true;
|
|
502
|
+
lines.push('');
|
|
503
|
+
lines.push(`#### ${labels.wave.replace('{n}', String(group.waveIndex + 1))} · ${info.name}`);
|
|
504
|
+
lines.push(...renderMonster(info.child, info.name, labels, config, lang));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
for (const id of monsterIdsOf(waves[0])) {
|
|
508
|
+
if (shown.has(id)) continue;
|
|
509
|
+
const info = await fetchMonster(id);
|
|
510
|
+
if (info && !firstWaveNames.includes(info.name)) firstWaveNames.push(info.name);
|
|
511
|
+
}
|
|
512
|
+
if (firstWaveNames.length > 0) lines.push(`- ${labels.laterWaves}:${firstWaveNames.join('、')}`);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// 末日幻影的首领 id 直接写在关卡上,不在波次里。
|
|
516
|
+
if (level?.boss_monster_id) {
|
|
517
|
+
const bossId = String(level.boss_monster_id);
|
|
518
|
+
if (!shown.has(bossId)) {
|
|
519
|
+
const info = await fetchMonster(bossId);
|
|
520
|
+
if (info) {
|
|
521
|
+
shown.add(bossId);
|
|
522
|
+
found = true;
|
|
523
|
+
lines.push('');
|
|
524
|
+
lines.push(`#### ${labels.mainMonster} · ${info.name}`);
|
|
525
|
+
lines.push(...renderMonster(info.child, info.name, labels, config, lang));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (!found) lines.push(labels.noMonster);
|
|
531
|
+
return lines;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* 渲染一个玩法的正文。
|
|
536
|
+
* @param {object} params 参数。
|
|
537
|
+
* @returns {Promise<string>} 正文。
|
|
538
|
+
*/
|
|
539
|
+
async function renderMode(params) {
|
|
540
|
+
const { mode, entry, entryId, levels, lang, labels, config, fetchMonster, isBossLevel } = params;
|
|
541
|
+
const en = lang === 'en';
|
|
542
|
+
const lines = [];
|
|
543
|
+
const modeName = en ? mode.en : mode.zh;
|
|
544
|
+
const entryName = plainText(entry?.[lang] || entry?.zh || entry?.en || '', []);
|
|
545
|
+
lines.push(`## ${modeName}|${entryName}`);
|
|
546
|
+
if (entry && entry.active === false) lines.push(labels.inactive);
|
|
547
|
+
|
|
548
|
+
if (mode.key === 'story') {
|
|
549
|
+
lines.push(...renderEffects(labels.effects, [entry?.buff], labels));
|
|
550
|
+
lines.push(...renderEffects(labels.options, entry?.option, labels));
|
|
551
|
+
lines.push(...renderEffects(labels.options, entry?.sub_option, labels));
|
|
552
|
+
} else if (mode.key === 'boss') {
|
|
553
|
+
lines.push(...renderEffects(labels.effects, [entry?.buff], labels));
|
|
554
|
+
lines.push(...renderEffects(labels.effects, entry?.buff_list1, labels));
|
|
555
|
+
lines.push(...renderEffects(labels.effects, entry?.buff_list2, labels));
|
|
556
|
+
lines.push(...renderEffects(labels.effects, entry?.buff_list3, labels));
|
|
557
|
+
} else if (mode.key === 'peak') {
|
|
558
|
+
lines.push(...renderEffects(labels.effects, params.bossConfig?.buff_list, labels));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
for (const level of levels) {
|
|
562
|
+
lines.push('');
|
|
563
|
+
lines.push(
|
|
564
|
+
...(await renderLevel({
|
|
565
|
+
level,
|
|
566
|
+
entryName,
|
|
567
|
+
// 异相仲裁的每一关名字都一样(「骑士(一)」这类),靠前面的关卡名区分。
|
|
568
|
+
titlePrefix: mode.key === 'peak' ? entryName : '',
|
|
569
|
+
goalParams: params.goalParams,
|
|
570
|
+
lang,
|
|
571
|
+
labels,
|
|
572
|
+
config,
|
|
573
|
+
fetchMonster,
|
|
574
|
+
traitLimit: params.traitLimit,
|
|
575
|
+
isBoss: Boolean(isBossLevel && isBossLevel(level)),
|
|
576
|
+
})),
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
return lines.join('\n');
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* 把用户给的玩法名归一成玩法 key。
|
|
584
|
+
* @param {string} value 用户输入。
|
|
585
|
+
* @returns {{mode: object, peakId: string|null}|null} 解析结果。
|
|
586
|
+
*/
|
|
587
|
+
export function resolveMode(value) {
|
|
588
|
+
const query = normalizeName(value);
|
|
589
|
+
if (query.length === 0) return null;
|
|
590
|
+
for (const mode of STAGE_MODES) {
|
|
591
|
+
const names = [mode.key, mode.zh, mode.en, ...mode.aliases];
|
|
592
|
+
if (names.some((item) => normalizeName(item) === query)) return { mode, peakId: null };
|
|
593
|
+
}
|
|
594
|
+
// 「异相仲裁 3」「peak3」这类:只指第 3 关。
|
|
595
|
+
for (const mode of STAGE_MODES) {
|
|
596
|
+
if (mode.key !== 'peak') continue;
|
|
597
|
+
const names = [mode.key, mode.zh, mode.en, ...mode.aliases].map((item) => normalizeName(item));
|
|
598
|
+
for (const name of names) {
|
|
599
|
+
if (query.startsWith(name)) {
|
|
600
|
+
const digits = query.slice(name.length);
|
|
601
|
+
if (/^\d{1,2}$/.test(digits)) return { mode, peakId: digits };
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* 判断用户给的玩法名能不能认出来。
|
|
610
|
+
* @param {string} value 用户输入。
|
|
611
|
+
* @returns {boolean} 能认出来时为 true。
|
|
612
|
+
*/
|
|
613
|
+
export function isKnownStage(value) {
|
|
614
|
+
return resolveMode(value) !== null;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* 生成深渊关卡正文。
|
|
619
|
+
* @param {object} options 参数。
|
|
620
|
+
* @param {string} options.version 数据版本。
|
|
621
|
+
* @param {string} options.lang 语言。
|
|
622
|
+
* @param {object} options.config 配置。
|
|
623
|
+
* @param {string[]} [options.only] 只查这些玩法 key。
|
|
624
|
+
* @param {string} [options.peakId] 只查异相仲裁的这一关。
|
|
625
|
+
* @param {(index: string, version: string) => Promise<object>} options.loadIndex 读索引。
|
|
626
|
+
* @param {(folder: string, version: string, lang: string, id: string) => Promise<object>} options.loadDetail 读关卡详情。
|
|
627
|
+
* @param {(id: string) => Promise<object|null>} options.fetchMonster 查怪物详情。
|
|
628
|
+
* @returns {Promise<string>} 正文。
|
|
629
|
+
*/
|
|
630
|
+
export async function renderStages(options) {
|
|
631
|
+
const { version, lang, config, only, peakId, fetchMonster, testMode } = options;
|
|
632
|
+
const labels = LABELS[lang] || LABELS.zh;
|
|
633
|
+
const wanted = new Set(only && only.length > 0 ? only : STAGE_MODES.map((mode) => mode.key));
|
|
634
|
+
const sections = [];
|
|
635
|
+
|
|
636
|
+
for (const mode of STAGE_MODES) {
|
|
637
|
+
if (!wanted.has(mode.key)) continue;
|
|
638
|
+
const index = await options.loadIndex(mode.index, version);
|
|
639
|
+
const entries = [];
|
|
640
|
+
if (mode.key === 'peak') {
|
|
641
|
+
// 异相仲裁没有开放期,当前关卡是 id 最大的那一关;
|
|
642
|
+
// 测试模式下的数据总比稳定版多一条(更新的那期),所以要退一格。
|
|
643
|
+
const all = [];
|
|
644
|
+
for (const [id, entry] of Object.entries(index)) {
|
|
645
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
646
|
+
if (peakId !== undefined && peakId !== null && String(id) !== String(peakId)) continue;
|
|
647
|
+
all.push({ id, entry, active: true });
|
|
648
|
+
}
|
|
649
|
+
all.sort((a, b) => Number(a.id) - Number(b.id));
|
|
650
|
+
if (peakId === undefined || peakId === null) {
|
|
651
|
+
// 当前一期是 id 最大的那一关;测试模式的数据比正式版多一条最新的,退一格。
|
|
652
|
+
const maxId = all.length > 0 ? Number(all[all.length - 1].id) : 0;
|
|
653
|
+
const target = testMode ? maxId - 1 : maxId;
|
|
654
|
+
const picked = all.filter((item) => Number(item.id) === target).pop();
|
|
655
|
+
if (picked) entries.push(picked);
|
|
656
|
+
} else {
|
|
657
|
+
entries.push(...all);
|
|
658
|
+
}
|
|
659
|
+
} else {
|
|
660
|
+
const picked = pickLiveEntry(index);
|
|
661
|
+
if (!picked) continue;
|
|
662
|
+
entries.push(picked);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
for (const item of entries) {
|
|
666
|
+
const detail = await options.loadDetail(mode.folder, version, lang, item.id);
|
|
667
|
+
const levels = selectLevels(mode.key, detail);
|
|
668
|
+
if (levels.length === 0) continue;
|
|
669
|
+
const body = await renderMode({
|
|
670
|
+
mode,
|
|
671
|
+
entry: item.entry,
|
|
672
|
+
entryId: item.id,
|
|
673
|
+
levels,
|
|
674
|
+
goalParams: collectGoalParams(detail),
|
|
675
|
+
peakId,
|
|
676
|
+
lang,
|
|
677
|
+
labels,
|
|
678
|
+
config,
|
|
679
|
+
fetchMonster,
|
|
680
|
+
bossConfig: detail?.boss_config,
|
|
681
|
+
isBossLevel: (level) => detail?.boss_level === level,
|
|
682
|
+
});
|
|
683
|
+
sections.push(body);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (sections.length === 0) return `${labels.title}\n\n${labels.nothing}`;
|
|
688
|
+
return [`# ${labels.title}`, '', sections.join('\n\n')].join('\n');
|
|
689
|
+
}
|