forked from dekzeh/calc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdesc.js
827 lines (826 loc) · 33.8 KB
/
desc.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
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
exports.__esModule = true;
var result_1 = require("./result");
var util_1 = require("./util");
var util_2 = require("./mechanics/util");
function display(gen, attacker, defender, move, field, damage, rawDesc, notation, err) {
if (notation === void 0) { notation = '%'; }
if (err === void 0) { err = true; }
var _a = __read((0, result_1.damageRange)(damage), 2), minDamage = _a[0], maxDamage = _a[1];
var min = (typeof minDamage === 'number' ? minDamage : minDamage[0] + minDamage[1]) * move.hits;
var max = (typeof maxDamage === 'number' ? maxDamage : maxDamage[0] + maxDamage[1]) * move.hits;
var minDisplay = toDisplay(notation, min, defender.maxHP());
var maxDisplay = toDisplay(notation, max, defender.maxHP());
var desc = buildDescription(rawDesc, attacker, defender);
var damageText = "".concat(min, "-").concat(max, " (").concat(minDisplay, " - ").concat(maxDisplay).concat(notation, ")");
if (move.category === 'Status' && !move.named('Nature Power'))
return "".concat(desc, ": ").concat(damageText);
var koChanceText = getKOChance(gen, attacker, defender, move, field, damage, err).text;
return koChanceText ? "".concat(desc, ": ").concat(damageText, " -- ").concat(koChanceText) : "".concat(desc, ": ").concat(damageText);
}
exports.display = display;
function displayMove(gen, attacker, defender, move, damage, notation) {
if (notation === void 0) { notation = '%'; }
var _a = __read((0, result_1.damageRange)(damage), 2), minDamage = _a[0], maxDamage = _a[1];
var min = (typeof minDamage === 'number' ? minDamage : minDamage[0] + minDamage[1]) * move.hits;
var max = (typeof maxDamage === 'number' ? maxDamage : maxDamage[0] + maxDamage[1]) * move.hits;
var minDisplay = toDisplay(notation, min, defender.maxHP());
var maxDisplay = toDisplay(notation, max, defender.maxHP());
var recoveryText = getRecovery(gen, attacker, defender, move, damage, notation).text;
var recoilText = getRecoil(gen, attacker, defender, move, damage, notation).text;
return "".concat(minDisplay, " - ").concat(maxDisplay).concat(notation).concat(recoveryText &&
" (".concat(recoveryText, ")")).concat(recoilText && " (".concat(recoilText, ")"));
}
exports.displayMove = displayMove;
function getRecovery(gen, attacker, defender, move, damage, notation) {
if (notation === void 0) { notation = '%'; }
var _a = __read((0, result_1.damageRange)(damage), 2), minDamage = _a[0], maxDamage = _a[1];
var minD = typeof minDamage === 'number' ? [minDamage] : minDamage;
var maxD = typeof maxDamage === 'number' ? [maxDamage] : maxDamage;
var recovery = [0, 0];
var text = '';
var ignoresShellBell = gen.num === 3 && move.named('Doom Desire', 'Future Sight');
if (attacker.hasItem('Shell Bell') && !ignoresShellBell) {
var max = Math.round(defender.maxHP() / 8);
for (var i = 0; i < minD.length; i++) {
recovery[0] += Math.min(Math.round(minD[i] * move.hits / 8), max);
recovery[1] += Math.min(Math.round(maxD[i] * move.hits / 8), max);
}
}
if (move.named('G-Max Finale')) {
recovery[0] = recovery[1] = Math.round(attacker.maxHP() / 6);
}
if (move.drain) {
var percentHealed = move.drain[0] / move.drain[1];
var max = Math.round(defender.maxHP() * percentHealed);
for (var i = 0; i < minD.length; i++) {
recovery[0] += Math.min(Math.round(minD[i] * move.hits * percentHealed), max);
recovery[1] += Math.min(Math.round(maxD[i] * move.hits * percentHealed), max);
}
}
if (recovery[1] === 0)
return { recovery: recovery, text: text };
var minHealthRecovered = toDisplay(notation, recovery[0], attacker.maxHP());
var maxHealthRecovered = toDisplay(notation, recovery[1], attacker.maxHP());
text = "".concat(minHealthRecovered, " - ").concat(maxHealthRecovered).concat(notation, " recovered");
return { recovery: recovery, text: text };
}
exports.getRecovery = getRecovery;
function getRecoil(gen, attacker, defender, move, damage, notation) {
if (notation === void 0) { notation = '%'; }
var _a = __read((0, result_1.damageRange)(damage), 2), minDamage = _a[0], maxDamage = _a[1];
var min = (typeof minDamage === 'number' ? minDamage : minDamage[0] + minDamage[1]) * move.hits;
var max = (typeof maxDamage === 'number' ? maxDamage : maxDamage[0] + maxDamage[1]) * move.hits;
var recoil = [0, 0];
var text = '';
var damageOverflow = minDamage > defender.curHP() || maxDamage > defender.curHP();
if (move.recoil) {
var mod = (move.recoil[0] / move.recoil[1]) * 100;
var minRecoilDamage = void 0, maxRecoilDamage = void 0;
if (damageOverflow) {
minRecoilDamage =
toDisplay(notation, defender.curHP() * mod, attacker.maxHP(), 100);
maxRecoilDamage =
toDisplay(notation, defender.curHP() * mod, attacker.maxHP(), 100);
}
else {
minRecoilDamage = toDisplay(notation, Math.min(min, defender.curHP()) * mod, attacker.maxHP(), 100);
maxRecoilDamage = toDisplay(notation, Math.min(max, defender.curHP()) * mod, attacker.maxHP(), 100);
}
if (!attacker.hasAbility('Rock Head')) {
recoil = [minRecoilDamage, maxRecoilDamage];
text = "".concat(minRecoilDamage, " - ").concat(maxRecoilDamage).concat(notation, " recoil damage");
}
}
else if (move.hasCrashDamage) {
var genMultiplier = gen.num === 2 ? 12.5 : gen.num >= 3 ? 50 : 1;
var minRecoilDamage = void 0, maxRecoilDamage = void 0;
if (damageOverflow && gen.num !== 2) {
minRecoilDamage =
toDisplay(notation, defender.curHP() * genMultiplier, attacker.maxHP(), 100);
maxRecoilDamage =
toDisplay(notation, defender.curHP() * genMultiplier, attacker.maxHP(), 100);
}
else {
minRecoilDamage = toDisplay(notation, Math.min(min, defender.maxHP()) * genMultiplier, attacker.maxHP(), 100);
maxRecoilDamage = toDisplay(notation, Math.min(max, defender.maxHP()) * genMultiplier, attacker.maxHP(), 100);
}
recoil = [minRecoilDamage, maxRecoilDamage];
switch (gen.num) {
case 1:
recoil = toDisplay(notation, 1, attacker.maxHP());
text = '1hp damage on miss';
break;
case 2:
case 3:
case 4:
if (defender.hasType('Ghost')) {
if (gen.num === 4) {
var gen4CrashDamage = Math.floor(((defender.maxHP() * 0.5) / attacker.maxHP()) * 100);
recoil = notation === '%' ? gen4CrashDamage : Math.floor((gen4CrashDamage / 100) * 48);
text = "".concat(gen4CrashDamage, "% crash damage");
}
else {
recoil = 0;
text = 'no crash damage on Ghost types';
}
}
else {
text = "".concat(minRecoilDamage, " - ").concat(maxRecoilDamage).concat(notation, " crash damage on miss");
}
break;
default:
recoil = notation === '%' ? 24 : 50;
text = '50% crash damage';
}
}
else if (move.struggleRecoil) {
recoil = notation === '%' ? 12 : 25;
text = '25% struggle damage';
if (gen.num === 4)
text += ' (rounded down)';
}
else if (move.mindBlownRecoil) {
recoil = notation === '%' ? 24 : 50;
text = '50% recoil damage';
}
return { recoil: recoil, text: text };
}
exports.getRecoil = getRecoil;
function getKOChance(gen, attacker, defender, move, field, damage, err) {
if (err === void 0) { err = true; }
damage = combine(damage);
if (isNaN(damage[0])) {
(0, util_1.error)(err, 'damage[0] must be a number.');
return { chance: 0, n: 0, text: '' };
}
if (damage[damage.length - 1] === 0) {
(0, util_1.error)(err, 'damage[damage.length - 1] === 0.');
return { chance: 0, n: 0, text: '' };
}
if (move.timesUsed === undefined)
move.timesUsed = 1;
if (move.timesUsedWithMetronome === undefined)
move.timesUsedWithMetronome = 1;
if (damage[0] >= defender.maxHP() && move.timesUsed === 1 && move.timesUsedWithMetronome === 1) {
return { chance: 1, n: 1, text: 'guaranteed OHKO' };
}
var hazards = getHazards(gen, defender, field.defenderSide);
var eot = getEndOfTurn(gen, attacker, defender, move, field);
var toxicCounter = defender.hasStatus('tox') && !defender.hasAbility('Magic Guard') ? defender.toxicCounter : 0;
var qualifier = '';
if (move.hits > 1) {
qualifier = 'approx. ';
damage = squashMultihit(gen, damage, move.hits, err);
}
var hazardsText = hazards.texts.length > 0
? ' after ' + serializeText(hazards.texts)
: '';
var afterText = hazards.texts.length > 0 || eot.texts.length > 0
? ' after ' + serializeText(hazards.texts.concat(eot.texts))
: '';
if ((move.timesUsed === 1 && move.timesUsedWithMetronome === 1) || move.isZ) {
var chance = computeKOChance(damage, defender.curHP() - hazards.damage, 0, 1, 1, defender.maxHP(), toxicCounter);
if (chance === 1) {
return { chance: chance, n: 1, text: "guaranteed OHKO".concat(hazardsText) };
}
else if (chance > 0) {
return {
chance: chance,
n: 1,
text: qualifier + Math.round(chance * 1000) / 10 + "% chance to OHKO".concat(hazardsText)
};
}
if (damage.length === 256) {
qualifier = 'approx. ';
}
for (var i = 2; i <= 4; i++) {
var chance_1 = computeKOChance(damage, defender.curHP() - hazards.damage, eot.damage, i, 1, defender.maxHP(), toxicCounter);
if (chance_1 === 1) {
return { chance: chance_1, n: i, text: "".concat(qualifier || 'guaranteed ').concat(i, "HKO").concat(afterText) };
}
else if (chance_1 > 0) {
return {
chance: chance_1,
n: i,
text: qualifier + Math.round(chance_1 * 1000) / 10 + "% chance to ".concat(i, "HKO").concat(afterText)
};
}
}
for (var i = 5; i <= 9; i++) {
if (predictTotal(damage[0], eot.damage, i, 1, toxicCounter, defender.maxHP()) >=
defender.curHP() - hazards.damage) {
return { chance: 1, n: i, text: "".concat(qualifier || 'guaranteed ').concat(i, "HKO").concat(afterText) };
}
else if (predictTotal(damage[damage.length - 1], eot.damage, i, 1, toxicCounter, defender.maxHP()) >=
defender.curHP() - hazards.damage) {
return { n: i, text: qualifier + "possible ".concat(i, "HKO").concat(afterText) };
}
}
}
else {
var chance = computeKOChance(damage, defender.maxHP() - hazards.damage, eot.damage, move.hits || 1, move.timesUsed || 1, defender.maxHP(), toxicCounter);
if (chance === 1) {
return {
chance: chance,
n: move.timesUsed,
text: "".concat(qualifier || 'guaranteed ', "KO in ").concat(move.timesUsed, " turns").concat(afterText)
};
}
else if (chance > 0) {
return {
chance: chance,
n: move.timesUsed,
text: qualifier +
Math.round(chance * 1000) / 10 +
"% chance to ".concat(move.timesUsed, "HKO").concat(afterText)
};
}
if (predictTotal(damage[0], eot.damage, move.hits, move.timesUsed, toxicCounter, defender.maxHP()) >=
defender.curHP() - hazards.damage) {
return {
chance: 1,
n: move.timesUsed,
text: "".concat(qualifier || 'guaranteed ', "KO in ").concat(move.timesUsed, " turns").concat(afterText)
};
}
else if (predictTotal(damage[damage.length - 1], eot.damage, move.hits, move.timesUsed, toxicCounter, defender.maxHP()) >=
defender.curHP() - hazards.damage) {
return {
n: move.timesUsed,
text: qualifier + "possible KO in ".concat(move.timesUsed, " turns").concat(afterText)
};
}
return { n: move.timesUsed, text: qualifier + 'not a KO' };
}
return { chance: 0, n: 0, text: '' };
}
exports.getKOChance = getKOChance;
function combine(damage) {
if (typeof damage === 'number')
return [damage];
if (damage.length > 2) {
if (damage[0] > damage[damage.length - 1])
damage = damage.slice().sort();
return damage;
}
if (typeof damage[0] === 'number' && typeof damage[1] === 'number') {
return [damage[0] + damage[1]];
}
var d = damage;
var combined = [];
for (var i = 0; i < d[0].length; i++) {
for (var j = 0; j < d[1].length; j++) {
combined.push(d[0][i] + d[1][j]);
}
}
return combined.sort();
}
var TRAPPING = [
'Bind', 'Clamp', 'Fire Spin', 'Infestation', 'Magma Storm', 'Sand Tomb',
'Thunder Cage', 'Whirlpool', 'Wrap', 'G-Max Sandblast', 'G-Max Centiferno',
];
function getHazards(gen, defender, defenderSide) {
var damage = 0;
var texts = [];
if (defender.hasItem('Heavy-Duty Boots')) {
return { damage: damage, texts: texts };
}
if (defenderSide.isSR && !defender.hasAbility('Magic Guard', 'Mountaineer')) {
var rockType = gen.types.get('rock');
var effectiveness = rockType.effectiveness[defender.types[0]] *
(defender.types[1] ? rockType.effectiveness[defender.types[1]] : 1);
damage += Math.floor((effectiveness * defender.maxHP()) / 8);
texts.push('Stealth Rock');
}
if (defenderSide.steelsurge && !defender.hasAbility('Magic Guard', 'Mountaineer')) {
var steelType = gen.types.get('steel');
var effectiveness = steelType.effectiveness[defender.types[0]] *
(defender.types[1] ? steelType.effectiveness[defender.types[1]] : 1);
damage += Math.floor((effectiveness * defender.maxHP()) / 8);
texts.push('Steelsurge');
}
if (!defender.hasType('Flying') &&
!defender.hasAbility('Magic Guard', 'Levitate') &&
!defender.hasItem('Air Balloon')) {
if (defenderSide.spikes === 1) {
damage += Math.floor(defender.maxHP() / 8);
if (gen.num === 2) {
texts.push('Spikes');
}
else {
texts.push('1 layer of Spikes');
}
}
else if (defenderSide.spikes === 2) {
damage += Math.floor(defender.maxHP() / 6);
texts.push('2 layers of Spikes');
}
else if (defenderSide.spikes === 3) {
damage += Math.floor(defender.maxHP() / 4);
texts.push('3 layers of Spikes');
}
}
if (isNaN(damage)) {
damage = 0;
}
return { damage: damage, texts: texts };
}
function getEndOfTurn(gen, attacker, defender, move, field) {
var damage = 0;
var texts = [];
if (field.hasWeather('Sun', 'Harsh Sunshine')) {
if (defender.hasAbility('Dry Skin', 'Solar Power')) {
damage -= Math.floor(defender.maxHP() / 8);
texts.push(defender.ability + ' damage');
}
}
else if (field.hasWeather('Rain', 'Heavy Rain')) {
if (defender.hasAbility('Dry Skin')) {
damage += Math.floor(defender.maxHP() / 8);
texts.push('Dry Skin recovery');
}
else if (defender.hasAbility('Rain Dish')) {
damage += Math.floor(defender.maxHP() / 16);
texts.push('Rain Dish recovery');
}
}
else if (field.hasWeather('Sand')) {
if (!defender.hasType('Rock', 'Ground', 'Steel') &&
!defender.hasAbility('Magic Guard', 'Overcoat', 'Sand Force', 'Sand Rush', 'Sand Veil') &&
!defender.hasItem('Safety Goggles')) {
damage -= Math.floor(defender.maxHP() / (gen.num === 2 ? 8 : 16));
texts.push('sandstorm damage');
}
}
else if (field.hasWeather('Hail', 'Snow')) {
if (defender.hasAbility('Ice Body')) {
damage += Math.floor(defender.maxHP() / 16);
texts.push('Ice Body recovery');
}
else if (!defender.hasType('Ice') &&
!defender.hasAbility('Magic Guard', 'Overcoat', 'Snow Cloak') &&
!defender.hasItem('Safety Goggles') &&
field.hasWeather('Hail')) {
damage -= Math.floor(defender.maxHP() / 16);
texts.push('hail damage');
}
}
var loseItem = move.named('Knock Off') && !defender.hasAbility('Sticky Hold');
if (defender.hasItem('Leftovers') && !loseItem) {
damage += Math.floor(defender.maxHP() / 16);
texts.push('Leftovers recovery');
}
else if (defender.hasItem('Black Sludge') && !loseItem) {
if (defender.hasType('Poison')) {
damage += Math.floor(defender.maxHP() / 16);
texts.push('Black Sludge recovery');
}
else if (!defender.hasAbility('Magic Guard', 'Klutz')) {
damage -= Math.floor(defender.maxHP() / 8);
texts.push('Black Sludge damage');
}
}
else if (defender.hasItem('Sticky Barb')) {
damage -= Math.floor(defender.maxHP() / 8);
texts.push('Sticky Barb damage');
}
if (field.defenderSide.isSeeded) {
if (!defender.hasAbility('Magic Guard')) {
damage -= Math.floor(defender.maxHP() / (gen.num >= 2 ? 8 : 16));
texts.push('Leech Seed damage');
}
}
if (field.attackerSide.isSeeded && !attacker.hasAbility('Magic Guard')) {
if (attacker.hasAbility('Liquid Ooze')) {
damage -= Math.floor(attacker.maxHP() / (gen.num >= 2 ? 8 : 16));
texts.push('Liquid Ooze damage');
}
else {
damage += Math.floor(attacker.maxHP() / (gen.num >= 2 ? 8 : 16));
texts.push('Leech Seed recovery');
}
}
if (field.hasTerrain('Grassy')) {
if ((0, util_2.isGrounded)(defender, field)) {
damage += Math.floor(defender.maxHP() / 16);
texts.push('Grassy Terrain recovery');
}
}
if (defender.hasStatus('psn')) {
if (defender.hasAbility('Poison Heal')) {
damage += Math.floor(defender.maxHP() / 8);
texts.push('Poison Heal');
}
else if (!defender.hasAbility('Magic Guard')) {
damage -= Math.floor(defender.maxHP() / (gen.num === 1 ? 16 : 8));
texts.push('poison damage');
}
}
else if (defender.hasStatus('tox')) {
if (defender.hasAbility('Poison Heal')) {
damage += Math.floor(defender.maxHP() / 8);
texts.push('Poison Heal');
}
else if (!defender.hasAbility('Magic Guard')) {
texts.push('toxic damage');
}
}
else if (defender.hasStatus('brn')) {
if (defender.hasAbility('Heatproof')) {
damage -= Math.floor(defender.maxHP() / (gen.num > 6 ? 32 : 16));
texts.push('reduced burn damage');
}
else if (!defender.hasAbility('Magic Guard')) {
damage -= Math.floor(defender.maxHP() / (gen.num === 1 || gen.num > 6 ? 16 : 8));
texts.push('burn damage');
}
}
else if ((defender.hasStatus('slp') || defender.hasAbility('Comatose')) &&
attacker.hasAbility('isBadDreams') &&
!defender.hasAbility('Magic Guard')) {
damage -= Math.floor(defender.maxHP() / 8);
texts.push('Bad Dreams');
}
if (!defender.hasAbility('Magic Guard') && TRAPPING.includes(move.name)) {
if (attacker.hasItem('Binding Band')) {
damage -= gen.num > 5 ? Math.floor(defender.maxHP() / 6) : Math.floor(defender.maxHP() / 8);
texts.push('trapping damage');
}
else {
damage -= gen.num > 5 ? Math.floor(defender.maxHP() / 8) : Math.floor(defender.maxHP() / 16);
texts.push('trapping damage');
}
}
if (defender.isSaltCure && !defender.hasAbility('Magic Guard')) {
var isWaterOrSteel = defender.hasType('Water', 'Steel') ||
(defender.teraType && ['Water', 'Steel'].includes(defender.teraType));
damage -= Math.floor(defender.maxHP() / (isWaterOrSteel ? 4 : 8));
texts.push('Salt Cure');
}
if (!defender.hasType('Fire') && !defender.hasAbility('Magic Guard') &&
(move.named('Fire Pledge (Grass Pledge Boosted)', 'Grass Pledge (Fire Pledge Boosted)'))) {
damage -= Math.floor(defender.maxHP() / 8);
texts.push('Sea of Fire damage');
}
if (!defender.hasAbility('Magic Guard') && !defender.hasType('Grass') &&
(field.defenderSide.vinelash || move.named('G-Max Vine Lash'))) {
damage -= Math.floor(defender.maxHP() / 6);
texts.push('Vine Lash damage');
}
if (!defender.hasAbility('Magic Guard') && !defender.hasType('Fire') &&
(field.defenderSide.wildfire || move.named('G-Max Wildfire'))) {
damage -= Math.floor(defender.maxHP() / 6);
texts.push('Wildfire damage');
}
if (!defender.hasAbility('Magic Guard') && !defender.hasType('Water') &&
(field.defenderSide.cannonade || move.named('G-Max Cannonade'))) {
damage -= Math.floor(defender.maxHP() / 6);
texts.push('Cannonade damage');
}
if (!defender.hasAbility('Magic Guard') && !defender.hasType('Rock') &&
(field.defenderSide.volcalith || move.named('G-Max Volcalith'))) {
damage -= Math.floor(defender.maxHP() / 6);
texts.push('Volcalith damage');
}
return { damage: damage, texts: texts };
}
function computeKOChance(damage, hp, eot, hits, timesUsed, maxHP, toxicCounter) {
var n = damage.length;
if (hits === 1) {
for (var i = 0; i < n; i++) {
if (damage[n - 1] < hp)
return 0;
if (damage[i] >= hp) {
return (n - i) / n;
}
}
}
var toxicDamage = 0;
if (toxicCounter > 0) {
toxicDamage = Math.floor((toxicCounter * maxHP) / 16);
toxicCounter++;
}
var sum = 0;
var lastc = 0;
for (var i = 0; i < n; i++) {
var c = void 0;
if (i === 0 || damage[i] !== damage[i - 1]) {
c = computeKOChance(damage, hp - damage[i] + eot - toxicDamage, eot, hits - 1, timesUsed, maxHP, toxicCounter);
}
else {
c = lastc;
}
if (c === 1) {
sum += n - i;
break;
}
else {
sum += c;
}
lastc = c;
}
return sum / n;
}
function predictTotal(damage, eot, hits, timesUsed, toxicCounter, maxHP) {
var toxicDamage = 0;
if (toxicCounter > 0) {
for (var i = 0; i < hits - 1; i++) {
toxicDamage += Math.floor(((toxicCounter + i) * maxHP) / 16);
}
}
var total = 0;
if (hits > 1 && timesUsed === 1) {
total = damage * hits - eot * (hits - 1) + toxicDamage;
}
else {
total = damage - eot * (hits - 1) + toxicDamage;
}
return total;
}
function squashMultihit(gen, d, hits, err) {
if (err === void 0) { err = true; }
if (d.length === 1) {
return [d[0] * hits];
}
else if (gen.num === 1) {
var r = [];
for (var i = 0; i < d.length; i++) {
r[i] = d[i] * hits;
}
return r;
}
else if (d.length === 16) {
switch (hits) {
case 2:
return [
2 * d[0], d[2] + d[3], d[4] + d[4], d[4] + d[5], d[5] + d[6], d[6] + d[6],
d[6] + d[7], d[7] + d[7], d[8] + d[8], d[8] + d[9], d[9] + d[9], d[9] + d[10],
d[10] + d[11], d[11] + d[11], d[12] + d[13], 2 * d[15],
];
case 3:
return [
3 * d[0], d[3] + d[3] + d[4], d[4] + d[4] + d[5], d[5] + d[5] + d[6],
d[5] + d[6] + d[6], d[6] + d[6] + d[7], d[6] + d[7] + d[7], d[7] + d[7] + d[8],
d[7] + d[8] + d[8], d[8] + d[8] + d[9], d[8] + d[9] + d[9], d[9] + d[9] + d[10],
d[9] + d[10] + d[10], d[10] + d[11] + d[11], d[11] + d[12] + d[12], 3 * d[15],
];
case 4:
return [
4 * d[0], 4 * d[4], d[4] + d[5] + d[5] + d[5], d[5] + d[5] + d[6] + d[6],
4 * d[6], d[6] + d[6] + d[7] + d[7], 4 * d[7], d[7] + d[7] + d[7] + d[8],
d[7] + d[8] + d[8] + d[8], 4 * d[8], d[8] + d[8] + d[9] + d[9], 4 * d[9],
d[9] + d[9] + d[10] + d[10], d[10] + d[10] + d[10] + d[11], 4 * d[11], 4 * d[15],
];
case 5:
return [
5 * d[0], d[4] + d[4] + d[4] + d[5] + d[5], d[5] + d[5] + d[5] + d[5] + d[6],
d[5] + d[6] + d[6] + d[6] + d[6], d[6] + d[6] + d[6] + d[6] + d[7],
d[6] + d[6] + d[7] + d[7] + d[7], 5 * d[7], d[7] + d[7] + d[7] + d[8] + d[8],
d[7] + d[7] + d[8] + d[8] + d[8], 5 * d[8], d[8] + d[8] + d[8] + d[9] + d[9],
d[8] + d[9] + d[9] + d[9] + d[9], d[9] + d[9] + d[9] + d[9] + d[10],
d[9] + d[10] + d[10] + d[10] + d[10], d[10] + d[10] + d[11] + d[11] + d[11], 5 * d[15],
];
case 10:
return [
10 * d[0], 10 * d[4], 3 * d[4] + 7 * d[5], 5 * d[5] + 5 * d[6], 10 * d[6],
5 * d[6] + 5 * d[7], 10 * d[7], 7 * d[7] + 3 * d[8], 3 * d[7] + 7 * d[8], 10 * d[8],
5 * d[8] + 5 * d[9], 4 * d[9], 5 * d[9] + 5 * d[10], 7 * d[10] + 3 * d[11], 10 * d[11],
10 * d[15],
];
default:
(0, util_1.error)(err, "Unexpected # of hits: ".concat(hits));
return d;
}
}
else if (d.length === 39) {
switch (hits) {
case 2:
return [
2 * d[0], 2 * d[7], 2 * d[10], 2 * d[12], 2 * d[14], d[15] + d[16],
2 * d[17], d[18] + d[19], d[19] + d[20], 2 * d[21], d[22] + d[23],
2 * d[24], 2 * d[26], 2 * d[28], 2 * d[31], 2 * d[38],
];
case 3:
return [
3 * d[0], 3 * d[9], 3 * d[12], 3 * d[13], 3 * d[15], 3 * d[16],
3 * d[17], 3 * d[18], 3 * d[20], 3 * d[21], 3 * d[22], 3 * d[23],
3 * d[25], 3 * d[26], 3 * d[29], 3 * d[38],
];
case 4:
return [
4 * d[0], 2 * d[10] + 2 * d[11], 4 * d[13], 4 * d[14], 2 * d[15] + 2 * d[16],
2 * d[16] + 2 * d[17], 2 * d[17] + 2 * d[18], 2 * d[18] + 2 * d[19],
2 * d[19] + 2 * d[20], 2 * d[20] + 2 * d[21], 2 * d[21] + 2 * d[22],
2 * d[22] + 2 * d[23], 4 * d[24], 4 * d[25], 2 * d[27] + 2 * d[28], 4 * d[38],
];
case 5:
return [
5 * d[0], 5 * d[11], 5 * d[13], 5 * d[15], 5 * d[16], 5 * d[17],
5 * d[18], 5 * d[19], 5 * d[19], 5 * d[20], 5 * d[21], 5 * d[22],
5 * d[23], 5 * d[25], 5 * d[27], 5 * d[38],
];
case 10:
return [
10 * d[0], 10 * d[11], 10 * d[13], 10 * d[15], 10 * d[16], 10 * d[17],
10 * d[18], 10 * d[19], 10 * d[19], 10 * d[20], 10 * d[21], 10 * d[22],
10 * d[23], 10 * d[25], 10 * d[27], 10 * d[38],
];
default:
(0, util_1.error)(err, "Unexpected # of hits: ".concat(hits));
return d;
}
}
else if (d.length === 256) {
if (hits > 1) {
(0, util_1.error)(err, "Unexpected # of hits for Parental Bond: ".concat(hits));
}
var r = [];
for (var i = 0; i < 16; i++) {
var val = 0;
for (var j = 0; j < 16; j++) {
val += d[i + j];
}
r[i] = Math.round(val / 16);
}
return r;
}
else {
(0, util_1.error)(err, "Unexpected # of possible damage values: ".concat(d.length));
return d;
}
}
function buildDescription(description, attacker, defender) {
var _a = __read(getDescriptionLevels(attacker, defender), 2), attackerLevel = _a[0], defenderLevel = _a[1];
var output = '';
if (description.attackBoost) {
if (description.attackBoost > 0) {
output += '+';
}
output += description.attackBoost + ' ';
}
output = appendIfSet(output, attackerLevel);
output = appendIfSet(output, description.attackEVs);
output = appendIfSet(output, description.attackerItem);
output = appendIfSet(output, description.attackerAbility);
output = appendIfSet(output, description.rivalry);
if (description.isBurned) {
output += 'burned ';
}
if (description.alliesFainted) {
output += Math.min(5, description.alliesFainted) +
" ".concat(description.alliesFainted === 1 ? 'ally' : 'allies', " fainted ");
}
if (description.attackerTera) {
output += "Tera ".concat(description.attackerTera, " ");
}
if (description.isBeadsOfRuin) {
output += 'Beads of Ruin ';
}
if (description.isSwordOfRuin) {
output += 'Sword of Ruin ';
}
output += description.attackerName + ' ';
if (description.isHelpingHand) {
output += 'Helping Hand ';
}
if (description.isFlowerGiftAttacker) {
output += ' with an ally\'s Flower Gift ';
}
if (description.isBattery) {
output += ' Battery boosted ';
}
if (description.isPowerSpot) {
output += ' Power Spot boosted ';
}
if (description.isSwitching) {
output += ' switching boosted ';
}
output += description.moveName + ' ';
if (description.moveBP && description.moveType) {
output += '(' + description.moveBP + ' BP ' + description.moveType + ') ';
}
else if (description.moveBP) {
output += '(' + description.moveBP + ' BP) ';
}
else if (description.moveType) {
output += '(' + description.moveType + ') ';
}
if (description.hits) {
output += '(' + description.hits + ' hits) ';
}
output = appendIfSet(output, description.moveTurns);
output += 'vs. ';
if (description.defenseBoost) {
if (description.defenseBoost > 0) {
output += '+';
}
output += description.defenseBoost + ' ';
}
output = appendIfSet(output, defenderLevel);
output = appendIfSet(output, description.HPEVs);
if (description.defenseEVs) {
output += '/ ' + description.defenseEVs + ' ';
}
output = appendIfSet(output, description.defenderItem);
output = appendIfSet(output, description.defenderAbility);
if (description.isTabletsOfRuin) {
output += 'Tablets of Ruin ';
}
if (description.isVesselOfRuin) {
output += 'Vessel of Ruin ';
}
if (description.isProtected) {
output += 'protected ';
}
if (description.isDefenderDynamaxed) {
output += 'Dynamax ';
}
if (description.defenderTera) {
output += "Tera ".concat(description.defenderTera, " ");
}
output += description.defenderName;
if (description.weather && description.terrain) {
}
else if (description.weather) {
output += ' in ' + description.weather;
}
else if (description.terrain) {
output += ' in ' + description.terrain + ' Terrain';
}
if (description.isReflect) {
output += ' through Reflect';
}
else if (description.isLightScreen) {
output += ' through Light Screen';
}
if (description.isFlowerGiftDefender) {
output += ' with an ally\'s Flower Gift';
}
if (description.isFriendGuard) {
output += ' with an ally\'s Friend Guard';
}
if (description.isAuroraVeil) {
output += ' with an ally\'s Aurora Veil';
}
if (description.isCritical) {
output += ' on a critical hit';
}
if (description.isWonderRoom) {
output += ' in Wonder Room';
}
return output;
}
function getDescriptionLevels(attacker, defender) {
if (attacker.level !== defender.level) {
return [
attacker.level === 100 ? '' : "Lvl ".concat(attacker.level),
defender.level === 100 ? '' : "Lvl ".concat(defender.level),
];
}
var elide = [100, 50, 5].includes(attacker.level);
var level = elide ? '' : "Lvl ".concat(attacker.level);
return [level, level];
}
function serializeText(arr) {
if (arr.length === 0) {
return '';
}
else if (arr.length === 1) {
return arr[0];
}
else if (arr.length === 2) {
return arr[0] + ' and ' + arr[1];
}
else {
var text = '';
for (var i = 0; i < arr.length - 1; i++) {
text += arr[i] + ', ';
}
return text + 'and ' + arr[arr.length - 1];
}
}
function appendIfSet(str, toAppend) {
return toAppend ? "".concat(str).concat(toAppend, " ") : str;
}
function toDisplay(notation, a, b, f) {
if (f === void 0) { f = 1; }
return notation === '%' ? Math.floor((a * (1000 / f)) / b) / 10 : Math.floor((a * (48 / f)) / b);
}
//# sourceMappingURL=desc.js.map