forked from smogon/pokemon-showdown-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattle-tooltips.ts
3291 lines (3082 loc) · 114 KB
/
battle-tooltips.ts
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
/**
* Pokemon Showdown Tooltips
*
* A file for generating tooltips for battles. This should be IE7+ and
* use the DOM directly.
*
* @author Guangcong Luo <guangcongluo@gmail.com>
* @license MIT
*/
class ModifiableValue {
value = 0;
maxValue = 0;
comment: string[];
battle: Battle;
pokemon: Pokemon;
serverPokemon: ServerPokemon;
itemName: string;
abilityName: string;
weatherName: string;
isAccuracy = false;
constructor(battle: Battle, pokemon: Pokemon, serverPokemon: ServerPokemon) {
this.comment = [];
this.battle = battle;
this.pokemon = pokemon;
this.serverPokemon = serverPokemon;
this.itemName = this.battle.dex.items.get(serverPokemon.item).name;
const ability = serverPokemon.ability || pokemon?.ability || serverPokemon.baseAbility;
this.abilityName = this.battle.dex.abilities.get(ability).name;
this.weatherName = battle.weather === 'snow' ? 'Snow' : this.battle.dex.moves.get(battle.weather).exists ?
this.battle.dex.moves.get(battle.weather).name : this.battle.dex.abilities.get(battle.weather).name;
}
reset(value = 0, isAccuracy?: boolean) {
this.value = value;
this.maxValue = 0;
this.isAccuracy = !!isAccuracy;
this.comment = [];
}
tryItem(itemName: string) {
if (itemName !== this.itemName) return false;
if (this.battle.hasPseudoWeather('Magic Room')) {
this.comment.push(` (${itemName} suppressed by Magic Room)`);
return false;
}
if (this.pokemon?.volatiles['embargo']) {
this.comment.push(` (${itemName} suppressed by Embargo)`);
return false;
}
const ignoreKlutz = [
"Macho Brace", "Power Anklet", "Power Band", "Power Belt", "Power Bracer", "Power Lens", "Power Weight",
];
if (this.tryAbility('Klutz') && !ignoreKlutz.includes(itemName)) {
this.comment.push(` (${itemName} suppressed by Klutz)`);
return false;
}
return true;
}
tryAbility(abilityName: string) {
if (abilityName !== this.abilityName) return false;
if (this.pokemon?.volatiles['gastroacid']) {
this.comment.push(` (${abilityName} suppressed by Gastro Acid)`);
return false;
}
// Check for Neutralizing Gas
if (!this.pokemon?.effectiveAbility(this.serverPokemon)) return false;
return true;
}
tryWeather(weatherName?: string) {
if (!this.weatherName) return false;
if (!weatherName) weatherName = this.weatherName;
else if (weatherName !== this.weatherName) return false;
for (const side of this.battle.sides) {
for (const active of side.active) {
if (active && ['Air Lock', 'Cloud Nine'].includes(active.ability)) {
this.comment.push(` (${weatherName} suppressed by ${active.ability})`);
return false;
}
}
}
return true;
}
itemModify(factor: number, itemName?: string) {
if (!itemName) itemName = this.itemName;
if (!itemName) return false;
if (!this.tryItem(itemName)) return false;
return this.modify(factor, itemName);
}
abilityModify(factor: number, abilityName: string) {
if (!this.tryAbility(abilityName)) return false;
return this.modify(factor, abilityName);
}
weatherModify(factor: number, weatherName?: string, name?: string) {
if (!weatherName) weatherName = this.weatherName;
if (!weatherName) return false;
if (!this.tryWeather(weatherName)) return false;
return this.modify(factor, name || weatherName);
}
modify(factor: number, name?: string) {
if (factor === 0) {
if (name) this.comment.push(` (${name})`);
this.value = 0;
this.maxValue = 0;
return true;
}
if (name) this.comment.push(` (${this.round(factor)}× from ${name})`);
this.value *= factor;
if (!(name === 'Technician' && this.maxValue > 60)) this.maxValue *= factor;
if (this.battle.tier.includes('Super Staff Bros') &&
!(name === 'Confirmed Town' && this.maxValue > 60)) this.maxValue *= factor;
return true;
}
set(value: number, reason?: string) {
if (reason) this.comment.push(` (${reason})`);
this.value = value;
this.maxValue = 0;
return true;
}
setRange(value: number, maxValue: number, reason?: string) {
if (reason) this.comment.push(` (${reason})`);
this.value = value;
this.maxValue = maxValue;
return true;
}
round(value: number) {
return value ? Number(value.toFixed(2)) : 0;
}
toString() {
let valueString;
if (this.isAccuracy) {
valueString = this.value ? `${this.round(this.value)}%` : `can't miss`;
} else {
valueString = this.value ? `${this.round(this.value)}` : ``;
}
if (this.maxValue) {
valueString += ` to ${this.round(this.maxValue)}` + (this.isAccuracy ? '%' : '');
}
return valueString + this.comment.join('');
}
}
class BattleTooltips {
battle: Battle;
constructor(battle: Battle) {
this.battle = battle;
}
// tooltips
// Touch delay, pressing finger more than that time will cause the tooltip to open.
// Shorter time will cause the button to click
static LONG_TAP_DELAY = 350; // ms
static longTapTimeout = 0;
static elem: HTMLDivElement | null = null;
static parentElem: HTMLElement | null = null;
static isLocked = false;
static isPressed = false;
static hideTooltip() {
if (!BattleTooltips.elem) return;
BattleTooltips.cancelLongTap();
BattleTooltips.elem.parentNode!.removeChild(BattleTooltips.elem);
BattleTooltips.elem = null;
BattleTooltips.parentElem = null;
BattleTooltips.isLocked = false;
$('#tooltipwrapper').removeClass('tooltip-locked');
}
static cancelLongTap() {
if (BattleTooltips.longTapTimeout) {
clearTimeout(BattleTooltips.longTapTimeout);
BattleTooltips.longTapTimeout = 0;
}
}
lockTooltip() {
if (BattleTooltips.elem && !BattleTooltips.isLocked) {
BattleTooltips.isLocked = true;
if (BattleTooltips.isPressed) {
$(BattleTooltips.parentElem!).removeClass('pressed');
BattleTooltips.isPressed = false;
}
$('#tooltipwrapper').addClass('tooltip-locked');
}
}
handleTouchEnd(e: TouchEvent) {
BattleTooltips.cancelLongTap();
if (!BattleTooltips.isLocked) BattleTooltips.hideTooltip();
}
listen(elem: HTMLElement | JQuery<HTMLElement>) {
const $elem = $(elem);
$elem.on('mouseover', '.has-tooltip', this.showTooltipEvent);
$elem.on('click', '.has-tooltip', this.clickTooltipEvent);
$elem.on('focus', '.has-tooltip', this.showTooltipEvent);
$elem.on('mouseout', '.has-tooltip', BattleTooltips.unshowTooltip);
$elem.on('mousedown', '.has-tooltip', this.holdLockTooltipEvent);
$elem.on('blur', '.has-tooltip', BattleTooltips.unshowTooltip);
$elem.on('mouseup', '.has-tooltip', BattleTooltips.unshowTooltip);
$elem.on('touchstart', '.has-tooltip', e => {
e.preventDefault();
this.holdLockTooltipEvent(e);
if (!BattleTooltips.parentElem) {
// should never happen, but in case there's a bug in the tooltip handler
BattleTooltips.parentElem = e.currentTarget;
}
$(BattleTooltips.parentElem!).addClass('pressed');
BattleTooltips.isPressed = true;
});
$elem.on('touchend', '.has-tooltip', e => {
e.preventDefault();
if (e.currentTarget === BattleTooltips.parentElem && BattleTooltips.isPressed) {
BattleTooltips.parentElem!.click();
}
BattleTooltips.unshowTooltip();
});
$elem.on('touchleave', '.has-tooltip', BattleTooltips.unshowTooltip);
$elem.on('touchcancel', '.has-tooltip', BattleTooltips.unshowTooltip);
}
clickTooltipEvent = (e: Event) => {
if (BattleTooltips.isLocked) {
e.preventDefault();
e.stopImmediatePropagation();
}
};
/**
* An event that will lock a tooltip if held down
*
* (Namely, a long-tap or long-click)
*/
holdLockTooltipEvent = (e: JQuery.TriggeredEvent) => {
if (BattleTooltips.isLocked) BattleTooltips.hideTooltip();
const target = e.currentTarget as HTMLElement;
this.showTooltip(target);
let factor = (e.type === 'mousedown' && target.tagName === 'BUTTON' ? 2 : 1);
BattleTooltips.longTapTimeout = setTimeout(() => {
BattleTooltips.longTapTimeout = 0;
this.lockTooltip();
}, BattleTooltips.LONG_TAP_DELAY * factor);
};
showTooltipEvent = (e: Event) => {
if (BattleTooltips.isLocked) return;
this.showTooltip(e.currentTarget as HTMLElement);
};
/**
* Only hides tooltips if they're not locked
*/
static unshowTooltip() {
if (BattleTooltips.isLocked) return;
if (BattleTooltips.isPressed) {
$(BattleTooltips.parentElem!).removeClass('pressed');
BattleTooltips.isPressed = false;
}
BattleTooltips.hideTooltip();
}
showTooltip(elem: HTMLElement) {
const args = (elem.dataset.tooltip || '').split('|');
const [type] = args;
/**
* If false, we instead attach the tooltip above the parent element.
* This is important for the move/switch menus so the tooltip doesn't
* cover up buttons above the hovered button.
*/
let ownHeight = !!elem.dataset.ownheight;
let buf: string;
switch (type) {
case 'move':
case 'zmove':
case 'maxmove': { // move|MOVE|ACTIVEPOKEMON|[GMAXMOVE]
let move = this.battle.dex.moves.get(args[1]);
let teamIndex = parseInt(args[2], 10);
let pokemon = this.battle.nearSide.active[
teamIndex + this.battle.pokemonControlled * Math.floor(this.battle.mySide.n / 2)
];
let gmaxMove = args[3] ? this.battle.dex.moves.get(args[3]) : undefined;
if (!pokemon) return false;
let serverPokemon = this.battle.myPokemon![teamIndex];
buf = this.showMoveTooltip(move, type, pokemon, serverPokemon, gmaxMove);
break;
}
case 'pokemon': { // pokemon|SIDE|POKEMON
// mouse over sidebar pokemon
// pokemon definitely exists, serverPokemon always ignored
let sideIndex = parseInt(args[1], 10);
let side = this.battle.sides[sideIndex];
let pokemon = side.pokemon[parseInt(args[2], 10)];
if (args[3] === 'illusion') {
buf = '';
const species = pokemon.getBaseSpecies().baseSpecies;
let index = 1;
for (const otherPokemon of side.pokemon) {
if (otherPokemon.getBaseSpecies().baseSpecies === species) {
buf += this.showPokemonTooltip(otherPokemon, null, false, index);
index++;
}
}
} else {
buf = this.showPokemonTooltip(pokemon);
}
break;
}
case 'activepokemon': { // activepokemon|SIDE|ACTIVE
// mouse over active pokemon
// pokemon definitely exists, serverPokemon maybe
let sideIndex = parseInt(args[1], 10);
let side = this.battle.sides[+this.battle.viewpointSwitched ^ sideIndex];
let activeIndex = parseInt(args[2], 10);
let pokemonIndex = activeIndex;
if (activeIndex >= 1 && this.battle.sides.length > 2) {
pokemonIndex -= 1;
side = this.battle.sides[side.n + 2];
}
let pokemon = side.active[activeIndex];
let serverPokemon = null;
if (side === this.battle.mySide && this.battle.myPokemon) {
serverPokemon = this.battle.myPokemon[pokemonIndex];
}
if (side === this.battle.mySide.ally && this.battle.myAllyPokemon) {
serverPokemon = this.battle.myAllyPokemon[pokemonIndex];
}
if (!pokemon) return false;
buf = this.showPokemonTooltip(pokemon, serverPokemon, true);
break;
}
case 'switchpokemon': { // switchpokemon|POKEMON
// mouse over switchable pokemon
// serverPokemon definitely exists, sidePokemon maybe
// let side = this.battle.mySide;
let activeIndex = parseInt(args[1], 10);
let pokemon = null;
/* if (activeIndex < side.active.length && activeIndex < this.battle.pokemonControlled) {
pokemon = side.active[activeIndex];
if (pokemon && pokemon.side === side.ally) pokemon = null;
} */
let serverPokemon = this.battle.myPokemon![activeIndex];
buf = this.showPokemonTooltip(pokemon, serverPokemon);
break;
}
case 'allypokemon': { // allypokemon|POKEMON
// mouse over ally's pokemon in multi battles
// serverPokemon definitely exists, sidePokemon maybe
// let side = this.battle.mySide.ally;
let activeIndex = parseInt(args[1], 10);
let pokemon = null;
/*if (activeIndex < side.pokemon.length) {
pokemon = side.pokemon[activeIndex] || side.ally ? side.ally.pokemon[activeIndex] : null;
}*/
let serverPokemon = this.battle.myAllyPokemon ? this.battle.myAllyPokemon[activeIndex] : null;
buf = this.showPokemonTooltip(pokemon, serverPokemon);
break;
}
case 'field': {
buf = this.showFieldTooltip();
break;
}
default:
// "throws" an error without crashing
Promise.resolve(new Error(`unrecognized type`));
buf = `<p class="message-error" style="white-space: pre-wrap">${new Error(`unrecognized type`).stack}</p>`;
}
this.placeTooltip(buf, elem, ownHeight, type);
return true;
}
placeTooltip(innerHTML: string, hoveredElem?: HTMLElement, notRelativeToParent?: boolean, type?: string) {
let $elem;
if (hoveredElem) {
$elem = $(hoveredElem);
} else {
$elem = (this.battle.scene as BattleScene).$turn;
notRelativeToParent = true;
}
let hoveredX1 = $elem.offset()!.left;
if (!notRelativeToParent) {
$elem = $elem.parent();
}
let hoveredY1 = $elem.offset()!.top;
let hoveredY2 = hoveredY1 + $elem.outerHeight()!;
// (x, y) are the left and top offsets of #tooltipwrapper, which mark the
// BOTTOM LEFT CORNER of the tooltip
let x = Math.max(hoveredX1 - 2, 0);
let y = Math.max(hoveredY1 - 5, 0);
let $wrapper = $('#tooltipwrapper');
if (!$wrapper.length) {
$wrapper = $(`<div id="tooltipwrapper" role="tooltip"></div>`);
$(document.body).append($wrapper);
$wrapper.on('click', e => {
try {
const selection = window.getSelection()!;
if (selection.type === 'Range') return;
} catch (err) {}
BattleTooltips.hideTooltip();
});
} else {
$wrapper.removeClass('tooltip-locked');
}
$wrapper.css({
left: x,
top: y,
});
innerHTML = `<div class="tooltipinner"><div class="tooltip tooltip-${type}">${innerHTML}</div></div>`;
$wrapper.html(innerHTML).appendTo(document.body);
BattleTooltips.elem = $wrapper.find('.tooltip')[0] as HTMLDivElement;
BattleTooltips.isLocked = false;
let height = $(BattleTooltips.elem).outerHeight()!;
if (y - height < 1) {
// tooltip is too tall to fit above the element:
// try to fit it below it instead
y = hoveredY2 + height + 5;
if (y > document.documentElement.clientHeight) {
// tooltip is also too tall to fit below the element:
// just place it at the top of the screen
y = height + 1;
}
$wrapper.css('top', y);
} else if (y < 75) {
// tooltip is pretty high up, put it below the element if it fits
y = hoveredY2 + height + 5;
if (y < document.documentElement.clientHeight) {
// it fits
$wrapper.css('top', y);
}
}
let width = $(BattleTooltips.elem).outerWidth()!;
if (x > document.documentElement.clientWidth - width - 2) {
x = document.documentElement.clientWidth - width - 2;
$wrapper.css('left', x);
}
BattleTooltips.parentElem = hoveredElem || null;
return true;
}
hideTooltip() {
BattleTooltips.hideTooltip();
}
static zMoveEffects: {[zEffect: string]: string} = {
'clearnegativeboost': "Restores negative stat stages to 0",
'crit2': "Crit ratio +2",
'heal': "Restores HP 100%",
'curse': "Restores HP 100% if user is Ghost type, otherwise Attack +1",
'redirect': "Redirects opposing attacks to user",
'healreplacement': "Restores replacement's HP 100%",
};
getStatusZMoveEffect(move: Move) {
if (move.zMove!.effect! in BattleTooltips.zMoveEffects) {
return BattleTooltips.zMoveEffects[move.zMove!.effect!];
}
let boostText = '';
if (move.zMove!.boost) {
let boosts = Object.keys(move.zMove!.boost) as StatName[];
boostText = boosts.map(stat =>
BattleTextParser.stat(stat) + ' +' + move.zMove!.boost![stat]
).join(', ');
}
return boostText;
}
static zMoveTable: {[type in TypeName]: string} = {
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",
Stellar: "",
"???": "",
};
static maxMoveTable: {[type in TypeName]: string} = {
Poison: "Max Ooze",
Fighting: "Max Knuckle",
Dark: "Max Darkness",
Grass: "Max Overgrowth",
Normal: "Max Strike",
Rock: "Max Rockfall",
Steel: "Max Steelspike",
Dragon: "Max Wyrmwind",
Electric: "Max Lightning",
Water: "Max Geyser",
Fire: "Max Flare",
Ghost: "Max Phantasm",
Bug: "Max Flutterby",
Psychic: "Max Mindstorm",
Ice: "Max Hailstorm",
Flying: "Max Airstream",
Ground: "Max Quake",
Fairy: "Max Starfall",
Stellar: "",
"???": "",
};
getMaxMoveFromType(type: TypeName, gmaxMove?: string | Move) {
if (gmaxMove) {
if (typeof gmaxMove === 'string') gmaxMove = this.battle.dex.moves.get(gmaxMove);
if (type === gmaxMove.type) return gmaxMove;
}
return this.battle.dex.moves.get(BattleTooltips.maxMoveTable[type]);
}
showMoveTooltip(move: Move, isZOrMax: string, pokemon: Pokemon, serverPokemon: ServerPokemon, gmaxMove?: Move) {
let text = '';
let zEffect = '';
let foeActive = pokemon.side.foe.active;
if (this.battle.gameType === 'freeforall') {
foeActive = [...foeActive, ...pokemon.side.active].filter(active => active !== pokemon);
}
// TODO: move this somewhere it makes more sense
if (pokemon.ability === '(suppressed)') serverPokemon.ability = '(suppressed)';
let ability = toID(serverPokemon.ability || pokemon.ability || serverPokemon.baseAbility);
let item = this.battle.dex.items.get(serverPokemon.item);
let value = new ModifiableValue(this.battle, pokemon, serverPokemon);
let [moveType, category] = this.getMoveType(move, value, gmaxMove || isZOrMax === 'maxmove');
let categoryDiff = move.category !== category;
if (isZOrMax === 'zmove') {
if (item.zMoveFrom === move.name) {
move = this.battle.dex.moves.get(item.zMove as string);
} else if (move.category === 'Status') {
move = new Move(move.id, "", {
...move,
name: 'Z-' + move.name,
});
zEffect = this.getStatusZMoveEffect(move);
} else {
let moveName = BattleTooltips.zMoveTable[item.zMoveType as TypeName];
let zMove = this.battle.dex.moves.get(moveName);
let movePower = move.zMove!.basePower;
// the different Hidden Power types don't have a Z power set, fall back on base move
if (!movePower && move.id.startsWith('hiddenpower')) {
movePower = this.battle.dex.moves.get('hiddenpower').zMove!.basePower;
}
if (move.id === 'weatherball') {
switch (this.battle.weather) {
case 'sunnyday':
case 'desolateland':
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Fire']);
break;
case 'raindance':
case 'primordialsea':
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Water']);
break;
case 'sandstorm':
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Rock']);
break;
case 'hail':
case 'snow':
zMove = this.battle.dex.moves.get(BattleTooltips.zMoveTable['Ice']);
break;
}
}
move = new Move(zMove.id, zMove.name, {
...zMove,
category: move.category,
basePower: movePower,
});
categoryDiff = false;
}
} else if (isZOrMax === 'maxmove') {
if (move.category === 'Status') {
move = this.battle.dex.moves.get('Max Guard');
} else {
let maxMove = this.getMaxMoveFromType(moveType, gmaxMove);
const basePower = ['gmaxdrumsolo', 'gmaxfireball', 'gmaxhydrosnipe'].includes(maxMove.id) ?
maxMove.basePower : move.maxMove.basePower;
move = new Move(maxMove.id, maxMove.name, {
...maxMove,
category: move.category,
basePower,
});
categoryDiff = false;
}
}
if (categoryDiff) {
move = new Move(move.id, move.name, {
...move,
category,
});
}
text += '<h2>' + move.name + '<br />';
text += Dex.getTypeIcon(moveType);
text += ` ${Dex.getCategoryIcon(category)}</h2>`;
// Check if there are more than one active Pokémon to check for multiple possible BPs.
let showingMultipleBasePowers = false;
if (category !== 'Status' && foeActive.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.
let prevBasePower: string | null = null;
let basePower: string = '';
let difference = false;
let basePowers = [];
for (const active of foeActive) {
if (!active) continue;
value = this.getMoveBasePower(move, moveType, value, active);
basePower = '' + value;
if (prevBasePower === null) prevBasePower = basePower;
if (prevBasePower !== basePower) difference = true;
basePowers.push('Base power vs ' + active.name + ': ' + basePower);
}
if (difference) {
text += '<p>' + basePowers.join('<br />') + '</p>';
showingMultipleBasePowers = true;
}
// Falls through to not to repeat code on showing the base power.
}
if (!showingMultipleBasePowers && category !== 'Status') {
let activeTarget = foeActive[0] || foeActive[1] || foeActive[2];
value = this.getMoveBasePower(move, moveType, value, activeTarget);
text += '<p>Base power: ' + value + '</p>';
}
let accuracy = this.getMoveAccuracy(move, value);
// Deal with Nature Power special case, indicating which move it calls.
if (move.id === 'naturepower') {
let 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';
}
let calledMove = this.battle.dex.moves.get(calls);
text += 'Calls ' + Dex.getTypeIcon(this.getMoveType(calledMove, value)[0]) + ' ' + calledMove.name;
}
text += '<p>Accuracy: ' + accuracy + '</p>';
if (zEffect) text += '<p>Z-Effect: ' + zEffect + '</p>';
if (this.battle.hardcoreMode) {
text += '<p class="tooltip-section">' + move.shortDesc + '</p>';
} else {
text += '<p class="tooltip-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>';
} else {
if (move.id === 'grassyglide' && this.battle.hasPseudoWeather('Grassy Terrain')) {
text += 'Usually moves first <em>(priority +1)</em>.</p><p>';
}
}
text += '' + (move.desc || move.shortDesc || '') + '</p>';
if (this.battle.gameType === 'doubles' || this.battle.gameType === 'multi') {
if (move.target === 'allAdjacent') {
text += '<p>◎ Hits both foes and ally.</p>';
} else if (move.target === 'allAdjacentFoes') {
text += '<p>◎ Hits both foes.</p>';
}
} else if (this.battle.gameType === 'triples') {
if (move.target === 'allAdjacent') {
text += '<p>◎ Hits adjacent foes and allies.</p>';
} else if (move.target === 'allAdjacentFoes') {
text += '<p>◎ Hits adjacent foes.</p>';
} else if (move.target === 'any') {
text += '<p>◎ Can target distant Pokémon in Triples.</p>';
}
} else if (this.battle.gameType === 'freeforall') {
if (move.target === 'allAdjacent' || move.target === 'allAdjacentFoes') {
text += '<p>◎ Hits all foes.</p>';
} else if (move.target === 'adjacentAlly') {
text += '<p>◎ Can target any foe in Free-For-All.</p>';
}
}
if (move.flags.defrost) {
text += `<p class="movetag">The user thaws out if it is frozen.</p>`;
}
if (!move.flags.protect && !['self', 'allySide'].includes(move.target)) {
text += `<p class="movetag">Not blocked by Protect <small>(and Detect, King's Shield, Spiky Shield)</small></p>`;
}
if (move.flags.bypasssub) {
text += `<p class="movetag">Bypasses Substitute <small>(but does not break it)</small></p>`;
}
if (!move.flags.reflectable && !['self', 'allySide'].includes(move.target) && move.category === 'Status') {
text += `<p class="movetag">✓ Not bounceable <small>(can't be bounced by Magic Coat/Bounce)</small></p>`;
}
if (move.flags.contact) {
text += `<p class="movetag">✓ Contact <small>(triggers Iron Barbs, Spiky Shield, etc)</small></p>`;
}
if (move.flags.sound) {
text += `<p class="movetag">✓ Sound <small>(doesn't affect Soundproof pokemon)</small></p>`;
}
if (move.flags.powder && this.battle.gen > 5) {
text += `<p class="movetag">✓ Powder <small>(doesn't affect Grass, Overcoat, Safety Goggles)</small></p>`;
}
if (move.flags.punch && ability === 'ironfist') {
text += `<p class="movetag">✓ Fist <small>(boosted by Iron Fist)</small></p>`;
}
if (move.flags.pulse && ability === 'megalauncher') {
text += `<p class="movetag">✓ Pulse <small>(boosted by Mega Launcher)</small></p>`;
}
if (move.flags.bite && ability === 'strongjaw') {
text += `<p class="movetag">✓ Bite <small>(boosted by Strong Jaw)</small></p>`;
}
if ((move.recoil || move.hasCrashDamage) && ability === 'reckless') {
text += `<p class="movetag">✓ Recoil <small>(boosted by Reckless)</small></p>`;
}
if (move.flags.bullet) {
text += `<p class="movetag">✓ Bullet-like <small>(doesn't affect Bulletproof pokemon)</small></p>`;
}
if (move.flags.slicing) {
text += `<p class="movetag">✓ Slicing <small>(boosted by Sharpness)</small></p>`;
}
if (move.flags.wind) {
text += `<p class="movetag">✓ Wind <small>(activates Wind Power and Wind Rider)</small></p>`;
}
}
return text;
}
/**
* Needs either a Pokemon or a ServerPokemon, but note that neither
* are guaranteed: If you hover over a possible switch-in that's
* never been switched in before, you'll only have a ServerPokemon,
* and if you hover over an opponent's pokemon, you'll only have a
* Pokemon.
*
* isActive is true if hovering over a pokemon in the battlefield,
* and false if hovering over a pokemon in the Switch menu.
*
* @param clientPokemon
* @param serverPokemon
* @param isActive
*/
showPokemonTooltip(
clientPokemon: Pokemon | null, serverPokemon?: ServerPokemon | null, isActive?: boolean, illusionIndex?: number
) {
const pokemon = clientPokemon || serverPokemon!;
let text = '';
let genderBuf = '';
const gender = pokemon.gender;
if (gender === 'M' || gender === 'F') {
genderBuf = ` <img src="${Dex.fxPrefix}gender-${gender.toLowerCase()}.png" alt="${gender}" width="7" height="10" class="pixelated" /> `;
}
let name = BattleLog.escapeHTML(pokemon.name);
if (pokemon.speciesForme !== pokemon.name) {
name += ' <small>(' + BattleLog.escapeHTML(pokemon.speciesForme) + ')</small>';
}
let levelBuf = (pokemon.level !== 100 ? ` <small>L${pokemon.level}</small>` : ``);
if (!illusionIndex || illusionIndex === 1) {
text += `<h2>${name}${genderBuf}${illusionIndex ? '' : levelBuf}<br />`;
if (clientPokemon?.volatiles.formechange) {
if (clientPokemon.volatiles.transform) {
text += `<small>(Transformed into ${clientPokemon.volatiles.formechange[1]})</small><br />`;
} else {
text += `<small>(Changed forme: ${clientPokemon.volatiles.formechange[1]})</small><br />`;
}
}
let types = serverPokemon?.terastallized ? [serverPokemon.teraType] : this.getPokemonTypes(pokemon);
let knownPokemon = serverPokemon || clientPokemon!;
if (pokemon.terastallized) {
text += `<small>(Terastallized)</small><br />`;
} else if (clientPokemon?.volatiles.typechange || clientPokemon?.volatiles.typeadd) {
text += `<small>(Type changed)</small><br />`;
}
text += `<span class="textaligned-typeicons">${types.map(type => Dex.getTypeIcon(type)).join(' ')}</span>`;
if (pokemon.terastallized) {
text += ` <small>(base: <span class="textaligned-typeicons">${this.getPokemonTypes(pokemon, true).map(type => Dex.getTypeIcon(type)).join(' ')}</span>)</small>`;
} else if (knownPokemon.teraType && !this.battle.rules['Terastal Clause']) {
text += ` <small>(Tera Type: <span class="textaligned-typeicons">${Dex.getTypeIcon(knownPokemon.teraType)}</span>)</small>`;
}
text += `</h2>`;
}
if (illusionIndex) {
text += `<p class="tooltip-section"><strong>Possible Illusion #${illusionIndex}</strong>${levelBuf}</p>`;
}
if (pokemon.fainted) {
text += '<p><small>HP:</small> (fainted)</p>';
} else if (this.battle.hardcoreMode) {
if (serverPokemon) {
text += '<p><small>HP:</small> ' + serverPokemon.hp + '/' + serverPokemon.maxhp + (pokemon.status ? ' <span class="status ' + pokemon.status + '">' + pokemon.status.toUpperCase() + '</span>' : '') + '</p>';
}
} else {
let exacthp = '';
if (serverPokemon) {
exacthp = ' (' + serverPokemon.hp + '/' + serverPokemon.maxhp + ')';
} else if (pokemon.maxhp === 48) {
exacthp = ' <small>(' + pokemon.hp + '/' + pokemon.maxhp + ' pixels)</small>';
}
text += '<p><small>HP:</small> ' + Pokemon.getHPText(pokemon) + exacthp + (pokemon.status ? ' <span class="status ' + pokemon.status + '">' + pokemon.status.toUpperCase() + '</span>' : '');
if (clientPokemon) {
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(clientPokemon.statusData.toxicTurns + 1, 15)) + '%</small>';
} else {
text += ' Next damage: ' + Math.floor(100 / (clientPokemon.volatiles['dynamax'] ? 32 : 16) * Math.min(clientPokemon.statusData.toxicTurns + 1, 15)) + '%';
}
} else if (pokemon.status === 'slp') {
text += ' Turns asleep: ' + clientPokemon.statusData.sleepTurns;
}
}
text += '</p>';
}
const supportsAbilities = this.battle.gen > 2 && !this.battle.tier.includes("Let's Go");
let abilityText = '';
if (supportsAbilities) {
abilityText = this.getPokemonAbilityText(
clientPokemon, serverPokemon, isActive, !!illusionIndex && illusionIndex > 1
);
}
let itemText = '';
if (serverPokemon) {
let item = '';
let itemEffect = '';
if (clientPokemon?.prevItem) {
item = 'None';
let prevItem = this.battle.dex.items.get(clientPokemon.prevItem).name;
itemEffect += clientPokemon.prevItemEffect ? prevItem + ' was ' + clientPokemon.prevItemEffect : 'was ' + prevItem;
}
if (serverPokemon.item) item = this.battle.dex.items.get(serverPokemon.item).name;
if (itemEffect) itemEffect = ' (' + itemEffect + ')';
if (item) itemText = '<small>Item:</small> ' + item + itemEffect;
} else if (clientPokemon) {
let item = '';
let itemEffect = clientPokemon.itemEffect || '';
if (clientPokemon.prevItem) {
item = 'None';
if (itemEffect) itemEffect += '; ';
let prevItem = this.battle.dex.items.get(clientPokemon.prevItem).name;
itemEffect += clientPokemon.prevItemEffect ? prevItem + ' was ' + clientPokemon.prevItemEffect : 'was ' + prevItem;
}
if (pokemon.item) item = this.battle.dex.items.get(pokemon.item).name;
if (itemEffect) itemEffect = ' (' + itemEffect + ')';
if (item) itemText = '<small>Item:</small> ' + item + itemEffect;
}
if (abilityText || itemText) {
text += '<p>';
text += abilityText;
if (abilityText && itemText) {
// ability/item on one line for your own switch tooltips, two lines everywhere else
text += (!isActive && serverPokemon ? ' / ' : '</p><p>');
}
text += itemText;
text += '</p>';
}
text += this.renderStats(clientPokemon, serverPokemon, !isActive);
if (serverPokemon && !isActive) {
// move list
text += `<p class="tooltip-section">`;
const battlePokemon = clientPokemon || this.battle.findCorrespondingPokemon(pokemon);
for (const moveid of serverPokemon.moves) {
const move = this.battle.dex.moves.get(moveid);
let moveName = `• ${move.name}`;
if (battlePokemon?.moveTrack) {
for (const row of battlePokemon.moveTrack) {
if (moveName === row[0]) {
moveName = this.getPPUseText(row, true);
break;
}
}
}
text += `${moveName}<br />`;
}
text += '</p>';
} else if (!this.battle.hardcoreMode && clientPokemon?.moveTrack.length) {
// move list (guessed)
text += `<p class="tooltip-section">`;
for (const row of clientPokemon.moveTrack) {
text += `${this.getPPUseText(row)}<br />`;
}
if (clientPokemon.moveTrack.filter(([moveName]) => {
if (moveName.charAt(0) === '*') return false;
const move = this.battle.dex.moves.get(moveName);
return !move.isZ && !move.isMax && move.name !== 'Mimic';
}).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 in certain situations, more PP may have been lost than shown here.) `;
}
if (this.pokemonHasClones(clientPokemon)) {
text += `(Your opponent has two indistinguishable Pokémon, making it impossible for you to tell which one has which moves/ability/item.) `;
}
text += `</p>`;
}
return text;
}
showFieldTooltip() {
const scene = this.battle.scene as BattleScene;
let buf = `<table style="border: 0; border-collapse: collapse; vertical-align: top; padding: 0; width: 100%"><tr>`;
let atLeastOne = false;
for (const side of this.battle.sides) {
const sideConditions = scene.sideConditionsLeft(side, true);
if (sideConditions) atLeastOne = true;
buf += `<td><p class="tooltip-section"><strong>${BattleLog.escapeHTML(side.name)}</strong>${sideConditions || "<br />(no conditions)"}</p></td>`;
}
buf += `</tr><table>`;
if (!atLeastOne) buf = ``;
let weatherbuf = scene.weatherLeft() || `(no weather)`;
if (weatherbuf.startsWith('<br />')) {
weatherbuf = weatherbuf.slice(6);
}
buf = `<p>${weatherbuf}</p>` + buf;
return `<p>${buf}</p>`;
}
/**
* Does this Pokémon's trainer have two of these Pokémon that are
* indistinguishable? (Same nickname, species, forme, level, gender,
* and shininess.)
*/
pokemonHasClones(pokemon: Pokemon) {
const side = pokemon.side;
if (side.battle.speciesClause) return false;
for (const ally of side.pokemon) {
if (pokemon !== ally && pokemon.searchid === ally.searchid) {
return true;
}
}
return false;
}
calculateModifiedStats(clientPokemon: Pokemon | null, serverPokemon: ServerPokemon, statStagesOnly?: boolean) {
let stats = {...serverPokemon.stats};
let pokemon = clientPokemon || serverPokemon;
const isPowerTrick = clientPokemon?.volatiles['powertrick'];
for (const statName of Dex.statNamesExceptHP) {
let sourceStatName = statName;
if (isPowerTrick) {
if (statName === 'atk') sourceStatName = 'def';
if (statName === 'def') sourceStatName = 'atk';
}
stats[statName] = serverPokemon.stats[sourceStatName];
if (!clientPokemon) continue;