-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
555 lines (517 loc) · 21.3 KB
/
app.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
document.addEventListener('alpine:init', () => {
Alpine.data('app', function () {
return {
//past progress
current_tier: this.$persist(1),
current_tier_xp: this.$persist(0),
days_missed: this.$persist(0),
//future plans
expected_weeklies: this.$persist(8),
expected_play_days: this.$persist(5),
expected_dailies: this.$persist(3),
expected_daily_matches: this.$persist(5),
expected_match_xp: this.$persist(500),
days_to_be_missed: this.$persist(0),
// default values
season: { season: 1, seasonStart: new Date('2022-10-04'), seasonEnd: new Date('2022-12-06') },
//ui
tab: this.$persist('all'),
init() {
// get current season and display it
this.season = this.getSeason(new Date('2022-10-04'));
document.getElementById('season_title').innerText = 'Season ' + this.season.season;
if (window.location.hash) {
const params = new URLSearchParams(window.location.hash.substring(1));
//past progress
if (params.has('t')) this.current_tier = params.get('t');
if (params.has('x')) this.current_tier_xp = params.get('x');
if (params.has('s')) this.days_missed = params.get('s');
//future plans
if (params.has('w')) this.expected_weeklies = params.get('w');
if (params.has('p')) this.expected_play_days = params.get('p');
if (params.has('d')) this.expected_dailies = params.get('d');
if (params.has('m')) this.expected_daily_matches = params.get('m');
if (params.has('v')) this.expected_match_xp = params.get('v');
if (params.has('e')) this.days_to_be_missed = params.get('e');
}
},
//buttons
share() {
const params = new URLSearchParams();
//past progress
params.set('t', this.currentTier().toString());
params.set('x', this.currentTierXp().toString());
params.set('s', this.daysMissed().toString());
//future plans
params.set('w', this.expectedWeeklies().toString());
params.set('p', this.expectedPlayDays().toString());
params.set('d', this.expectedDailies().toString());
params.set('m', this.expectedDailyMatches().toString());
params.set('v', this.expectedMatchXp().toString());
params.set('e', this.daysToBeMissed().toString());
let link = window.location.toString();
link = link.substring(0, link.length - window.location.hash.length);
link = link + '#' + params;
window.prompt('Here is your link!', link);
},
reset() {
//past progress
this.current_tier = 1;
this.current_tier_xp = 0;
this.days_missed = 0;
//future plans
this.expected_weeklies = 8;
this.expected_play_days = 5;
this.expected_dailies = 3;
this.expected_daily_matches = 5;
this.expected_match_xp = 500;
this.days_to_be_missed = 0;
},
//tabs
currentTab() {
return this.tab;
},
tabSelected(...tabs) {
for (const tab of tabs) {
if (tab === this.currentTab()) return true;
}
return false;
},
selectTab(tab) {
this.tab = tab;
//not sure i like this, it might confuse people that don't realize it's on, leaving it disabled for now
//window.location.hash = this.tab;
},
//season
/**
*
* @param {Date} startDate default is 2022-10-04
* @param {Date} today default is today, overwrite for testing
* @returns {Object} {season: number, seasonStart: Date, seasonEnd: Date}
*/
getSeason(startDate = new Date('2022-10-04'), today = new Date()) {
const oneWeek = 7 * 24 * 60 * 60 * 1000;
// Calculate season duration in milliseconds
const seasonDuration = 9 * oneWeek;
// Calculate the difference between start date and today
const diff = today - startDate;
// Get the season number
const season = Math.floor(diff / seasonDuration) + 1;
// Get the start date of the season
const seasonStart = new Date(startDate.getTime() + seasonDuration * (season - 1));
// Get the end date of the season
const seasonEnd = new Date(seasonStart.getTime() + seasonDuration - 1);
// Return season number, start and end dates
return { season, seasonStart, seasonEnd };
},
seasonStart() {
return this.season.seasonStart;
},
seasonEnd() {
return this.season.seasonEnd;
},
daysLeft() {
return (this.seasonEnd() - new Date()) / 86400000;
},
daysMissed() {
return parseInt(this.days_missed || 0);
},
//current progress
currentDay() {
return (new Date() - this.seasonStart()) / 86400000;
},
daysPlayed() {
return (this.currentDay() - this.daysMissed()).$max(0);
},
currentTier() {
let result = parseInt(this.current_tier || 0);
if (result < 1) return 1;
if (result > 200) return 200;
return result;
},
currentCompletedTier() {
if (this.currentTier() > 200) return 200;
else if (this.currentTier() === 200 && this.currentTierXp() >= 250000) return 200;
else if (this.currentTier() > 175) return 175;
else if (this.currentTier() > 155) return 155;
else if (this.currentTier() > 135) return 135;
else if (this.currentTier() > 120) return 120;
else if (this.currentTier() > 105) return 105;
else if (this.currentTier() > 95) return 95;
else if (this.currentTier() > 85) return 85;
else if (this.currentTier() > 80) return 80;
return Math.max(this.currentTier() - 1, 0);
},
currentCompletedPrestigeTier() {
return Math.max(this.currentCompletedTier() - 80, 0);
},
currentTierXp() {
if (this.current_tier_xp < 0) return 0;
return parseInt(this.current_tier_xp || 0);
},
currentXp() {
return (this.currentCompletedTier() * 10000) + this.currentTierXp();
},
currentPrestigeXp() {
return Math.max(this.currentXp() - 800000, 0);
},
currentMissingXp() {
return Math.max(800000 - this.currentXp(), 0);
},
currentMissingPrestigeXp() {
return Math.max(2000000 - this.currentXp(), 0);
},
currentPercent() {
return Math.min(this.currentXp() / 800000, 1) * 100;
},
currentPercentBar() {
let current = Math.min(this.currentXp(), 800000);
return Math.min(current / 2000000, 1) * 100;
},
currentPrestigePercent() {
return Math.min((this.currentXp() - 800000) / 1200000, 1) * 100;
},
currentPrestigePercentBar() {
return Math.min((this.currentXp() - 800000) / 2000000, 1) * 100;
},
//remaining
remainingDays() {
return Math.max((this.seasonEnd() - new Date()) / 86400000, 0);
},
daysToBeMissed() {
return parseInt(this.days_to_be_missed || 0);
},
remainingTiers() {
return 80 - this.currentCompletedTier();
},
remainingPrestigeTiers() {
if (this.currentCompletedTier() === 199 && this.currentTierXp() >= 10000) return 0;
return 200 - this.currentCompletedTier();
},
remainingXp() {
return (80 * 10000) - this.currentXp();
},
remainingPrestigeXp() {
return (200 * 10000) - this.currentXp();
},
remainingPercent() {
return (this.remainingTiers() / 80) * 100;
},
remainingPrestigePercent() {
return (this.remainingPrestigeTiers() / 200) * 100;
},
//minimum daily
minimumDailyTiers() {
return Math.max(this.remainingTiers() / this.remainingDays(), 0);
},
minimumDailyXp() {
return Math.max(this.remainingXp() / this.remainingDays(), 0);
},
minimumDailyPercent() {
return Math.max(this.remainingPercent() / this.remainingDays(), 0);
},
//minimum weekly
minimumWeeklyTiers() {
return this.minimumDailyTiers() * 7;
},
minimumWeeklyXp() {
return this.minimumDailyXp() * 7;
},
minimumWeeklyPercent() {
return this.minimumDailyPercent() * 7;
},
//minimum daily for prestige
minimumDailyPrestigeTiers() {
return this.remainingPrestigeTiers() / this.remainingDays();
},
minimumDailyPrestigeXp() {
return this.remainingPrestigeXp() / this.remainingDays();
},
minimumDailyPrestigePercent() {
return this.remainingPrestigePercent() / this.remainingDays();
},
//minimum weekly for prestige
minimumWeeklyPrestigeTiers() {
return this.minimumDailyPrestigeTiers() * 7;
},
minimumWeeklyPrestigeXp() {
return this.minimumDailyPrestigeXp() * 7;
},
minimumWeeklyPrestigePercent() {
return this.minimumDailyPrestigePercent() * 7;
},
//projected missed
projectedTiersMissed() {
return this.projectedDailyTiers() * this.daysMissed();
},
projectedXpMissed() {
return this.projectedDailyXp() * this.daysMissed();
},
projectedPercentMissed() {
return this.projectedDailyPercent() * this.daysMissed();
},
//projected daily earn rate
projectedDailyTiers() {
return this.currentCompletedTier() / this.daysPlayed();
},
projectedDailyXp() {
return this.currentXp() / this.daysPlayed();
},
projectedDailyPercent() {
return this.currentPercent() / this.daysPlayed();
},
//projected weekly earn rate
projectedWeeklyTiers() {
return this.projectedDailyTiers() * 7;
},
projectedWeeklyXp() {
return this.projectedDailyXp() * 7;
},
projectedWeeklyPercent() {
return this.projectedDailyPercent() * 7;
},
//projected finish
projectedWillFinish() {
return this.projectedTiers() >= 80;
},
projectedXp() {
return this.projectedDailyXp() * this.remainingDays();
},
projectedDays() {
let result = (800000 / this.projectedDailyXp()) - this.daysPlayed();
if (result < 0) return 0;
return result;
},
projectedSpareDays() {
return 63 - (this.daysPlayed() + this.projectedDays());
},
projectedTiers() {
let expecting = this.currentXp() + (this.projectedDailyXp() * this.remainingDays());
let result = expecting / 10000;
if (result < 0) return 0;
if (result > 200) return 200;
return result;
},
projectedPercent() {
return (Math.min(this.projectedTiers(), 80) / 80) * 100;
},
projectedPercentBar() {
return (Math.min(this.projectedTiers(), 80) / 200) * 100;
},
projectedPrestigePercent() {
return (this.projectedPrestigeTiers() / 120) * 100;
},
projectedPrestigePercentBar() {
return (this.projectedPrestigeTiers() / 200) * 100;
},
//projected prestige
projectedWillPrestige() {
return this.projectedTiers() > 80;
},
projectedWillFinishPrestige() {
return this.projectedPrestigeTiers() >= 120;
},
projectedPrestigeDays() {
return (63 - this.projectedPrestigeSpareDays()) - this.daysPlayed();
},
projectedPrestigeSpareDays() {
let extra = this.projectedXp() - (2000000 - this.currentXp());
return Math.min(extra / this.projectedDailyXp(), 7 * 9);
},
projectedPrestigeTiers() {
let have = this.currentXp();
let projecting = this.projectedDailyXp() * this.remainingDays();
let total = have + projecting;
return Math.min((total / 10000) - 80, 120);
},
projectedPrestigeTiersMissed() {
return 120 - this.projectedPrestigeTiers();
},
projectedPrestigeTitles() {
let extraTiers = this.projectedPrestigeTiers();
return this.titlesFromTiers(extraTiers + 80);
},
projectedPrestigeTitlesMissed() {
return 8 - this.projectedPrestigeTitles();
},
//projected fail
projectedWillFail() {
return this.projectedTiers() < 80;
},
projectedSpareTiers() {
return 80 - this.projectedTiers();
},
projectedSpareTiersCoins() {
return this.projectedSpareTiers().$ceil() * 200;
},
projectedSpareTiersDollars() {
return this.projectedSpareTiersCoins() / 100;
},
//expected daily earn rate
expectedDailyMatches() {
return parseInt(this.expected_daily_matches || 0);
},
expectedMatchXp() {
return parseInt(this.expected_match_xp || 0);
},
expectedPlayDays() {
return parseInt(this.expected_play_days || 0);
},
expectedDailies() {
return parseInt(this.expected_dailies || 0);
},
expectedDailyDailiesXp() {
let dailyXp = 0;
if (this.expectedDailies() >= 3) dailyXp = 9000;
else if (this.expectedDailies() >= 2) dailyXp = 6000;
else if (this.expectedDailies() >= 1) dailyXp = 3000;
else return 0;
return (dailyXp * this.expectedPlayDays()) / 7;
},
expectedWeeklies() {
return parseInt(this.expected_weeklies || 0);
},
expectedDailyWeekliesXp() {
return (this.expectedWeeklies() * 5000) / 7;
},
expectedDailyTiers() {
return this.expectedDailyXp() / 10000;
},
expectedDailyMatchXp() {
return ((this.expectedDailyMatches() * this.expectedMatchXp()) * this.expectedPlayDays()) / 7;
},
expectedDailyXp() {
return this.expectedDailyMatchXp() + this.expectedDailyDailiesXp() + this.expectedDailyWeekliesXp();
},
expectedXp() {
return this.expectedDailyXp() * this.remainingDays();
},
expectedDailyPercent() {
return (this.expectedDailyXp() / 800000) * 100;
},
//expected weekly earn rate
expectedWeeklyTiers() {
return this.expectedDailyTiers() * 7;
},
expectedWeeklyXp() {
return this.expectedDailyXp() * 7;
},
expectedWeeklyPercent() {
return this.expectedDailyPercent() * 7;
},
//expected finish
expectedWillFinish() {
return this.expectedTiers() >= 80;
},
expectedDays() {
return Math.max(this.currentMissingXp() / this.expectedDailyXp(), 0);
},
expectedSpareDays() {
return 63 - (this.currentDay() + this.expectedDays());
},
expectedTiers() {
let expecting = this.currentXp() + this.expectedXp();
let result = Math.floor(expecting / 10000);
if (result < 0) return 0;
if (result > 200) return 200;
return result;
},
expectedPercent() {
return (Math.min(this.expectedTiers(), 80) / 80) * 100;
},
expectedPercentBar() {
return (Math.min(this.expectedTiers(), 80) / 200) * 100;
},
expectedPrestigePercent() {
return (this.expectedPrestigeTiers() / 120) * 100;
},
expectedPrestigePercentBar() {
return (this.expectedPrestigeTiers() / 200) * 100;
},
//expected prestige
expectedWillPrestige() {
return this.expectedTiers() > 80;
},
expectedWillFinishPrestige() {
return this.expectedPrestigeTiers() >= 120;
},
expectedPrestigeDays() {
return (63 - this.expectedPrestigeSpareDays()) - this.daysPlayed();
},
expectedPrestigeSpareDays() {
let extra = this.expectedXp() - (2000000 - this.currentXp());
return Math.min(extra / this.expectedDailyXp(), 7 * 9);
},
expectedPrestigeTiers() {
let have = this.currentXp();
let expecting = this.expectedXp();
let total = have + expecting;
return Math.min(Math.floor(total / 10000) - 80, 200 - 80);
},
expectedPrestigeTiersMissed() {
return 120 - this.expectedPrestigeTiers();
},
expectedPrestigeTitles() {
let extraTiers = this.expectedPrestigeTiers();
return this.titlesFromTiers(extraTiers + 80);
},
expectedPrestigeTitlesMissed() {
return 8 - this.expectedPrestigeTitles();
},
//expected fail
expectedWillFail() {
return this.expectedTiers() < 80;
},
expectedSpareTiers() {
let required = 80 * 10000;
let have = this.currentXp();
let need = required - have;
let expecting = this.expectedXp();
let missing = need - expecting;
return Math.ceil(missing / 10000);
},
expectedSpareTiersCoins() {
return this.expectedSpareTiers() * 200;
},
expectedSpareTiersUsd() {
return this.expectedSpareTiersCoins() / 100;
},
//coins rate
expectedDailyCoins() {
return this.expectedWeeklyCoins() / 7;
},
expectedWeeklyCoins() {
return this.coinsFromWeeklies(this.expectedWeeklies());
},
expectedSeasonalCoins() {
return this.expectedWeeklyCoins() * 9;
},
expectedCoins() {
return this.remainingDays() * this.expectedDailyCoins();
},
expectedBattlePassDays() {
return 1000 / this.expectedDailyCoins();
},
expectedLegendaryDays() {
return 2000 / this.expectedDailyCoins();
},
titlesFromTiers(tiers) {
if (tiers >= 200) return 8;
else if (tiers >= 175) return 7;
else if (tiers >= 155) return 6;
else if (tiers >= 135) return 5;
else if (tiers >= 120) return 4;
else if (tiers >= 105) return 3;
else if (tiers >= 95) return 2;
else if (tiers >= 85) return 1;
else return 0;
},
coinsFromWeeklies(weeklies) {
if (weeklies >= 11) return 60;
else if (weeklies >= 8) return 50;
else if (weeklies >= 4) return 30;
else return 0;
}
}
})
})