-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathabyss.js
371 lines (340 loc) · 8.53 KB
/
abyss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import { element } from '../lib/convert.js';
import { getSquareAvatar, getSquareBangboo } from '../lib/download.js';
/**
* @typedef {Object} IChallengeAvatar
* @property {number} id
* @property {number} level
* @property {string} rarity
* @property {number} element_type
*/
/**
* @typedef {Object} IChallengeBangboo
* @property {number} id
* @property {string} rarity
* @property {number} level
*/
/**
* @typedef {Object} IHadalTime
* @property {number} year
* @property {number} month
* @property {number} day
* @property {number} hour
* @property {number} minute
* @property {number} second
*/
/**
* @typedef {Object} IMonsterInfo
* @property {number} id
* @property {string} name
* @property {number} weak_element_type
*/
/**
* @typedef {Object} IBuff
* @property {string} title
* @property {string} text
*/
/**
* @typedef {Object} IChallengeNode
* @property {IChallengeAvatar[]} avatars
* @property {IChallengeBangboo} buddy
* @property {number[]} element_type_list
* @property {IMonsterInfo} monster_info
*/
/**
* @typedef {Object} IFloorChallengeTime
* @property {number} year
* @property {number} month
* @property {number} day
* @property {number} hour
* @property {number} minute
* @property {number} second
*/
/**
* @typedef {Object} IFloorDetail
* @property {number} layer_index
* @property {string} rating
* @property {number} layer_id
* @property {IBuff[]} buffs
* @property {IChallengeNode} node_1
* @property {IChallengeNode} node_2
* @property {number} challenge_time
* @property {string} zone_name
* @property {IFloorChallengeTime} floor_challenge_time
*/
/**
* @typedef {Object} IRating
* @property {number} times
* @property {string} rating
*/
/**
* @typedef {Object} IZZZChallenge
* @property {number} schedule_id
* @property {number} begin_time
* @property {number} end_time
* @property {IRating[]} rating_list
* @property {boolean} has_data
* @property {IFloorDetail[]} all_floor_detail
* @property {number} fast_layer_time
* @property {number} max_layer
* @property {IHadalTime} hadal_begin_time
* @property {IHadalTime} hadal_end_time
*/
/**
* @class ChallengeAvatar.
*/
export class ChallengeAvatar {
/**
* @param {IChallengeAvatar} data
*/
constructor(data) {
this.id = data.id;
this.level = data.level;
this.rarity = data.rarity;
this.element_type = data.element_type;
}
async get_assets() {
const result = await getSquareAvatar(this.id);
this.square_icon = result;
}
get element() {
return element.IDToElement(this.element_type);
}
}
/**
* @class ChallengeBangboo.
*/
export class ChallengeBangboo {
/**
* @param {IChallengeBangboo} data
*/
constructor(data) {
this.id = data.id;
this.rarity = data.rarity;
this.level = data.level;
}
async get_assets() {
const result = await getSquareBangboo(this.id);
this.square_icon = result;
}
}
/**
* @class MonsterInfo.
*/
export class MonsterInfo {
/**
* @param {IMonsterInfo} data
*/
constructor(data) {
this.id = data.id;
this.name = data.name;
this.weak_element_type = data.weak_element_type;
}
}
/**
* @class Buff.
*/
export class Buff {
/**
* @param {IBuff} data
*/
constructor(data) {
this.title = data.title;
this.text = data.text;
}
}
/**
* @class ChallengeNode.
*/
export class ChallengeNode {
/**
* @param {IChallengeNode} data
*/
constructor(data) {
/** @type {IChallengeAvatar[]} */
this.avatars = data?.avatars?.map(avatar => new ChallengeAvatar(avatar));
/** @type {IChallengeBangboo} */
this.buddy = data?.buddy && new ChallengeBangboo(data.buddy);
/** @type {number[]} */
this.element_type_list = data.element_type_list;
/** @type {MonsterInfo} */
this.monster_info =
data?.monster_info && new MonsterInfo(data.monster_info);
}
async get_assets() {
if (this.avatars) {
await Promise.all(this.avatars.map(avatar => avatar.get_assets()));
}
if (this.buddy) {
await this.buddy.get_assets();
}
}
get elements() {
return this.element_type_list.map(type => {
return element.IDToElement(type);
});
}
}
/**
* @class FloorChallengeTime.
*/
export class FloorChallengeTime {
/**
* @param {IFloorChallengeTime} data
*/
constructor(data) {
/** @type {number} */
this.year = data.year;
/** @type {number} */
this.month = data.month;
/** @type {number} */
this.day = data.day;
/** @type {number} */
this.hour = data.hour;
/** @type {number} */
this.minute = data.minute;
/** @type {number} */
this.second = data.second;
}
/** @type {string} */
get formattedTime() {
return `${this.year}/${this.month}/${this.day} ${this.hour}:${this.minute}:${this.second}`;
}
}
/**
* @class FloorDetail.
*/
export class FloorDetail {
/**
* @param {IFloorDetail} data
*/
constructor(data) {
/** @type {number} */
this.layer_index = data.layer_index;
/** @type {string} */
this.rating = data.rating;
/** @type {number} */
this.layer_id = data.layer_id;
/** @type {IBuff[]} */
this.buffs = data.buffs.map(buff => new Buff(buff));
/** @type {IChallengeNode} */
this.node_1 = data?.node_1 && new ChallengeNode(data.node_1);
/** @type {IChallengeNode} */
this.node_2 = data?.node_2 && new ChallengeNode(data.node_2);
/** @type {number} */
this.challenge_time = data.challenge_time;
/** @type {string} */
this.zone_name = data.zone_name;
/** @type {IFloorChallengeTime} */
this.floor_challenge_time = new FloorChallengeTime(
data.floor_challenge_time
);
}
async get_assets() {
if (this.node_1) {
await this.node_1.get_assets();
}
if (this.node_2) {
await this.node_2.get_assets();
}
}
/** @type {string} */
get formattedTime() {
return (
this.floor_challenge_time.year +
'年' +
this.floor_challenge_time.month +
'月' +
this.floor_challenge_time.day +
'日 ' +
this.floor_challenge_time.hour.toString().padStart(2, '0') +
':' +
this.floor_challenge_time.minute.toString().padStart(2, '0') +
':' +
this.floor_challenge_time.second.toString().padStart(2, '0')
);
}
}
/**
* @class Rating.
*/
export class Rating {
/**
* @param {IRating} data
*/
constructor(data) {
this.times = data.times;
this.rating = data.rating;
}
}
/**
* @class ZZZChallenge.
*/
export class ZZZChallenge {
/**
* @param {IZZZChallenge} data
*/
constructor(data) {
// 类型标注
/** @type {number} */
this.schedule_id = data.schedule_id;
/** @type {number} */
this._begin_time = data.begin_time;
/** @type {number} */
this._end_time = data.end_time;
/** @type {IRating[]} */
this.rating_list = data.rating_list.map(rating => new Rating(rating));
/** @type {boolean} */
this.has_data = data.has_data;
/** @type {IFloorDetail[]} */
this.all_floor_detail = data.all_floor_detail.map(
floorDetail => new FloorDetail(floorDetail)
);
/** @type {number} */
this.fast_layer_time = data.fast_layer_time;
/** @type {number} */
this.max_layer = data.max_layer;
/** @type {IHadalTime} */
this.hadal_begin_time = data.hadal_begin_time;
/** @type {IHadalTime} */
this.hadal_end_time = data.hadal_end_time;
/** @type {{
* S: number;
* A: number;
* B: number;
* }} */
this.rate_count = {
S: this.rating_list.find(rating => rating.rating === 'S')?.times || 0,
A: this.rating_list.find(rating => rating.rating === 'A')?.times || 0,
B: this.rating_list.find(rating => rating.rating === 'B')?.times || 0,
};
}
async get_assets() {
await Promise.all(this.all_floor_detail.map(floor => floor.get_assets()));
}
get fast_layer_time_str() {
// 将秒数转换为 xx小时xx分钟xx秒 的格式,例如:234 -> 3分钟54秒
const seconds = this.fast_layer_time % 60;
const minutes = Math.floor(this.fast_layer_time / 60) % 60;
const hours = Math.floor(this.fast_layer_time / 3600);
return `${hours ? hours + '小时' : ''}${minutes ? minutes + '分钟' : ''}${
seconds ? seconds + '秒' : ''
}`;
}
/** @type {string} */
get begin_time() {
return new Date(Number(this._begin_time) * 1000).toLocaleDateString(
'en-US',
{
month: '2-digit',
day: '2-digit',
}
);
}
/** @type {string} */
get end_time() {
return new Date(Number(this._end_time) * 1000).toLocaleDateString('en-US', {
month: '2-digit',
day: '2-digit',
});
}
}