forked from smogon/pokemon-showdown-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-battle-tooltips.js
1408 lines (1335 loc) · 54.6 KB
/
client-battle-tooltips.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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var BattleTooltips = (function () {
// In addition to some static methods:
// BattleTooltips.tooltipAttrs()
// BattleTooltips.showTooltip()
// BattleTooltips.hideTooltip()
// Most tooltips tend to involve a battle and/or room object
function BattleTooltips(battle, room) {
this.battle = battle;
this.room = room;
// tooltips
var buf = '';
var tooltips = {
your2: {top: 70, left: 250, width: 80, height: 100},
your1: {top: 85, left: 320, width: 90, height: 100},
your0: {top: 90, left: 390, width: 100, height: 100},
my0: {top: 200, left: 130, width: 120, height: 160},
my1: {top: 200, left: 250, width: 150, height: 160},
my2: {top: 200, left: 350, width: 150, height: 160}
};
for (var active in tooltips) {
buf += '<div style="position:absolute;';
for (var css in tooltips[active]) {
buf += css + ':' + tooltips[active][css] + 'px;';
}
buf += '"' + this.tooltipAttrs(active, 'pokemon', true) + '></div>';
}
room.$foeHint.html(buf);
}
BattleTooltips.showTooltipFor = function (roomid, thing, type, elem, ownHeight) {
app.rooms[roomid].tooltips.showTooltip(thing, type, elem, ownHeight);
};
BattleTooltips.hideTooltip = function () {
$('#tooltipwrapper').html('');
};
// tooltips
// Touch delay, pressing finger more than that time will cause the tooltip to open.
// Shorter time will cause the button to click
var LONG_TAP_DELAY = 350; // ms
var touchTooltipTimeout;
var runClickActionOfButtonWithTooltip = false;
// Each time a finger presses the button this function will be callled
// First finger starts the counter, and when last finger leaves time is checked
BattleTooltips._handleTouchStartFor = function (e, roomid, thing, type, elem, ownHeight) {
// Prevent default on touch events to block mouse events when touch is used
e.preventDefault();
// On first tap start counting
if (e.touches.length === 1) {
// Timeout will be canceled by `_handleTouchEndFor` if a short tap have occurred
touchTooltipTimeout = setTimeout(function () {
touchTooltipTimeout = undefined;
BattleTooltips.showTooltipFor(roomid, thing, type, elem, ownHeight);
}, LONG_TAP_DELAY);
}
};
BattleTooltips._handleTouchLeaveFor = function (e) {
// Prevent default on touch events to block mouse events when touch is used
e.preventDefault();
// If tooltip is open and the last finger just left, close the tooptip
if (touchTooltipTimeout === undefined && e.touches.length === 0) {
BattleTooltips.hideTooltip();
}
};
BattleTooltips._handleTouchEndFor = function (e, elem) {
// Close tooptip if needed
BattleTooltips._handleTouchLeaveFor(e);
// If tooltip is not opened (`touchTooltipTimeout` is still defined) and the last finger left,
// meaning the timeout in `_handleTouchStartFor` wasn't fired, fire the action
if (touchTooltipTimeout !== undefined && e.touches.length === 0) {
clearTimeout(touchTooltipTimeout);
touchTooltipTimeout = undefined;
runClickActionOfButtonWithTooltip = true;
// Need to call `click` event manually because we prevented default behaviour of `touchend` event
elem.click();
}
};
// Call click on mouse up, because `runClickActionOfButtonWithTooltip` must be set before the click
BattleTooltips._handleMouseUpFor = function () {
BattleTooltips.hideTooltip();
runClickActionOfButtonWithTooltip = true;
};
// Stop click from doing it's action unless `runClickActionOfButtonWithTooltip` was set to true
// (in `_handleMouseUpFor` or in `_handleTouchEndFor`)
BattleTooltips._handleClickFor = function (e) {
if (!runClickActionOfButtonWithTooltip) {
e.stopPropagation();
} else {
// Reset `runClickActionOfButtonWithTooltip` value to false for next click
runClickActionOfButtonWithTooltip = false;
}
};
BattleTooltips.prototype.tooltipAttrs = function (thing, type, ownHeight) {
var roomid = this.room.id;
return ' onclick="BattleTooltips._handleClickFor(event)"' +
' ontouchstart="BattleTooltips._handleTouchStartFor(event, \'' + roomid + '\', \'' + Tools.escapeHTML('' + thing, true) + '\',\'' + type + '\', this, ' + (ownHeight ? 'true' : 'false') + ')"' +
' ontouchend="BattleTooltips._handleTouchEndFor(event, this)"' +
' ontouchleave="BattleTooltips._handleTouchLeaveFor(event)"' +
' ontouchcancel="BattleTooltips._handleTouchLeaveFor(event)"' +
' onmouseover="BattleTooltips.showTooltipFor(\'' + roomid + '\', \'' + Tools.escapeHTML('' + thing, true) + '\',\'' + type + '\', this, ' + (ownHeight ? 'true' : 'false') + ')"' +
' onfocus="BattleTooltips.showTooltipFor(\'' + roomid + '\', \'' + Tools.escapeHTML('' + thing, true) + '\',\'' + type + '\', this, ' + (ownHeight ? 'true' : 'false') + ')"' +
' onmouseout="BattleTooltips.hideTooltip()"' +
' onblur="BattleTooltips.hideTooltip()"' +
' onmouseup="BattleTooltips._handleMouseUpFor()"' +
' aria-describedby="tooltipwrapper"';
};
BattleTooltips.prototype.showTooltip = function (thing, type, elem, ownHeight) {
var room = this.room;
var text = '';
switch (type) {
case 'move':
case 'zmove':
var move = Tools.getMove(thing);
if (!move) return;
text = this.showMoveTooltip(move, type === 'zmove');
break;
case 'pokemon':
var side = room.battle[thing.slice(0, -1) + "Side"];
var pokemon = side.active[thing.slice(-1)];
if (!pokemon) return;
/* falls through */
case 'sidepokemon':
var pokemonData;
var isActive = (type === 'pokemon');
if (room.myPokemon) {
if (!pokemon) {
pokemonData = room.myPokemon[parseInt(thing, 10)];
pokemon = pokemonData;
} else if (room.controlsShown && pokemon.side === room.battle.mySide) {
// battlePokemon = pokemon;
pokemonData = room.myPokemon[pokemon.slot];
}
}
text = this.showPokemonTooltip(pokemon, pokemonData, isActive);
break;
}
var offset = {
left: 150,
top: 500
};
if (elem) offset = $(elem).offset();
var x = offset.left - 2;
if (elem) {
if (ownHeight) offset = $(elem).offset();
else offset = $(elem).parent().offset();
}
var y = offset.top - 5;
if (x > room.leftWidth + 335) x = room.leftWidth + 335;
if (y < 140) y = 140;
if (x > $(window).width() - 303) x = Math.max($(window).width() - 303, 0);
if (!$('#tooltipwrapper').length) $(document.body).append('<div id="tooltipwrapper" onclick="$(\'#tooltipwrapper\').html(\'\');" role="tooltip"></div>');
$('#tooltipwrapper').css({
left: x,
top: y
});
$('#tooltipwrapper').html(text).appendTo(document.body);
if (elem) {
var height = $('#tooltipwrapper .tooltip').height();
if (height > y) {
y += height + 10;
if (ownHeight) y += $(elem).height();
else y += $(elem).parent().height();
$('#tooltipwrapper').css('top', y);
}
}
};
BattleTooltips.prototype.hideTooltip = function () {
BattleTooltips.hideTooltip();
};
BattleTooltips.prototype.zMoveTable = {
Poison: "Acid Downpour",
Fighting: "All-Out Pummeling",
Dark: "Black Hole Eclipse",
Grass: "Bloom Doom",
Normal: "Breakneck Blitz",
Rock: "Continental Crush",
Steel: "Corkscrew Crash",
Dragon: "Devastating Drake",
Electric: "Gigavolt Havoc",
Water: "Hydro Vortex",
Fire: "Inferno Overdrive",
Ghost: "Never-Ending Nightmare",
Bug: "Savage Spin-Out",
Psychic: "Shattered Psyche",
Ice: "Subzero Slammer",
Flying: "Supersonic Skystrike",
Ground: "Tectonic Rage",
Fairy: "Twinkle Tackle"
};
BattleTooltips.prototype.showMoveTooltip = function (move, isZ) {
var text = '';
var basePowerText = '';
var additionalInfo = '';
var yourActive = this.battle.yourSide.active;
var pokemon = this.battle.mySide.active[this.room.choice.choices.length];
var pokemonData = this.room.myPokemon[pokemon.slot];
// TODO: move this somewhere it makes more sense
if (pokemon.ability === '(suppressed)') pokemonData.ability = '(suppressed)';
var ability = toId(pokemonData.ability || pokemon.ability || pokemonData.baseAbility);
if (isZ) {
var item = Tools.getItem(pokemonData.item);
if (item.zMoveFrom == move.name) {
move = Tools.getMove(item.zMove);
} else if (move.category === 'Status') {
move = JSON.parse(JSON.stringify(move));
move.name = 'Z-' + move.name;
// TODO: show zMoveBoost/Effect
} else {
var zmove = Tools.getMove(this.zMoveTable[item.zMoveType]);
zmove = JSON.parse(JSON.stringify(zmove));
zmove.category = move.category;
zmove.basePower = move.zMovePower;
move = zmove;
// TODO: Weather Ball type-changing shenanigans
}
}
var basePower = move.basePower;
// Check if there are more than one active Pokémon to check for multiple possible BPs.
if (yourActive.length > 1) {
// We check if there is a difference in base powers to note it.
// Otherwise, it is just shown as in singles.
// The trick is that we need to calculate it first for each Pokémon to see if it changes.
var previousBasepower = false;
var difference = false;
var basePowers = [];
for (var i = 0; i < yourActive.length; i++) {
if (!yourActive[i]) continue;
basePower = this.getMoveBasePower(move, pokemon, yourActive[i]);
if (previousBasepower === false) previousBasepower = basePower;
if (previousBasepower !== basePower) difference = true;
if (!basePower) basePower = '—';
basePowers.push('Base power for ' + yourActive[i].name + ': ' + basePower);
}
if (difference) {
basePowerText = '<p>' + basePowers.join('<br />') + '</p>';
}
// Falls through to not to repeat code on showing the base power.
}
if (!basePowerText) {
var activeTarget = yourActive[0] || yourActive[1] || yourActive[2];
basePower = this.getMoveBasePower(move, pokemon, activeTarget) || basePower;
if (!basePower) basePower = '—';
basePowerText = '<p>Base power: ' + basePower + '</p>';
}
var accuracy = this.getMoveAccuracy(move, pokemon);
// Handle move type for moves that vary their type.
var moveType = this.getMoveType(move, pokemon);
// Deal with Nature Power special case, indicating which move it calls.
if (move.id === 'naturepower') {
var calls;
if (this.battle.gen > 5) {
if (this.battle.hasPseudoWeather('Electric Terrain')) {
calls = 'Thunderbolt';
} else if (this.battle.hasPseudoWeather('Grassy Terrain')) {
calls = 'Energy Ball';
} else if (this.battle.hasPseudoWeather('Misty Terrain')) {
calls = 'Moonblast';
} else if (this.battle.hasPseudoWeather('Psychic Terrain')) {
calls = 'Psychic';
} else {
calls = 'Tri Attack';
}
} else if (this.battle.gen > 3) {
// In gens 4 and 5 it calls Earthquake.
calls = 'Earthquake';
} else {
// In gen 3 it calls Swift, so it retains its normal typing.
calls = 'Swift';
}
calls = Tools.getMove(calls);
additionalInfo = 'Calls ' + Tools.getTypeIcon(this.getMoveType(calls, pokemon)) + ' ' + calls.name;
}
text = '<div class="tooltipinner"><div class="tooltip">';
var category = Tools.getCategory(move, this.battle.gen, moveType);
text += '<h2>' + move.name + '<br />' + Tools.getTypeIcon(moveType) + ' <img src="' + Tools.resourcePrefix;
text += 'sprites/categories/' + category + '.png" alt="' + category + '" /></h2>';
text += basePowerText;
if (additionalInfo) text += '<p>' + additionalInfo + '</p>';
text += '<p>Accuracy: ' + accuracy + '</p>';
if (move.desc) {
if (this.battle.gen < 7 || this.battle.hardcoreMode) {
var desc = move.shortDesc;
for (var i = this.battle.gen; i < 7; i++) {
if (move.id in BattleTeambuilderTable['gen' + i].overrideMoveDesc) {
desc = BattleTeambuilderTable['gen' + i].overrideMoveDesc[move.id];
break;
}
}
text += '<p class="section">' + desc + '</p>';
} else {
text += '<p class="section">';
if (move.priority > 1) {
text += 'Nearly always moves first <em>(priority +' + move.priority + ')</em>.</p><p>';
} else if (move.priority <= -1) {
text += 'Nearly always moves last <em>(priority −' + (-move.priority) + ')</em>.</p><p>';
} else if (move.priority == 1) {
text += 'Usually moves first <em>(priority +' + move.priority + ')</em>.</p><p>';
}
text += '' + (move.desc || move.shortDesc) + '</p>';
if ('defrost' in move.flags) {
text += '<p class="movetag">The user thaws out if it is frozen.</p>';
}
if (!('protect' in move.flags) && move.target !== 'self' && move.target !== 'allySide' && move.target !== 'allyTeam') {
text += '<p class="movetag">Bypasses Protect <small>(and Detect, King\'s Shield, Spiky Shield)</small></p>';
}
if ('authentic' in move.flags) {
text += '<p class="movetag">Bypasses Substitute <small>(but does not break it)</small></p>';
}
if (!('reflectable' in move.flags) && move.target !== 'self' && move.target !== 'allySide' && move.target !== 'allyTeam' && move.category === 'Status') {
text += '<p class="movetag">✓ Not bounceable <small>(can\'t be bounced by Magic Coat/Bounce)</small></p>';
}
if ('contact' in move.flags) {
text += '<p class="movetag">✓ Contact <small>(triggers Iron Barbs, Spiky Shield, etc)</small></p>';
}
if ('sound' in move.flags) {
text += '<p class="movetag">✓ Sound <small>(doesn\'t affect Soundproof pokemon)</small></p>';
}
if ('powder' in move.flags) {
text += '<p class="movetag">✓ Powder <small>(doesn\'t affect Grass, Overcoat, Safety Goggles)</small></p>';
}
if ('punch' in move.flags && ability === 'ironfist') {
text += '<p class="movetag">✓ Fist <small>(boosted by Iron Fist)</small></p>';
}
if ('pulse' in move.flags && ability === 'megalauncher') {
text += '<p class="movetag">✓ Pulse <small>(boosted by Mega Launcher)</small></p>';
}
if ('bite' in move.flags && ability === 'strongjaw') {
text += '<p class="movetag">✓ Bite <small>(boosted by Strong Jaw)</small></p>';
}
if ((move.recoil || move.hasCustomRecoil) && ability === 'reckless') {
text += '<p class="movetag">✓ Recoil <small>(boosted by Reckless)</small></p>';
}
if ('bullet' in move.flags) {
text += '<p class="movetag">✓ Ballistic <small>(doesn\'t affect Bulletproof pokemon)</small></p>';
}
if (this.battle.gameType === 'doubles') {
if (move.target === 'allAdjacent') {
text += '<p class="movetag">◎ Hits both foes and ally.</p>';
} else if (move.target === 'allAdjacentFoes') {
text += '<p class="movetag">◎ Hits both foes.</p>';
}
} else if (this.battle.gameType === 'triples') {
if (move.target === 'allAdjacent') {
text += '<p class="movetag">◎ Hits adjacent foes and allies.</p>';
} else if (move.target === 'allAdjacentFoes') {
text += '<p class="movetag">◎ Hits adjacent foes.</p>';
} else if (move.target === 'any') {
text += '<p class="movetag">◎ Can target distant Pokémon in Triples.</p>';
}
}
}
}
text += '</div></div>';
return text;
};
BattleTooltips.prototype.showPokemonTooltip = function (pokemon, pokemonData, isActive) {
var text = '';
var gender = pokemon.gender;
if (gender) gender = ' <img src="' + Tools.resourcePrefix + 'fx/gender-' + gender.toLowerCase() + '.png" alt="' + gender + '" />';
text = '<div class="tooltipinner"><div class="tooltip">';
text += '<h2>' + pokemon.getFullName() + gender + (pokemon.level !== 100 ? ' <small>L' + pokemon.level + '</small>' : '') + '<br />';
var template = Tools.getTemplate(pokemon.getSpecies ? pokemon.getSpecies() : pokemon.species);
if (pokemon.volatiles && pokemon.volatiles.formechange) {
if (pokemon.volatiles.transform) {
text += '<small>(Transformed into ' + pokemon.volatiles.formechange[1] + ')</small><br />';
} else {
text += '<small>(Forme: ' + pokemon.volatiles.formechange[1] + ')</small><br />';
}
}
var types = this.getPokemonTypes(pokemon);
if (pokemon.volatiles && (pokemon.volatiles.typechange || pokemon.volatiles.typeadd)) text += '<small>(Type changed)</small><br />';
if (types) {
text += types.map(Tools.getTypeIcon).join(' ');
} else {
text += 'Types unknown';
}
text += '</h2>';
if (pokemon.fainted) {
text += '<p>HP: (fainted)</p>';
} else if (this.battle.hardcoreMode) {
if (pokemonData) {
text += '<p>HP: ' + pokemonData.hp + '/' + pokemonData.maxhp + (pokemon.status ? ' <span class="status ' + pokemon.status + '">' + pokemon.status.toUpperCase() + '</span>' : '') + '</p>';
}
} else {
var exacthp = '';
if (pokemonData) exacthp = ' (' + pokemonData.hp + '/' + pokemonData.maxhp + ')';
else if (pokemon.maxhp == 48) exacthp = ' <small>(' + pokemon.hp + '/' + pokemon.maxhp + ' pixels)</small>';
text += '<p>HP: ' + pokemon.hpDisplay() + exacthp + (pokemon.status ? ' <span class="status ' + pokemon.status + '">' + pokemon.status.toUpperCase() + '</span>' : '');
if (pokemon.statusData) {
if (pokemon.status === 'tox') {
if (pokemon.ability === 'Poison Heal' || pokemon.ability === 'Magic Guard') {
text += ' <small>Would take if ability removed: ' + Math.floor(100 / 16) * Math.min(pokemon.statusData.toxicTurns, 15) + '%</small>';
} else {
text += ' Next damage: ' + Math.floor(100 / 16) * Math.min(pokemon.statusData.toxicTurns, 15) + '%';
}
} else if (pokemon.status === 'slp') {
text += ' Turns asleep: ' + pokemon.statusData.sleepTurns;
}
}
text += '</p>';
}
var showOtherSees = !this.battle.hardcoreMode && isActive;
if (pokemonData) {
if (this.battle.gen > 2) {
var abilityText = Tools.getAbility(pokemonData.baseAbility).name;
var ability = Tools.getAbility(pokemonData.ability || pokemon.ability).name;
if (ability && (ability !== abilityText)) {
abilityText = ability + ' (base: ' + abilityText + ')';
}
text += '<p>Ability: ' + abilityText;
if (pokemonData.item) {
text += ' / Item: ' + Tools.getItem(pokemonData.item).name;
}
text += '</p>';
} else if (pokemonData.item) {
item = Tools.getItem(pokemonData.item).name;
text += '<p>Item: ' + item + '</p>';
}
text += '<p>' + pokemonData.stats['atk'] + ' Atk / ' + pokemonData.stats['def'] + ' Def / ' + pokemonData.stats['spa'];
if (this.battle.gen === 1) {
text += ' Spc / ';
} else {
text += ' SpA / ' + pokemonData.stats['spd'] + ' SpD / ';
}
text += pokemonData.stats['spe'] + ' Spe</p>';
if (showOtherSees) {
if (this.battle.gen > 1) {
var modifiedStats = this.calculateModifiedStats(pokemon, pokemonData);
var statsText = this.makeModifiedStatText(pokemonData, modifiedStats);
if (statsText.match('<b')) {
text += '<p>After Modifiers:</p>';
text += statsText;
}
}
text += '<p class="section">Opponent sees:</p>';
}
} else {
showOtherSees = !this.battle.hardcoreMode;
}
if (this.battle.gen > 2 && showOtherSees) {
if (!pokemon.baseAbility && !pokemon.ability) {
if (template.abilities) {
var abilitiesInThisGen = Tools.getAbilitiesFor(template, this.battle.gen);
text += '<p>Possible abilities: ' + Tools.getAbility(abilitiesInThisGen['0']).name;
if (abilitiesInThisGen['1']) text += ', ' + Tools.getAbility(abilitiesInThisGen['1']).name;
if (abilitiesInThisGen['H']) text += ', ' + Tools.getAbility(abilitiesInThisGen['H']).name;
if (abilitiesInThisGen['S']) text += ', ' + Tools.getAbility(abilitiesInThisGen['S']).name;
text += '</p>';
}
} else if (pokemon.ability) {
if (pokemon.ability === pokemon.baseAbility) {
text += '<p>Ability: ' + Tools.getAbility(pokemon.ability).name + '</p>';
} else {
text += '<p>Ability: ' + Tools.getAbility(pokemon.ability).name + ' (base: ' + Tools.getAbility(pokemon.baseAbility).name + ')' + '</p>';
}
} else if (pokemon.baseAbility) {
text += '<p>Ability: ' + Tools.getAbility(pokemon.baseAbility).name + '</p>';
}
}
if (showOtherSees) {
var item = '';
var itemEffect = pokemon.itemEffect || '';
if (pokemon.prevItem) {
item = 'None';
if (itemEffect) itemEffect += '; ';
var prevItem = Tools.getItem(pokemon.prevItem).name;
itemEffect += pokemon.prevItemEffect ? prevItem + ' was ' + pokemon.prevItemEffect : 'was ' + prevItem;
}
if (pokemon.item) item = Tools.getItem(pokemon.item).name;
if (itemEffect) itemEffect = ' (' + itemEffect + ')';
if (item) text += '<p>Item: ' + item + itemEffect + '</p>';
if (template.baseStats) {
text += '<p>' + this.getTemplateMinSpeed(template, pokemon.level) + ' to ' + this.getTemplateMaxSpeed(template, pokemon.level) + ' Spe (before items/abilities/modifiers)</p>';
}
}
if (pokemonData && !isActive) {
text += '<p class="section">';
var battlePokemon = this.battle.getPokemon(pokemon.ident, pokemon.details);
for (var i = 0; i < pokemonData.moves.length; i++) {
var move = Tools.getMove(pokemonData.moves[i]);
var name = move.name;
var pp = 0, maxpp = 0;
if (battlePokemon && battlePokemon.moveTrack) {
for (var j = 0; j < battlePokemon.moveTrack.length; j++) {
if (name === battlePokemon.moveTrack[j][0]) {
name = this.getPPUseText(battlePokemon.moveTrack[j], true);
break;
}
}
}
text += '• ' + name + '<br />';
}
text += '</p>';
} else if (!this.battle.hardcoreMode && pokemon.moveTrack && pokemon.moveTrack.length) {
text += '<p class="section">';
for (var i = 0; i < pokemon.moveTrack.length; i++) {
text += '• ' + this.getPPUseText(pokemon.moveTrack[i]) + '<br />';
}
if (pokemon.moveTrack.length > 4) {
text += '(More than 4 moves is usually a sign of Illusion Zoroark/Zorua.)';
}
if (this.battle.gen === 3) {
text += '(Pressure is not visible in Gen 3, so if you have Pressure, more PP may have been lost than shown here.)';
}
text += '</p>';
}
text += '</div></div>';
return text;
};
BattleTooltips.prototype.calculateModifiedStats = function (pokemon, pokemonData) {
var stats = {};
for (var statName in pokemonData.stats) {
stats[statName] = pokemonData.stats[statName];
if (pokemon.boosts && pokemon.boosts[statName]) {
var boostTable = [1, 1.5, 2, 2.5, 3, 3.5, 4];
if (pokemon.boosts[statName] > 0) {
stats[statName] *= boostTable[pokemon.boosts[statName]];
} else {
if (this.battle.gen <= 2) boostTable = [1, 100 / 66, 2, 2.5, 100 / 33, 100 / 28, 4];
stats[statName] /= boostTable[-pokemon.boosts[statName]];
}
stats[statName] = Math.floor(stats[statName]);
}
}
var ability = toId(pokemonData.ability || pokemon.ability || pokemonData.baseAbility);
if ('gastroacid' in pokemon.volatiles) ability = '';
// check for burn, paralysis, guts, quick feet
if (pokemon.status) {
if (this.battle.gen > 2 && ability === 'guts') {
stats.atk = Math.floor(stats.atk * 1.5);
} else if (pokemon.status === 'brn') {
stats.atk = Math.floor(stats.atk * 0.5);
}
if (this.battle.gen > 2 && ability === 'quickfeet') {
stats.spe = Math.floor(stats.spe * 1.5);
} else if (pokemon.status === 'par') {
if (this.battle.gen > 6) {
stats.spe = Math.floor(stats.spe * 0.5);
} else {
stats.spe = Math.floor(stats.spe * 0.25);
}
}
}
// gen 1 doesn't support items
if (this.battle.gen <= 1) {
for (var statName in stats) {
if (stats[statName] > 999) stats[statName] = 999;
}
return stats;
}
var item = toId(pokemonData.item);
if (ability === 'klutz' && item !== 'machobrace') item = '';
var species = pokemon.baseSpecies;
// check for light ball, thick club, metal/quick powder
// the only stat modifying items in gen 2 were light ball, thick club, metal powder
if (item === 'lightball' && species === 'Pikachu') {
if (this.battle.gen >= 4) stats.atk *= 2;
stats.spa *= 2;
}
if (item === 'thickclub') {
if (species === 'Marowak' || species === 'Cubone') {
stats.atk *= 2;
}
}
if (species === 'Ditto' && !('transform' in pokemon.volatiles)) {
if (item === 'quickpowder') {
stats.spe *= 2;
}
if (item === 'metalpowder') {
if (this.battle.gen === 2) {
stats.def = Math.floor(stats.def * 1.5);
stats.spd = Math.floor(stats.spd * 1.5);
} else {
stats.def *= 2;
}
}
}
// check abilities other than Guts and Quick Feet
// check items other than light ball, thick club, metal/quick powder
if (this.battle.gen <= 2) {
return stats;
}
var weather = this.battle.weather;
if (weather) {
// Check if anyone has an anti-weather ability
for (var i = 0; i < this.battle.p1.active.length; i++) {
if (this.battle.p1.active[i] && this.battle.p1.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
weather = '';
break;
}
if (this.battle.p2.active[i] && this.battle.p2.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
weather = '';
break;
}
}
}
if (item === 'choiceband') {
stats.atk = Math.floor(stats.atk * 1.5);
}
if (ability === 'purepower' || ability === 'hugepower') {
stats.atk *= 2;
}
if (ability === 'hustle') {
stats.atk = Math.floor(stats.atk * 1.5);
}
if (weather) {
if (weather === 'sunnyday' || weather === 'desolateland') {
if (ability === 'solarpower') {
stats.spa = Math.floor(stats.spa * 1.5);
}
var allyActive = pokemon.side.active;
if (allyActive.length > 1) {
for (var i = 0; i < allyActive.length; i++) {
var ally = allyActive[i];
if (!ally || ally.fainted) continue;
if (ally.ability === 'flowergift' && (ally.baseSpecies === 'Cherrim' || this.battle.gen <= 4)) {
stats.atk = Math.floor(stats.atk * 1.5);
stats.spd = Math.floor(stats.spd * 1.5);
}
}
}
}
if (this.battle.gen >= 4 && this.pokemonHasType(pokemonData, 'Rock') && weather === 'sandstorm') {
stats.spd = Math.floor(stats.spd * 1.5);
}
if (ability === 'chlorophyll' && (weather === 'sunnyday' || weather === 'desolateland')) {
stats.spe *= 2;
}
if (ability === 'swiftswim' && (weather === 'raindance' || weather === 'primordialsea')) {
stats.spe *= 2;
}
if (ability === 'sandrush' && weather === 'sandstorm') {
stats.spe *= 2;
}
if (ability === 'slushrush' && weather === 'hail') {
stats.spe *= 2;
}
}
if (ability === 'defeatist' && pokemonData.hp <= pokemonData.maxhp / 2) {
stats.atk = Math.floor(stats.atk * 0.5);
stats.spa = Math.floor(stats.spa * 0.5);
}
if (pokemon.volatiles) {
if ('slowstart' in pokemon.volatiles) {
stats.atk = Math.floor(stats.atk * 0.5);
stats.spe = Math.floor(stats.spe * 0.5);
}
if (ability === 'unburden' && 'itemremoved' in pokemon.volatiles && !item) {
stats.spe *= 2;
}
}
if (ability === 'marvelscale' && pokemon.status) {
stats.def = Math.floor(stats.def * 1.5);
}
if (item === 'eviolite' && Tools.getTemplate(pokemon.species).evos) {
stats.def = Math.floor(stats.def * 1.5);
stats.spd = Math.floor(stats.spd * 1.5);
}
if (ability === 'grasspelt' && this.battle.hasPseudoWeather('Grassy Terrain')) {
stats.def = Math.floor(stats.def * 1.5);
}
if (ability === 'surgesurfer' && this.battle.hasPseudoWeather('Electric Terrain')) {
stats.spe *= 2;
}
if (item === 'choicespecs') {
stats.spa = Math.floor(stats.spa * 1.5);
}
if (item === 'deepseatooth' && species === 'Clamperl') {
stats.spa *= 2;
}
if (item === 'souldew' && this.battle.gen <= 6 && (species === 'Latios' || species === 'Latias')) {
stats.spa = Math.floor(stats.spa * 1.5);
stats.spd = Math.floor(stats.spd * 1.5);
}
if (ability === 'plus' || ability === 'minus') {
var allyActive = pokemon.side.active;
if (allyActive.length > 1) {
var abilityName = (ability === 'plus' ? 'Plus' : 'Minus');
for (var i = 0; i < allyActive.length; i++) {
var ally = allyActive[i];
if (!(ally && ally !== pokemon && !ally.fainted)) continue;
if (!(ally.ability === 'Plus' || ally.ability === 'Minus')) continue;
if (this.battle.gen <= 4 && ally.ability === abilityName) continue;
stats.spa = Math.floor(stats.spa * 1.5);
break;
}
}
}
if (item === 'assaultvest') {
stats.spd = Math.floor(stats.spd * 1.5);
}
if (item === 'deepseascale' && species === 'Clamperl') {
stats.spd *= 2;
}
if (item === 'choicescarf') {
stats.spe = Math.floor(stats.spe * 1.5);
}
if (item === 'ironball' || item === 'machobrace' || /power(?!herb)/.test(item)) {
stats.spe = Math.floor(stats.spe * 0.5);
}
if (ability === 'furcoat') {
stats.def *= 2;
}
return stats;
};
BattleTooltips.prototype.makeModifiedStatText = function (pokemonData, modifiedStats) {
var statsText = '<p>';
var statTable = {atk: ' Atk / ', def: ' Def / ', spa: ' SpA / ',
spc: ' Spc / ', spd: ' SpD / ', spe: ' Spe</p>'};
statsText += this.boldModifiedStat(pokemonData, modifiedStats, 'atk') + statTable['atk'];
statsText += this.boldModifiedStat(pokemonData, modifiedStats, 'def') + statTable['def'];
statsText += this.boldModifiedStat(pokemonData, modifiedStats, 'spa');
if (this.battle.gen === 1) {
statsText += statTable['spc'];
} else {
statsText += statTable['spa'];
statsText += this.boldModifiedStat(pokemonData, modifiedStats, 'spd') + statTable['spd'];
}
statsText += this.boldModifiedStat(pokemonData, modifiedStats, 'spe') + statTable['spe'];
return statsText;
};
BattleTooltips.prototype.boldModifiedStat = function (pokemonData, modifiedStats, statName) {
var statText = '';
if (pokemonData.stats[statName] === modifiedStats[statName]) {
statText += '' + modifiedStats[statName];
} else if (pokemonData.stats[statName] > modifiedStats[statName]) {
statText += '<b class="stat-lowered">' + modifiedStats[statName] + '</b>';
} else {
statText += '<b class="stat-boosted">' + modifiedStats[statName] + '</b>';
}
return statText;
};
BattleTooltips.prototype.getPPUseText = function (moveTrackRow, showKnown) {
var moveName = moveTrackRow[0];
var ppUsed = moveTrackRow[1];
var move, maxpp;
if (moveName.charAt(0) === '*') {
move = Tools.getMove(moveName.substr(1));
maxpp = 5;
} else {
move = Tools.getMove(moveName);
maxpp = move.pp;
if (this.battle.gen < 7) {
var table = BattleTeambuilderTable['gen' + this.battle.gen];
if (move.id in table.overridePP) maxpp = table.overridePP[move.id];
}
maxpp = Math.floor(maxpp * 8 / 5);
}
if (ppUsed === Infinity) return move.name + ' <small>(0/' + maxpp + ')</small>';
if (ppUsed || moveName.charAt(0) === '*') return move.name + ' <small>(' + (maxpp - ppUsed) + '/' + maxpp + ')</small>';
return move.name + (showKnown ? ' <small>(revealed)</small>' : '');
};
// Functions to calculate speed ranges of an opponent.
BattleTooltips.prototype.getTemplateMinSpeed = function (template, level) {
var baseSpe = template.baseStats['spe'];
var tier = this.battle.tier;
var gen = this.battle.gen;
if (gen < 7) {
var overrideStats = BattleTeambuilderTable['gen' + gen].overrideStats[template.id];
if (overrideStats && 'spe' in overrideStats) baseSpe = overrideStats['spe'];
}
var nature = (tier.indexOf('Random Battle') >= 0 || (tier.indexOf('Random') >= 0 && tier.indexOf('Battle') >= 0 && gen >= 6) || gen < 3) ? 1 : 0.9;
return Math.floor(Math.floor(2 * baseSpe * level / 100 + 5) * nature);
};
BattleTooltips.prototype.getTemplateMaxSpeed = function (template, level) {
var baseSpe = template.baseStats['spe'];
var tier = this.battle.tier;
var gen = this.battle.gen;
if (gen < 7) {
var overrideStats = BattleTeambuilderTable['gen' + gen].overrideStats[template.id];
if (overrideStats && 'spe' in overrideStats) baseSpe = overrideStats['spe'];
}
var iv = (gen < 3) ? 30 : 31;
var isRandomBattle = tier.indexOf('Random Battle') >= 0 || (tier.indexOf('Random') >= 0 && tier.indexOf('Battle') >= 0 && gen >= 6);
var value = iv + ((isRandomBattle && gen >= 3) ? 21 : 63);
var nature = (isRandomBattle || gen < 3) ? 1 : 1.1;
return Math.floor(Math.floor(Math.floor(2 * baseSpe + value) * level / 100 + 5) * nature);
};
// Gets the proper current type for moves with a variable type.
BattleTooltips.prototype.getMoveType = function (move, pokemon) {
var pokemonData = this.room.myPokemon[pokemon.slot] || pokemon;
var ability = Tools.getAbility(pokemonData.ability || pokemon.ability || pokemonData.baseAbility).name;
var moveType = move.type;
var pokemonTypes = this.getPokemonTypes(pokemon);
// Normalize is the first move type changing effect.
if (ability === 'Normalize') {
moveType = 'Normal';
}
if ((move.id === 'bite' || move.id === 'gust' || move.id === 'karatechop' || move.id === 'sandattack') && this.battle.gen <= 1) {
moveType = 'Normal';
}
if ((move.id === 'charm' || move.id === 'moonlight' || move.id === 'sweetkiss') && this.battle.gen <= 5) {
moveType = 'Normal';
}
if (move.id === 'revelationdance') {
moveType = pokemonTypes[0];
}
// Moves that require an item to change their type.
if (!this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
if (move.id === 'multiattack') {
var item = Tools.getItem(pokemonData.item);
if (item.onMemory) moveType = item.onMemory;
}
if (move.id === 'judgment') {
var item = Tools.getItem(pokemonData.item);
if (item.onPlate && !item.zMove) moveType = item.onPlate;
}
if (move.id === 'technoblast') {
var item = Tools.getItem(pokemonData.item);
if (item.onDrive) moveType = item.onDrive;
}
if (move.id === 'naturalgift') {
var item = Tools.getItem(pokemonData.item);
if (item.naturalGift) moveType = item.naturalGift.type;
}
}
// Weather and pseudo-weather type changes.
if (move.id === 'weatherball' && this.battle.weather) {
var noWeatherAbility = false;
// Check if your side has an anti weather ability to skip this.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.mySide.active.length; i++) {
if (this.battle.mySide.active[i] && this.battle.mySide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
}
}
}
// If you don't, check if the opponent has it afterwards.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.yourSide.active.length; i++) {
if (this.battle.yourSide.active[i] && this.battle.yourSide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
}
}
}
// If the weather is indeed active, check it to see what move type weatherball gets.
if (!noWeatherAbility) {
if (this.battle.weather === 'sunnyday' || this.battle.weather === 'desolateland') moveType = 'Fire';
if (this.battle.weather === 'raindance' || this.battle.weather === 'primordialsea') moveType = 'Water';
if (this.battle.weather === 'sandstorm') moveType = 'Rock';
if (this.battle.weather === 'hail') moveType = 'Ice';
}
}
// Other abilities that change the move type.
if ('sound' in move.flags && ability === 'Liquid Voice') moveType = 'Water';
if (moveType === 'Normal' && move.category && move.category !== 'Status' && !(move.id in {judgment: 1, multiattack: 1, naturalgift: 1, revelationdance: 1, struggle: 1, technoblast: 1, weatherball: 1})) {
if (ability === 'Aerilate') moveType = 'Flying';
if (ability === 'Galvanize') moveType = 'Electric';
if (ability === 'Pixilate') moveType = 'Fairy';
if (ability === 'Refrigerate') moveType = 'Ice';
}
return moveType;
};
BattleTooltips.prototype.makePercentageChangeText = function (boost, source) {
return ' (×' + boost + ' from ' + source + ')';
};
// Gets the current accuracy for a move.
BattleTooltips.prototype.getMoveAccuracy = function (move, pokemon) {
var pokemonData = this.room.myPokemon[pokemon.slot];
var ability = Tools.getAbility(pokemonData.ability || pokemon.ability || pokemonData.baseAbility).name;
var accuracy = move.accuracy;
if (this.battle.gen < 7) {
var table = BattleTeambuilderTable['gen' + this.battle.gen];
if (move.id in table.overrideAcc) accuracy = table.overrideAcc[move.id];
}
var accuracyComment = '%';
if (move.id === 'toxic' && this.battle.gen >= 6 && this.pokemonHasType(pokemon, 'Poison')) return '— (Boosted by Poison type)';
if (move.id === 'blizzard' && this.battle.weather === 'hail') return '— (Boosted by Hail)';
if (move.id === 'hurricane' || move.id === 'thunder') {
if (this.battle.weather === 'raindance' || this.battle.weather === 'primordialsea') return '— (Boosted by Rain)';
if (this.battle.weather === 'sunnyday' || this.battle.weather === 'desolateland') {
accuracy = 50;
accuracyComment += ' (Reduced by Sun)';
}
}
if (!accuracy || accuracy === true) return '—';
if (ability === 'No Guard') return '— (Boosted by No Guard)';
if (move.ohko) {
if (this.battle.gen === 1) return accuracy + '% (Will fail if target\'s speed is higher)';
if (move.id === 'sheercold' && this.battle.gen >= 7) {
if (!this.pokemonHasType(pokemon, 'Ice')) accuracy = 20;
}
return accuracy + '% (Will fail if target\'s level is higher, increases 1% per each level above target)';
}
if (pokemon.boosts && pokemon.boosts.accuracy) {
if (pokemon.boosts.accuracy > 0) {
accuracy *= (pokemon.boosts.accuracy + 3) / 3;
} else {
accuracy *= 3 / (3 - pokemon.boosts.accuracy);
}
}
if (ability === 'Hustle' && move.category === 'Physical') {
accuracy *= 0.8;
accuracyComment += this.makePercentageChangeText(0.8, 'Hustle');
}
if (ability === 'Compound Eyes') {
accuracy *= 1.3;
accuracyComment += this.makePercentageChangeText(1.3, 'Compound Eyes');
}
for (var i = 0; i < pokemon.side.active.length; i++) {
if (!pokemon.side.active[i] || pokemon.side.active[i].fainted) continue;
ability = Tools.getAbility(pokemon.side.pokemon[i].ability).name;
if (ability === 'Victory Star') {
accuracy *= 1.1;
accuracyComment += this.makePercentageChangeText(1.1, 'Victory Star');
}
}
if (pokemonData.item === 'widelens' && !this.battle.hasPseudoWeather('Magic Room') && !(pokemon.volatiles && pokemon.volatiles['embargo'])) {
accuracy *= 1.1;
accuracyComment += this.makePercentageChangeText(1.1, 'Wide Lens');
}
if (this.battle.hasPseudoWeather('Gravity')) {
accuracy *= 5 / 3;
accuracyComment += this.makePercentageChangeText(1.66, 'Gravity');
}
return Math.round(accuracy) + accuracyComment;
};
// Gets the proper current base power for moves which have a variable base power.
// Takes into account the target for some moves.
// If it is unsure of the actual base power, it gives an estimate.
BattleTooltips.prototype.getMoveBasePower = function (move, pokemon, target) {
if (!target) target = this.room.myPokemon[0]; // fallback
var pokemonData = this.room.myPokemon[pokemon.slot];
if (!pokemonData) return '' + move.basePower;
var ability = Tools.getAbility(pokemonData.ability || pokemon.ability || pokemonData.baseAbility).name;
var item = {};
var basePower = move.basePower;
var moveType = this.getMoveType(move, pokemon);
if (this.battle.gen < 7) {
var table = BattleTeambuilderTable['gen' + this.battle.gen];
if (move.id in table.overrideBP) basePower = table.overrideBP[move.id];
}
var basePowerComment = '';
var noWeatherAbility = false;
// Check if your side has an anti weather ability to skip this.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.mySide.active.length; i++) {
if (this.battle.mySide.active[i] && this.battle.mySide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
}
}