pf2e-sage-stats 0.2.9 → 0.2.10
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/dist/app.d.ts +608 -0
- package/dist/app.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/package.json +11 -3
- package/eslint.config.mjs +0 -11
- package/jest.config.ts +0 -11
- package/src/app.ts +0 -878
- package/src/index.ts +0 -612
- package/src/types.d.ts +0 -5
- package/test/app.test.ts +0 -67
- package/tsconfig.json +0 -14
package/src/app.ts
DELETED
|
@@ -1,878 +0,0 @@
|
|
|
1
|
-
import zod from 'zod';
|
|
2
|
-
import { TSV } from 'tsv';
|
|
3
|
-
import { capitalize, entries, startCase, toLower, kebabCase, keys, difference, groupBy, mapValues } from 'lodash';
|
|
4
|
-
import dedent from 'dedent-js';
|
|
5
|
-
import abbreviate from 'abbreviate';
|
|
6
|
-
import pluralize from 'pluralize';
|
|
7
|
-
import { JSDOM } from 'jsdom';
|
|
8
|
-
import { readdir, rename, stat } from 'fs/promises';
|
|
9
|
-
|
|
10
|
-
const schema = zod.object({
|
|
11
|
-
name: zod.string(),
|
|
12
|
-
alias: zod.string().optional(),
|
|
13
|
-
level: zod.coerce.number().default(0),
|
|
14
|
-
maxhp: zod.coerce.number().default(0),
|
|
15
|
-
attributes: zod.object({
|
|
16
|
-
strength: zod.coerce.number().default(0),
|
|
17
|
-
dexterity: zod.coerce.number().default(0),
|
|
18
|
-
constitution: zod.coerce.number().default(0),
|
|
19
|
-
intelligence: zod.coerce.number().default(0),
|
|
20
|
-
wisdom: zod.coerce.number().default(0),
|
|
21
|
-
charisma: zod.coerce.number().default(0),
|
|
22
|
-
}).default({}),
|
|
23
|
-
saves: zod.object({
|
|
24
|
-
fortitude: zod.coerce.number().default(0),
|
|
25
|
-
reflex: zod.coerce.number().default(0),
|
|
26
|
-
will: zod.coerce.number().default(0),
|
|
27
|
-
}).default({}),
|
|
28
|
-
ac: zod.coerce.number().default(10),
|
|
29
|
-
perception: zod.coerce.number().default(0),
|
|
30
|
-
perceptionInfo: zod.array(zod.string()).default([]),
|
|
31
|
-
initiativeInfo: zod.array(zod.string()).default([]),
|
|
32
|
-
skills: zod.object({
|
|
33
|
-
acrobatics: zod.coerce.number().optional(),
|
|
34
|
-
arcana: zod.coerce.number().optional(),
|
|
35
|
-
athletics: zod.coerce.number().optional(),
|
|
36
|
-
crafting: zod.coerce.number().optional(),
|
|
37
|
-
deception: zod.coerce.number().optional(),
|
|
38
|
-
diplomacy: zod.coerce.number().optional(),
|
|
39
|
-
intimidation: zod.coerce.number().optional(),
|
|
40
|
-
medicine: zod.coerce.number().optional(),
|
|
41
|
-
nature: zod.coerce.number().optional(),
|
|
42
|
-
occultism: zod.coerce.number().optional(),
|
|
43
|
-
performance: zod.coerce.number().optional(),
|
|
44
|
-
religion: zod.coerce.number().optional(),
|
|
45
|
-
society: zod.coerce.number().optional(),
|
|
46
|
-
stealth: zod.coerce.number().optional(),
|
|
47
|
-
survival: zod.coerce.number().optional(),
|
|
48
|
-
thievery: zod.coerce.number().optional(),
|
|
49
|
-
piloting: zod.coerce.number().optional(),
|
|
50
|
-
computers: zod.coerce.number().optional(),
|
|
51
|
-
}).default({}),
|
|
52
|
-
lores: zod.record(zod.string(), zod.object({
|
|
53
|
-
mod: zod.coerce.number().default(0),
|
|
54
|
-
name: zod.string(),
|
|
55
|
-
info: zod.array(zod.string()).default([]),
|
|
56
|
-
})).default({}),
|
|
57
|
-
melee: zod.record(zod.string(), zod.object({
|
|
58
|
-
mod: zod.coerce.number().default(0),
|
|
59
|
-
desc: zod.string(),
|
|
60
|
-
damage: zod.string().optional(),
|
|
61
|
-
})).default({}),
|
|
62
|
-
ranged: zod.record(zod.string(), zod.object({
|
|
63
|
-
mod: zod.coerce.number().default(0),
|
|
64
|
-
desc: zod.string(),
|
|
65
|
-
damage: zod.string().optional(),
|
|
66
|
-
})).default({}),
|
|
67
|
-
spells: zod.object({
|
|
68
|
-
attack: zod.coerce.number().optional(),
|
|
69
|
-
dc: zod.coerce.number().optional(),
|
|
70
|
-
}).default({}),
|
|
71
|
-
extra: zod.record(zod.string(), zod.coerce.number()).default({}),
|
|
72
|
-
extraDCs: zod.record(zod.string(), zod.coerce.number()).default({}),
|
|
73
|
-
extraDice: zod.record(zod.string(), zod.coerce.string()).default({}),
|
|
74
|
-
classDC: zod.coerce.number().default(10),
|
|
75
|
-
untrained: zod.coerce.number().default(0),
|
|
76
|
-
bump: zod.object({
|
|
77
|
-
default: zod.coerce.number().default(0),
|
|
78
|
-
attack: zod.coerce.number().optional(),
|
|
79
|
-
ac: zod.coerce.number().optional(),
|
|
80
|
-
saves: zod.coerce.number().optional(),
|
|
81
|
-
skills: zod.coerce.number().optional(),
|
|
82
|
-
spells: zod.coerce.number().optional(),
|
|
83
|
-
perception: zod.coerce.number().optional(),
|
|
84
|
-
hp: zod.coerce.number().optional(),
|
|
85
|
-
}).default({ default: 0 }),
|
|
86
|
-
bullwark: zod.coerce.number().default(0),
|
|
87
|
-
saveInfo: zod.object({
|
|
88
|
-
fortitude: zod.array(zod.string()).default([]),
|
|
89
|
-
reflex: zod.array(zod.string()).default([]),
|
|
90
|
-
will: zod.array(zod.string()).default([]),
|
|
91
|
-
}).default({}),
|
|
92
|
-
skillInfo: zod.object({
|
|
93
|
-
acrobatics: zod.array(zod.string()).optional(),
|
|
94
|
-
arcana: zod.array(zod.string()).optional(),
|
|
95
|
-
athletics: zod.array(zod.string()).optional(),
|
|
96
|
-
crafting: zod.array(zod.string()).optional(),
|
|
97
|
-
deception: zod.array(zod.string()).optional(),
|
|
98
|
-
diplomacy: zod.array(zod.string()).optional(),
|
|
99
|
-
intimidation: zod.array(zod.string()).optional(),
|
|
100
|
-
medicine: zod.array(zod.string()).optional(),
|
|
101
|
-
nature: zod.array(zod.string()).optional(),
|
|
102
|
-
occultism: zod.array(zod.string()).optional(),
|
|
103
|
-
performance: zod.array(zod.string()).optional(),
|
|
104
|
-
religion: zod.array(zod.string()).optional(),
|
|
105
|
-
society: zod.array(zod.string()).optional(),
|
|
106
|
-
stealth: zod.array(zod.string()).optional(),
|
|
107
|
-
survival: zod.array(zod.string()).optional(),
|
|
108
|
-
thievery: zod.array(zod.string()).optional(),
|
|
109
|
-
piloting: zod.array(zod.string()).optional(),
|
|
110
|
-
computers: zod.array(zod.string()).optional(),
|
|
111
|
-
}).default({}),
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
export type Schema = zod.infer<typeof schema>;
|
|
115
|
-
|
|
116
|
-
export const stub: Required<Schema> = {
|
|
117
|
-
name: 'name',
|
|
118
|
-
alias: 'nm',
|
|
119
|
-
level: 0,
|
|
120
|
-
maxhp: 0,
|
|
121
|
-
attributes: {
|
|
122
|
-
strength: 0,
|
|
123
|
-
dexterity: 0,
|
|
124
|
-
constitution: 0,
|
|
125
|
-
intelligence: 0,
|
|
126
|
-
wisdom: 0,
|
|
127
|
-
charisma: 0,
|
|
128
|
-
},
|
|
129
|
-
saves: {
|
|
130
|
-
fortitude: 0,
|
|
131
|
-
reflex: 0,
|
|
132
|
-
will: 0,
|
|
133
|
-
},
|
|
134
|
-
ac: 10,
|
|
135
|
-
perception: 0,
|
|
136
|
-
perceptionInfo: [],
|
|
137
|
-
initiativeInfo: [],
|
|
138
|
-
skills: {
|
|
139
|
-
acrobatics: 0,
|
|
140
|
-
arcana: 0,
|
|
141
|
-
athletics: 0,
|
|
142
|
-
crafting: 0,
|
|
143
|
-
deception: 0,
|
|
144
|
-
diplomacy: 0,
|
|
145
|
-
intimidation: 0,
|
|
146
|
-
medicine: 0,
|
|
147
|
-
nature: 0,
|
|
148
|
-
occultism: 0,
|
|
149
|
-
performance: 0,
|
|
150
|
-
religion: 0,
|
|
151
|
-
society: 0,
|
|
152
|
-
stealth: 0,
|
|
153
|
-
survival: 0,
|
|
154
|
-
thievery: 0,
|
|
155
|
-
piloting: 0,
|
|
156
|
-
computers: 0,
|
|
157
|
-
},
|
|
158
|
-
lores: {},
|
|
159
|
-
melee: {
|
|
160
|
-
fist: { mod: 7, desc: 'fist (agile, finesse)', damage: '1d4 bludgeoning' }
|
|
161
|
-
},
|
|
162
|
-
ranged: {},
|
|
163
|
-
spells: {},
|
|
164
|
-
extra: {},
|
|
165
|
-
extraDCs: {},
|
|
166
|
-
extraDice: {},
|
|
167
|
-
classDC: 10,
|
|
168
|
-
untrained: 0,
|
|
169
|
-
bump: { default: 0 },
|
|
170
|
-
bullwark: 0,
|
|
171
|
-
saveInfo: {
|
|
172
|
-
fortitude: [],
|
|
173
|
-
reflex: [],
|
|
174
|
-
will: [],
|
|
175
|
-
},
|
|
176
|
-
skillInfo: {},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const childSchema = zod.object({
|
|
180
|
-
name: zod.string().default(""),
|
|
181
|
-
alias: zod.string().default(""),
|
|
182
|
-
id: zod.string().default(""),
|
|
183
|
-
hp: zod.coerce.number().default(0),
|
|
184
|
-
temphp: zod.coerce.number().default(0),
|
|
185
|
-
maxhp: zod.coerce.number().default(10),
|
|
186
|
-
conditions: zod.string().default(''),
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
export type ChildSchema = zod.infer<typeof childSchema>;
|
|
190
|
-
|
|
191
|
-
export const charSchema = zod.object({
|
|
192
|
-
init: zod.coerce.number().default(0),
|
|
193
|
-
foe: zod.boolean().default(false),
|
|
194
|
-
state: zod.union([zod.literal('empty'), zod.literal('arrow'), zod.literal('check'), zod.literal('cross')]).default('empty'),
|
|
195
|
-
name: zod.string().default(""),
|
|
196
|
-
alias: zod.string().default(""),
|
|
197
|
-
id: zod.string().default(""),
|
|
198
|
-
hp: zod.coerce.number().default(0),
|
|
199
|
-
temphp: zod.coerce.number().default(0),
|
|
200
|
-
maxhp: zod.coerce.number().default(10),
|
|
201
|
-
conditions: zod.string().default(''),
|
|
202
|
-
children: zod.array(childSchema).default([]),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
export type CharSchema = zod.infer<typeof charSchema>;
|
|
206
|
-
|
|
207
|
-
export const flatMap: Record<string, string> = {
|
|
208
|
-
...([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v): [string, string] => (
|
|
209
|
-
[`${v}`, `d20 >= ${v} flat;`]
|
|
210
|
-
)).reduce<Record<string, string>>((p, [k, v]) => { p[k] = v; return p }, {})),
|
|
211
|
-
c: 'd20 >= 5 flat;',
|
|
212
|
-
concealed: 'd20 >= 5 flat;',
|
|
213
|
-
h: 'd20 >= 11 flat;',
|
|
214
|
-
hidden: 'd20 >= 11 flat;',
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export const diceMap: Record<string, string> = {
|
|
218
|
-
...([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20].map((v): [string, string] => (
|
|
219
|
-
[`${v}`, `(${v})`]
|
|
220
|
-
)).reduce<Record<string, string>>((p, [k, v]) => { p[k] = v; return p }, {})),
|
|
221
|
-
a: '+2',
|
|
222
|
-
adv: '+2',
|
|
223
|
-
advantage: '+2',
|
|
224
|
-
d: '-2',
|
|
225
|
-
dis: '-2',
|
|
226
|
-
disadvantage: '-2',
|
|
227
|
-
f: '+2',
|
|
228
|
-
for: '+2',
|
|
229
|
-
fort: '+2',
|
|
230
|
-
fortune: '+2',
|
|
231
|
-
m: '-2',
|
|
232
|
-
mis: '-2',
|
|
233
|
-
misfortune: '-2',
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
export const fromatMap = (name: string, map: Record<string, string>) => {
|
|
237
|
-
return TSV.stringify([{
|
|
238
|
-
name,
|
|
239
|
-
...map,
|
|
240
|
-
}]);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const dcByLevel = [13, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 42, 44, 46, 48, 50]
|
|
244
|
-
|
|
245
|
-
export const formatJSON = (stats: Schema): string => JSON.stringify(stats, undefined, 2);
|
|
246
|
-
export const parseJSON = (json: string): Schema => schema.parse(JSON.parse(json));
|
|
247
|
-
|
|
248
|
-
export const parseTracker = (json: string): CharSchema[] => zod.array(charSchema).parse(JSON.parse(json));
|
|
249
|
-
|
|
250
|
-
const locateName = (statblock: string): { name: string; level: number } | null => {
|
|
251
|
-
const regex = /^([^()]+?)(\s+\(\d+\))?\s+\S+\s+(-?\d+)$/m;
|
|
252
|
-
|
|
253
|
-
const match = statblock.match(regex);
|
|
254
|
-
|
|
255
|
-
if (match && match[1] && match[3]) {
|
|
256
|
-
return { name: pluralize(startCase(toLower(match[1].replace(/\s+/, ' ').trim())), 1), level: parseInt(match[3]) };
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
const locateInt = <T extends string>(name: T, statblock: string, section: string | null = null, signed: boolean = true, alias?: string): { [k in T]: number } | null => {
|
|
263
|
-
const match = statblock.match(new RegExp(`${section ? `(${section}|,)\\s+` : '()'}${alias ?? capitalize(name)}\\s+(${signed ? '[+-]' : '-?'}\\d+)`))
|
|
264
|
-
|
|
265
|
-
if (match && match[2]) {
|
|
266
|
-
return { [name]: parseInt(match[2]) } as { [k in T]: number };
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const locateInts = (statblock: string, section: string, alias: string, signed: boolean = true): Record<string, { mod: number; name: string; info: string[] }> => {
|
|
273
|
-
const regex = new RegExp(`(${section}|,)([^,]*?)${alias}\\s+(${signed ? '[+-]' : '-?'}\\d+)`, 'g');
|
|
274
|
-
|
|
275
|
-
let matches: RegExpExecArray | null = null;
|
|
276
|
-
const output: [string, string, number][] = [];
|
|
277
|
-
// eslint-disable-next-line no-cond-assign
|
|
278
|
-
while (matches = regex.exec(statblock)) {
|
|
279
|
-
const [,, name, mod] = matches;
|
|
280
|
-
|
|
281
|
-
if (name && mod) {
|
|
282
|
-
output.push([
|
|
283
|
-
name.toLowerCase().trim().replace(/\s+/g, '-'),
|
|
284
|
-
name.trim(),
|
|
285
|
-
parseInt(mod),
|
|
286
|
-
]);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return output.reduce<Record<string, { mod: number; name: string; info: string[] }>>((p, [key, name, value]) => { p[key] = { mod: value, name: name, info: [] }; return p; }, {});
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const locateIntsAfter = (statblock: string, alias: string, signed: boolean = true): Record<string, { mod: number; name: string; info: string[] }> => {
|
|
294
|
-
const regex = new RegExp(`${alias}([\\s\\S]*?)(${signed ? '[+-]' : '-?'}\\d+)`, 'g');
|
|
295
|
-
|
|
296
|
-
let matches: RegExpExecArray | null = null;
|
|
297
|
-
const output: [string, string, number][] = [];
|
|
298
|
-
// eslint-disable-next-line no-cond-assign
|
|
299
|
-
while (matches = regex.exec(statblock)) {
|
|
300
|
-
const [,name, mod] = matches;
|
|
301
|
-
|
|
302
|
-
if (name && mod) {
|
|
303
|
-
output.push([
|
|
304
|
-
name.toLowerCase().trim().replace(/\s+/g, '-'),
|
|
305
|
-
name.trim(),
|
|
306
|
-
parseInt(mod),
|
|
307
|
-
]);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return output.reduce<Record<string, { mod: number; name: string; info: string[] }>>((p, [key, name, value]) => { p[key] = { mod: value, name: name, info: [] }; return p; }, {});
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const locateStrikes = (statblock: string, alias: string): Record<string, Schema['melee'][string]> => {
|
|
315
|
-
const regex = new RegExp(`${alias}(\\s+\\[.+\\])?\\s+(.+?)\\s+(\\(x\\d+\\)\\s+)?([+-]\\d+)\\s*([\\S\\s]*?),\\s+(Damage|Effect)\\s+(\\S+\\s+\\S+.*?)(?=$|\\s+Melee|\\s+Ranged)`, 'gm');
|
|
316
|
-
|
|
317
|
-
let matches: RegExpExecArray | null = null;
|
|
318
|
-
const output: [string, number, string, string][] = [];
|
|
319
|
-
// eslint-disable-next-line no-cond-assign
|
|
320
|
-
while (matches = regex.exec(statblock)) {
|
|
321
|
-
const [, , name, , attack, traits, , dice] = matches;
|
|
322
|
-
|
|
323
|
-
if (name && attack && dice) {
|
|
324
|
-
const _name = name.toLowerCase()
|
|
325
|
-
.replace(/\+\d/g, '')
|
|
326
|
-
.replace(/Weapon\s+Striking(\s+\((Greater|Major)\))?/gi, '')
|
|
327
|
-
.replace(/((Greater|Major)\s+)?Striking/gi, '')
|
|
328
|
-
.replace(/\(.*\)/gi, '')
|
|
329
|
-
.replace(/\s+/g, ' ')
|
|
330
|
-
.trim();
|
|
331
|
-
|
|
332
|
-
const bps = /(?<=[^\w']|^)[BbPpSs](?=[^\w]|$)/g;
|
|
333
|
-
|
|
334
|
-
let _traits = traits && traits.toLowerCase()
|
|
335
|
-
.replace(/\(\)/gi, '')
|
|
336
|
-
.replace(/\s+/g, ' ')
|
|
337
|
-
.replace(bps, (m) => m.toUpperCase())
|
|
338
|
-
.replace(/1d/, 'd')
|
|
339
|
-
.replace(/jousting\s+d(\d+)/g, 'jousting$1')
|
|
340
|
-
.replace(/boost\s+d(\d+)/g, 'boost$1')
|
|
341
|
-
.trim();
|
|
342
|
-
|
|
343
|
-
const _dice = dice
|
|
344
|
-
.replace(/\s+/g, ' ')
|
|
345
|
-
.replace(bps, (m) => ({ b: 'bludgeoning', p: 'piercing', s: 'slashing' }[m.toLowerCase()] ?? m))
|
|
346
|
-
.replace(/Fire/g, 'fire')
|
|
347
|
-
.replace(/Cold/g, 'cold')
|
|
348
|
-
.replace(/Electricity/g, 'electricity')
|
|
349
|
-
.replace(/Sonic/g, 'sonic')
|
|
350
|
-
.replace(/Spirit/g, 'spirit')
|
|
351
|
-
.replace(/Acid/g, 'acid')
|
|
352
|
-
.replace(/[pP]lus\s(\d+d)/g, '+$1')
|
|
353
|
-
.trim();
|
|
354
|
-
|
|
355
|
-
const twoHand = _traits.match(/(two-hand|two-handed)\s+(d\d+)/);
|
|
356
|
-
|
|
357
|
-
if (twoHand && twoHand[2]) {
|
|
358
|
-
_traits = _traits.replace(/(two-hand|two-handed)\s+d\d+/g, 'two-hand');
|
|
359
|
-
|
|
360
|
-
const dice2h = _dice.replace(/(?<=\d)d\d+/, twoHand[2]);
|
|
361
|
-
|
|
362
|
-
output.push([
|
|
363
|
-
_name.replace(/\s+/g, '-') + '-2h',
|
|
364
|
-
parseInt(attack),
|
|
365
|
-
`2h ${_traits ? `${_name} ${_traits}` : _name}`,
|
|
366
|
-
dice2h,
|
|
367
|
-
], [
|
|
368
|
-
_name.replace(/\s+/g, '-') + '-1h',
|
|
369
|
-
parseInt(attack),
|
|
370
|
-
`1h ${_traits ? `${_name} ${_traits}` : _name}`,
|
|
371
|
-
_dice,
|
|
372
|
-
]);
|
|
373
|
-
} else {
|
|
374
|
-
output.push([
|
|
375
|
-
_name.replace(/\s+/g, '-'),
|
|
376
|
-
parseInt(attack),
|
|
377
|
-
_traits ? `${_name} ${_traits}` : _name,
|
|
378
|
-
_dice,
|
|
379
|
-
]);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return output.reduce<Record<string, Schema['melee'][string]>>((p, [key, m, t, d]) => { p[key] = {
|
|
385
|
-
mod: m,
|
|
386
|
-
desc: t,
|
|
387
|
-
damage: d,
|
|
388
|
-
}; return p; }, {});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
const locateSpells = (statblock: string): Schema['spells'] | null => {
|
|
392
|
-
const match = statblock.match(new RegExp(/Spells\s+DC\s+(\d+)(,\s+[Aa]ttack\s+([+-]\d+))?/));
|
|
393
|
-
|
|
394
|
-
if (match && match[1]) {
|
|
395
|
-
return {
|
|
396
|
-
dc: parseInt(match[1]),
|
|
397
|
-
...(match[3] ? { attack: parseInt(match[3]) } : null)
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
export const parseStatblock = (name: string | null, _statblock: string, alias: string | null): Schema => {
|
|
405
|
-
const defaults = schema.parse({ name: name ?? 'Unknown' });
|
|
406
|
-
|
|
407
|
-
const improvisation = _statblock.match(/Untrained\s+Improvisation/);
|
|
408
|
-
const plate = _statblock.match(/Full\s+Plate/)
|
|
409
|
-
|
|
410
|
-
const statblock = _statblock
|
|
411
|
-
.replace(/^Items.*$/m, '')
|
|
412
|
-
.replace('', '')
|
|
413
|
-
.replace(/–/g, '-') + '\n';
|
|
414
|
-
|
|
415
|
-
const basic = locateName(statblock);
|
|
416
|
-
|
|
417
|
-
const result: Schema = {
|
|
418
|
-
...defaults,
|
|
419
|
-
...basic,
|
|
420
|
-
...(name && { name: name }),
|
|
421
|
-
...{ alias: alias ?? abbreviate(name ?? basic?.name ?? defaults.name, { length: 3 }).toLowerCase() },
|
|
422
|
-
...locateInt('perception', statblock),
|
|
423
|
-
...locateInt('ac', statblock, null, false, 'AC'),
|
|
424
|
-
...locateInt('maxhp', statblock, null, false, 'HP'),
|
|
425
|
-
attributes: {
|
|
426
|
-
...defaults.attributes,
|
|
427
|
-
...locateInt('strength', statblock, null, true, 'Str'),
|
|
428
|
-
...locateInt('dexterity', statblock, null, true, 'Dex'),
|
|
429
|
-
...locateInt('constitution', statblock, null, true, 'Con'),
|
|
430
|
-
...locateInt('intelligence', statblock, null, true, 'Int'),
|
|
431
|
-
...locateInt('wisdom', statblock, null, true, 'Wis'),
|
|
432
|
-
...locateInt('charisma', statblock, null, true, 'Cha'),
|
|
433
|
-
},
|
|
434
|
-
saves: {
|
|
435
|
-
...defaults.saves,
|
|
436
|
-
...locateInt('fortitude', statblock, null, true, 'Fortitude'),
|
|
437
|
-
...locateInt('reflex', statblock, null, true, 'Reflex'),
|
|
438
|
-
...locateInt('fortitude', statblock, null, true, 'Fort'),
|
|
439
|
-
...locateInt('reflex', statblock, null, true, 'Ref'),
|
|
440
|
-
...locateInt('will', statblock, null, true, 'Will'),
|
|
441
|
-
},
|
|
442
|
-
skills: {
|
|
443
|
-
...defaults.skills,
|
|
444
|
-
...locateInt('acrobatics', statblock, 'Skills'),
|
|
445
|
-
...locateInt('arcana', statblock, 'Skills'),
|
|
446
|
-
...locateInt('athletics', statblock, 'Skills'),
|
|
447
|
-
...locateInt('crafting', statblock, 'Skills'),
|
|
448
|
-
...locateInt('deception', statblock, 'Skills'),
|
|
449
|
-
...locateInt('diplomacy', statblock, 'Skills'),
|
|
450
|
-
...locateInt('intimidation', statblock, 'Skills'),
|
|
451
|
-
...locateInt('medicine', statblock, 'Skills'),
|
|
452
|
-
...locateInt('nature', statblock, 'Skills'),
|
|
453
|
-
...locateInt('occultism', statblock, 'Skills'),
|
|
454
|
-
...locateInt('performance', statblock, 'Skills'),
|
|
455
|
-
...locateInt('religion', statblock, 'Skills'),
|
|
456
|
-
...locateInt('society', statblock, 'Skills'),
|
|
457
|
-
...locateInt('stealth', statblock, 'Skills'),
|
|
458
|
-
...locateInt('survival', statblock, 'Skills'),
|
|
459
|
-
...locateInt('thievery', statblock, 'Skills'),
|
|
460
|
-
...locateInt('piloting', statblock, 'Skills'),
|
|
461
|
-
...locateInt('computers', statblock, 'Skills'),
|
|
462
|
-
},
|
|
463
|
-
lores: {
|
|
464
|
-
...locateInts(statblock, 'Skills', 'Lore'),
|
|
465
|
-
...locateIntsAfter(statblock, 'Lore:')
|
|
466
|
-
},
|
|
467
|
-
melee: {
|
|
468
|
-
...locateStrikes(statblock, 'Melee'),
|
|
469
|
-
},
|
|
470
|
-
ranged: {
|
|
471
|
-
...locateStrikes(statblock, 'Ranged'),
|
|
472
|
-
},
|
|
473
|
-
spells: {
|
|
474
|
-
...locateSpells(statblock),
|
|
475
|
-
},
|
|
476
|
-
extra: {},
|
|
477
|
-
extraDCs: {
|
|
478
|
-
...locateInt('stealth', statblock, null, false, 'Stealth DC'),
|
|
479
|
-
},
|
|
480
|
-
extraDice: {},
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
result.untrained = improvisation ? (result.level >= 7 ? result.level : result.level >= 5 ? result.level - 1 : result.level - 2) : 0;
|
|
484
|
-
result.bullwark = plate ? Math.max(3 - result.attributes.dexterity, 0) : 0;
|
|
485
|
-
|
|
486
|
-
return result;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
const dc2DC = (secret: boolean, bump: number) => ([key, value]: [string | number, number]): [string, string] => [`dc.${key}`, secret ? `||${value + bump}||` : `${value + bump}`];
|
|
490
|
-
const mod2DC = (secret: boolean, bump: number) => ([key, value]: [string | number, number]): [string, string] => [`dc.${key}`, secret ? `||${10 + value + bump}||` : `${10 + value + bump}`];
|
|
491
|
-
const toLoreMod = ([key, value]: [string | number, { mod: number; name: string; }]): [string, number] => [`lore.${key}`, value.mod];
|
|
492
|
-
const toLoreName = ([key, value]: [string | number, { mod: number; name: string; }]): [string, string] => [`lore.${key}.name`, value.name];
|
|
493
|
-
const toLoreInfo = ([key, value]: [string | number, { mod: number; name: string; info: string[] }]): [string, string] => [`lore.${key}.info`, `\`(${value.info.join(', ')})\``];
|
|
494
|
-
const toMelee = ([key, value]: [string, Schema['melee'][string]]): [string, number | string][] => [
|
|
495
|
-
[`melee.${key}`, value.mod],
|
|
496
|
-
[`melee.${key}.desc`, value.desc],
|
|
497
|
-
...(value.damage ? [[`melee.${key}.damage`, value.damage] as [string, string]] : []),
|
|
498
|
-
];
|
|
499
|
-
|
|
500
|
-
const toRanged = ([key, value]: [string, Schema['ranged'][string]]): [string, number | string][] => [
|
|
501
|
-
[`ranged.${key}`, value.mod],
|
|
502
|
-
[`ranged.${key}.desc`, value.desc],
|
|
503
|
-
...(value.damage ? [[`ranged.${key}.damage`, value.damage] as [string, string]] : []),
|
|
504
|
-
];
|
|
505
|
-
|
|
506
|
-
export const flatten = (stats: Schema, secretDC: boolean = false, defaultSkills: boolean = false): Record<string, string | number> => {
|
|
507
|
-
const untrained = stats.untrained;
|
|
508
|
-
const skills = defaultSkills ? {
|
|
509
|
-
acrobatics: untrained + stats.attributes.dexterity,
|
|
510
|
-
arcana: untrained + stats.attributes.intelligence,
|
|
511
|
-
athletics: untrained + stats.attributes.strength,
|
|
512
|
-
crafting: untrained + stats.attributes.intelligence,
|
|
513
|
-
deception: untrained + stats.attributes.charisma,
|
|
514
|
-
diplomacy: untrained + stats.attributes.charisma,
|
|
515
|
-
intimidation: untrained + stats.attributes.charisma,
|
|
516
|
-
medicine: untrained + stats.attributes.wisdom,
|
|
517
|
-
nature: untrained + stats.attributes.wisdom,
|
|
518
|
-
occultism: untrained + stats.attributes.intelligence,
|
|
519
|
-
performance: untrained + stats.attributes.charisma,
|
|
520
|
-
religion: untrained + stats.attributes.wisdom,
|
|
521
|
-
society: untrained + stats.attributes.intelligence,
|
|
522
|
-
stealth: untrained + stats.attributes.dexterity,
|
|
523
|
-
survival: untrained + stats.attributes.wisdom,
|
|
524
|
-
thievery: untrained + stats.attributes.dexterity,
|
|
525
|
-
piloting: untrained + stats.attributes.dexterity,
|
|
526
|
-
computers: untrained + stats.attributes.intelligence,
|
|
527
|
-
...stats.skills,
|
|
528
|
-
} : stats.skills;
|
|
529
|
-
|
|
530
|
-
const lores = defaultSkills ? {
|
|
531
|
-
...stats.lores,
|
|
532
|
-
other: {
|
|
533
|
-
mod: untrained + stats.attributes.intelligence,
|
|
534
|
-
name: "Other",
|
|
535
|
-
info: ['untrained']
|
|
536
|
-
}
|
|
537
|
-
} : stats.lores
|
|
538
|
-
|
|
539
|
-
let melee = entries(stats.melee).map(([k, v]): [string, typeof v] => [k, {
|
|
540
|
-
mod: v.mod + (stats.bump.attack ?? stats.bump.default),
|
|
541
|
-
desc: v.desc,
|
|
542
|
-
damage: stats.bump.default > 0 ? `${v.damage} +${stats.bump.default}` : v.damage,
|
|
543
|
-
}]);
|
|
544
|
-
if (melee.length > 0) {
|
|
545
|
-
melee = [
|
|
546
|
-
['default', melee[0][1]],
|
|
547
|
-
...melee,
|
|
548
|
-
];
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
let ranged = entries(stats.ranged).map(([k, v]): [string, typeof v] => [k, {
|
|
552
|
-
mod: v.mod + (stats.bump.attack ?? stats.bump.default),
|
|
553
|
-
desc: v.desc,
|
|
554
|
-
damage: v.damage && stats.bump.default > 0 ? `${v.damage} +${stats.bump.default}` : v.damage,
|
|
555
|
-
}]);
|
|
556
|
-
if (ranged.length > 0) {
|
|
557
|
-
ranged = [
|
|
558
|
-
['default', ranged[0][1]],
|
|
559
|
-
...ranged,
|
|
560
|
-
];
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
const maxhp = stats.bump.default > 0 ? (stats.bump.hp ? (stats.bump.hp + stats.maxhp) : Math.max(Math.floor(stats.maxhp * 1.1), stats.maxhp + 10)) : stats.maxhp;
|
|
564
|
-
|
|
565
|
-
const saveInfo = {
|
|
566
|
-
...stats.saveInfo,
|
|
567
|
-
reflex: stats.bullwark > 0 ? [...stats.saveInfo.reflex, `+${stats.bullwark} more vs damage`] : stats.saveInfo.reflex,
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const untrainedSkillInfo = entries(mapValues(groupBy(difference(keys(skills), keys(stats.skills)), (k) => k), () => ['untrained']));
|
|
571
|
-
const specifiedSkillInfo = entries(stats.skillInfo);
|
|
572
|
-
|
|
573
|
-
const skillInfo = mapValues(groupBy([...untrainedSkillInfo, ...specifiedSkillInfo], ([k]) => k), (list) => list.reduce<string[]>((p, [, v]) => [...p, ...v], []))
|
|
574
|
-
|
|
575
|
-
return [
|
|
576
|
-
['name', stats.name],
|
|
577
|
-
...(stats.alias ? [['alias', stats.alias]] : []),
|
|
578
|
-
['gamesystem', 'pf2e'],
|
|
579
|
-
['level', stats.level],
|
|
580
|
-
['lvl', stats.level],
|
|
581
|
-
['hp', maxhp],
|
|
582
|
-
['maxhp', maxhp],
|
|
583
|
-
...entries(stats.attributes),
|
|
584
|
-
...entries(stats.attributes).map(([key, value]) => [key.substring(0,3), value]),
|
|
585
|
-
['ac', secretDC ? `||${stats.ac + (stats.bump.ac ?? stats.bump.default)}||` : stats.ac + (stats.bump.ac ?? stats.bump.default)],
|
|
586
|
-
...entries(stats.saves).map(([k, v]) => [k, v + (stats.bump.saves ?? stats.bump.default)]),
|
|
587
|
-
['fort', stats.saves.fortitude + (stats.bump.saves ?? stats.bump.default)],
|
|
588
|
-
['ref', stats.saves.reflex + (stats.bump.saves ?? stats.bump.default)],
|
|
589
|
-
['perception', stats.perception + (stats.bump.perception ?? stats.bump.default)],
|
|
590
|
-
...entries(skills.performance ? { ...skills, perfomance: skills.performance } : skills).map(([k, v]) => [k, v + (stats.bump.skills ?? stats.bump.default)]),
|
|
591
|
-
...entries(lores).map(toLoreMod).map(([k, v]) => [k, v + (stats.bump.skills ?? stats.bump.default)]),
|
|
592
|
-
...entries(lores).map(toLoreName),
|
|
593
|
-
...entries(lores).filter(([, v]) => v.info.length > 0).map(toLoreInfo),
|
|
594
|
-
...melee.flatMap(toMelee),
|
|
595
|
-
...ranged.flatMap(toRanged),
|
|
596
|
-
...entries(stats.extra),
|
|
597
|
-
...(stats.spells.attack ? [['spells', stats.spells.attack + (stats.bump.attack ?? stats.bump.default)]] : []),
|
|
598
|
-
...(stats.spells.dc ? [dc2DC(secretDC, stats.bump.spells ?? stats.bump.default)(['spells', stats.spells.dc])] : []),
|
|
599
|
-
...(stats.classDC ? [['classDC', secretDC ? `||${stats.classDC + stats.bump.default}||` : `${stats.classDC + stats.bump.default}`]] : []),
|
|
600
|
-
...(stats.classDC ? [dc2DC(secretDC, stats.bump.default)(['class', stats.classDC])] : []),
|
|
601
|
-
dc2DC(secretDC, stats.bump.default)(['level', dcByLevel[Math.max(Math.min(stats.level + 1, dcByLevel.length - 1), 0)]]),
|
|
602
|
-
dc2DC(secretDC, stats.bump.ac ?? stats.bump.default)(['ac', stats.ac]),
|
|
603
|
-
...entries(stats.extraDCs).map(dc2DC(secretDC, stats.bump.default)),
|
|
604
|
-
...entries(stats.extraDice),
|
|
605
|
-
...(secretDC ? [
|
|
606
|
-
...entries(stats.saves).map(mod2DC(true, (stats.bump.saves ?? stats.bump.default))),
|
|
607
|
-
mod2DC(true, stats.bump.default)(['perception', stats.perception]),
|
|
608
|
-
mod2DC(true, (stats.bump.saves ?? stats.bump.default))(['fort', stats.saves.fortitude]),
|
|
609
|
-
mod2DC(true, (stats.bump.saves ?? stats.bump.default))(['ref', stats.saves.reflex]),
|
|
610
|
-
...entries(skills).map(mod2DC(true, (stats.bump.skills ?? stats.bump.default))),
|
|
611
|
-
...entries(stats.extra).map(mod2DC(true, stats.bump.default)),
|
|
612
|
-
] : []),
|
|
613
|
-
...(stats.perceptionInfo.length > 0 ? [
|
|
614
|
-
[`perception.info`, `\`(${stats.perceptionInfo.join(', ')})\``]
|
|
615
|
-
] : []),
|
|
616
|
-
...(stats.initiativeInfo.length > 0 ? [
|
|
617
|
-
[`initiative.info`, `\`(${stats.initiativeInfo.join(', ')})\``]
|
|
618
|
-
] : []),
|
|
619
|
-
...entries(saveInfo).filter(([, v]) => v.length > 0).map(([k, v]) => [`${k}.info`, `\`(${v.join(', ')})\``]),
|
|
620
|
-
...entries(skillInfo).filter(([, v]) => v.length > 0).map(([k, v]) => [`${k}.info`, `\`(${v.join(', ')})\``]),
|
|
621
|
-
['out', secretDC ? 'xs' : 'l'],
|
|
622
|
-
].reduce<Record<string | number, string | number>>((p, [key, value]) => { p[key] = value; return p }, {});
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
export const formatTSV = (stats: Schema, secretDC: boolean = false, defaultSkills: boolean = false): string => (
|
|
626
|
-
TSV.stringify([flatten(stats, secretDC, defaultSkills)])
|
|
627
|
-
);
|
|
628
|
-
|
|
629
|
-
export const formatCommand = (stats: Schema, secretDC: boolean = false, defaultSkills: boolean = false): string => (
|
|
630
|
-
Object.entries(flatten(stats, secretDC, defaultSkills)).map(([k, v]) => `${k}="${v}"`).join(' ')
|
|
631
|
-
);
|
|
632
|
-
|
|
633
|
-
export const formatTable = (table: string, season: string, scenario: string, _name: string, gm: string, players: string) => {
|
|
634
|
-
const name = _name.replace(/[\s-_]/g, ' ').replace(/[^a-zA-Z0-9 ]/g, '');
|
|
635
|
-
|
|
636
|
-
const gameName = `PF2 T${table} S${season} ${String(scenario).padStart(2, '0')} ${name}`;
|
|
637
|
-
const tableName = `pf2-t${table}-s${season}${String(scenario).padStart(2, '0')}-${kebabCase(name)}`;
|
|
638
|
-
|
|
639
|
-
return dedent`
|
|
640
|
-
\`\`\`
|
|
641
|
-
@TableBot create "${gameName}" --gm ${gm} --players ${players} --table-name ${tableName} --ooc-table-name ooc-${tableName} --category Game Tables
|
|
642
|
-
\`\`\`
|
|
643
|
-
\`\`\`
|
|
644
|
-
sage! game create name="${gameName}" gameSystem="pf2e" ic=" #${tableName} " ooc=" #ooc-${tableName} " gms=" ${gm} " players=" @${gameName} " dialogPost="post" diceSecret="gm" diceCrit="timestwo" diceOutput=M gmCharName="Хронист"
|
|
645
|
-
\`\`\`
|
|
646
|
-
`;
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
const _formatHP = (hp: number, maxhp: number) => {
|
|
650
|
-
const base32 = Math.ceil(hp * 32 / maxhp);
|
|
651
|
-
|
|
652
|
-
const slabs = Math.floor(base32 / 8);
|
|
653
|
-
const tail = base32 % 8;
|
|
654
|
-
|
|
655
|
-
const tails = [' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉'];
|
|
656
|
-
|
|
657
|
-
return `▕${new Array(slabs).fill(0).map(() => '█').join('')}${[tails[tail], ...new Array(3).fill(0).map(() => ' ')].slice(0, 4 - slabs).join('')}▏`;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
export const formatHP = (arg: string) => {
|
|
661
|
-
const match = arg.match(/^(m)?(\d+)\/(\d+)$/);
|
|
662
|
-
|
|
663
|
-
if (!match) {
|
|
664
|
-
throw new Error('No match');
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
const negative = !!match[1];
|
|
668
|
-
const hp = parseInt(match[2]);
|
|
669
|
-
const maxhp = parseInt(match[3]);
|
|
670
|
-
|
|
671
|
-
return _formatHP(negative ? maxhp - hp : hp, maxhp);
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
export const newtracker = (status: string) => {
|
|
675
|
-
const regex = /((.+)\s+\((\d+)\/(\d+)\s+HP\):(.*)(\n>(.+)\s+\((\d+)\/(\d+)\s+HP\):(.*))*)/gm;
|
|
676
|
-
|
|
677
|
-
const match = status.match(regex);
|
|
678
|
-
|
|
679
|
-
const tracker = zod.array(charSchema).parse([]);
|
|
680
|
-
|
|
681
|
-
for (const m of match ?? []) {
|
|
682
|
-
const mmatch = m.match(/([^>]+)\s+\((\d+)\/(\d+)\s+HP\):(.*)/)
|
|
683
|
-
const cmatch = m.match(/>\s+(\S+)\s+\((\d+)\/(\d+)\s+HP\):(.*)/g)
|
|
684
|
-
|
|
685
|
-
const char = charSchema.parse({
|
|
686
|
-
name: mmatch?.[1],
|
|
687
|
-
hp: mmatch?.[2],
|
|
688
|
-
maxhp: mmatch?.[3],
|
|
689
|
-
conditions: mmatch?.[4]?.trim(),
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
for (const c of cmatch ?? []) {
|
|
693
|
-
const fmatch = c.match(/>\s+(\S+)\s+\((\d+)\/(\d+)\s+HP\):(.*)/)
|
|
694
|
-
|
|
695
|
-
const child = childSchema.parse({
|
|
696
|
-
name: fmatch?.[1],
|
|
697
|
-
hp: fmatch?.[2],
|
|
698
|
-
maxhp: fmatch?.[3],
|
|
699
|
-
conditions: fmatch?.[4]?.trim(),
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
char.children.push(child);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
tracker.push(char);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
return tracker;
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
export const formatTracker = (tracker: CharSchema[]) => {
|
|
712
|
-
const aliasSpace = (t: { alias: string }) => (t.alias.length > 0 ? 0 : 5);
|
|
713
|
-
const nameLengthWithAlias = (t: { name: string, alias: string }) => t.name.length - aliasSpace(t);
|
|
714
|
-
|
|
715
|
-
const nameLength = tracker.reduce((p, c) => {
|
|
716
|
-
const length = c.children.reduce((pp, cc) => pp > nameLengthWithAlias(cc) ? pp : nameLengthWithAlias(cc), nameLengthWithAlias(c));
|
|
717
|
-
|
|
718
|
-
return p > length ? p : length;
|
|
719
|
-
}, 0);
|
|
720
|
-
|
|
721
|
-
const hpLength = tracker.reduce((p, c) => {
|
|
722
|
-
const hpLength = c.maxhp.toString().length + 1 + c.hp.toString().length + (c.temphp > 1 ? c.temphp.toString().length + 1 : 0);
|
|
723
|
-
|
|
724
|
-
const length = c.children.reduce((pp, cc) => {
|
|
725
|
-
const hhpLength = cc.maxhp.toString().length + 1 + cc.hp.toString().length + (cc.temphp > 1 ? cc.temphp.toString().length + 1 : 0);
|
|
726
|
-
|
|
727
|
-
return pp > hhpLength ? pp : hhpLength;
|
|
728
|
-
}, hpLength);
|
|
729
|
-
|
|
730
|
-
return p > length ? p : length;
|
|
731
|
-
}, 0);
|
|
732
|
-
|
|
733
|
-
const stateMap: Record<CharSchema['state'], string> = {
|
|
734
|
-
empty: ':emptynode:',
|
|
735
|
-
arrow: ':arrownode:',
|
|
736
|
-
check: ':checknode:',
|
|
737
|
-
cross: ':crossnode:',
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
const hpMap = [
|
|
741
|
-
':beaten:',
|
|
742
|
-
':bruised:',
|
|
743
|
-
':wounded:',
|
|
744
|
-
':limping:',
|
|
745
|
-
':dying:',
|
|
746
|
-
].reverse();
|
|
747
|
-
|
|
748
|
-
const lines = tracker.sort((a, b) => (a.init === b.init) ? (b.foe ? 1 : 0) - (a.foe ? 1 : 0) : b.init - a.init).flatMap((char, index) => {
|
|
749
|
-
const ls: string[] = [];
|
|
750
|
-
|
|
751
|
-
if (tracker[index - 1] && tracker[index - 1].foe !== char.foe) {
|
|
752
|
-
ls.push('')
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
const hp = !char.foe && char.hp > 0 ? (
|
|
756
|
-
`${char.hp}${char.temphp > 0 ? `+${char.temphp}` : ''}/${char.maxhp}`.padStart(hpLength)
|
|
757
|
-
) : char.hp > 0 ? (
|
|
758
|
-
`-${char.maxhp - char.hp}${char.temphp > 0 ? `+${char.temphp}` : ''}`.padStart(hpLength)
|
|
759
|
-
) : (
|
|
760
|
-
`${char.hp}${char.temphp > 0 ? `+${char.temphp}` : ''}`.padStart(hpLength)
|
|
761
|
-
);
|
|
762
|
-
|
|
763
|
-
const hpBar = (value: number, max: number) => (
|
|
764
|
-
value <= 0 ? (
|
|
765
|
-
':crossed:'
|
|
766
|
-
) : value >= max ? (
|
|
767
|
-
':healthy:'
|
|
768
|
-
) : (
|
|
769
|
-
hpMap[Math.round((hpMap.length - 1) * value / max)]
|
|
770
|
-
)
|
|
771
|
-
);
|
|
772
|
-
|
|
773
|
-
ls.push((
|
|
774
|
-
`${stateMap[char.hp > 0 ? char.state : 'cross']}**\` ${char.name.padEnd(nameLength + aliasSpace(char))}${char.alias.length > 0 ? ` ▏${char.alias.padEnd(3)}` : ''} ▏${hp} \`** ${hpBar(char.hp, char.maxhp)} `
|
|
775
|
-
))
|
|
776
|
-
|
|
777
|
-
if (char.conditions.length > 0) {
|
|
778
|
-
ls.push(`-# ${char.conditions}`)
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
for (const child of char.children) {
|
|
782
|
-
const hhp = !char.foe && child.hp > 0 ? (
|
|
783
|
-
`${child.hp}${child.temphp > 0 ? `+${child.temphp}` : ''}/${child.maxhp}`.padStart(hpLength)
|
|
784
|
-
) : child.hp > 0 ? (
|
|
785
|
-
`-${child.maxhp - child.hp}${child.temphp > 0 ? `+${child.temphp}` : ''}`.padStart(hpLength)
|
|
786
|
-
) : (
|
|
787
|
-
`${child.hp}${child.temphp > 0 ? `+${child.temphp}` : ''}`.padStart(hpLength)
|
|
788
|
-
);
|
|
789
|
-
|
|
790
|
-
ls.push((
|
|
791
|
-
`:smallnode:**\` ${child.name.padEnd(nameLength + aliasSpace(child))}${child.alias.length > 0 ? ` ▏${child.alias.padEnd(3)}` : ''} ▏${hhp} \`** ${hpBar(child.hp, child.maxhp)} `
|
|
792
|
-
))
|
|
793
|
-
|
|
794
|
-
if (child.conditions.length > 0) {
|
|
795
|
-
ls.push(`-# ${child.conditions}`)
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
return ls;
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
lines.push(':spacer:')
|
|
803
|
-
|
|
804
|
-
return lines.join('\n');
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
export const sortFolder = async () => {
|
|
808
|
-
const dir = await readdir('.');
|
|
809
|
-
|
|
810
|
-
const summary = await Promise.all(dir.map(async (file) => {
|
|
811
|
-
const stats = await stat(file);
|
|
812
|
-
|
|
813
|
-
const timestamp = parseInt(stats.birthtimeMs.toFixed(0));
|
|
814
|
-
|
|
815
|
-
return { file, timestamp };
|
|
816
|
-
}))
|
|
817
|
-
|
|
818
|
-
const transformed = summary.sort((a, b) => a.timestamp - b.timestamp).map((s, index) => {
|
|
819
|
-
const prefix = String(index + 1).padStart(3, '0');
|
|
820
|
-
|
|
821
|
-
const name = s.file.replace('RU PFS Online - ', '').replace(/\s\[.+\]/, '');
|
|
822
|
-
|
|
823
|
-
return { oldname: s.file, newname: name.startsWith('ooc') ? name : `${prefix} ${name}` };
|
|
824
|
-
})
|
|
825
|
-
|
|
826
|
-
await Promise.all(transformed.map(async (t) => rename(t.oldname, t.newname)));
|
|
827
|
-
|
|
828
|
-
return transformed;
|
|
829
|
-
};
|
|
830
|
-
|
|
831
|
-
export const screenPlay = (htmlContent: string) => {
|
|
832
|
-
const dom = new JSDOM(htmlContent);
|
|
833
|
-
const document = dom.window.document;
|
|
834
|
-
|
|
835
|
-
const outputLines = [];
|
|
836
|
-
|
|
837
|
-
const preambleEntry = document.querySelector('.preamble__entry');
|
|
838
|
-
if (preambleEntry) {
|
|
839
|
-
outputLines.push(`SCENE: ${preambleEntry.textContent}`);
|
|
840
|
-
outputLines.push('');
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
// Process all chatlog messages
|
|
844
|
-
const messages = document.querySelectorAll('.chatlog__message');
|
|
845
|
-
|
|
846
|
-
messages.forEach(message => {
|
|
847
|
-
const authorElement = message.querySelector('.chatlog__author');
|
|
848
|
-
const contentElement = message.querySelector('.chatlog__content');
|
|
849
|
-
|
|
850
|
-
if (!authorElement || !contentElement) return;
|
|
851
|
-
|
|
852
|
-
const author = authorElement.textContent?.trim() ?? '';
|
|
853
|
-
const content = contentElement.textContent?.trim() ?? '';
|
|
854
|
-
|
|
855
|
-
// Skip bot tags in character names
|
|
856
|
-
const characterName = author.replace(/\s*BOT$/, '');
|
|
857
|
-
|
|
858
|
-
// Add character line
|
|
859
|
-
outputLines.push(`${characterName.toUpperCase()}`);
|
|
860
|
-
|
|
861
|
-
// Add dialogue/content (wrap long lines)
|
|
862
|
-
const lines = content.split('\n').map((c) => (
|
|
863
|
-
c
|
|
864
|
-
.replace(/(—|--)/g, '-')
|
|
865
|
-
// eslint-disable-next-line no-irregular-whitespace
|
|
866
|
-
.replace(/(|)/g, '')
|
|
867
|
-
.trim()
|
|
868
|
-
)).filter((c) => c.length);
|
|
869
|
-
|
|
870
|
-
for (const line of lines) {
|
|
871
|
-
outputLines.push(` ${line}`);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
outputLines.push('');
|
|
875
|
-
});
|
|
876
|
-
|
|
877
|
-
return outputLines.join('\n');
|
|
878
|
-
}
|