@pkmn/sim 0.5.12 → 0.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/build/config/formats.js +163 -149
  2. package/build/config/formats.js.map +1 -1
  3. package/build/data/abilities.js +2 -2
  4. package/build/data/abilities.js.map +1 -1
  5. package/build/data/aliases.js +2 -2
  6. package/build/data/aliases.js.map +1 -1
  7. package/build/data/conditions.js +4 -1
  8. package/build/data/conditions.js.map +1 -1
  9. package/build/data/formats-data.js +2 -2
  10. package/build/data/formats-data.js.map +1 -1
  11. package/build/data/items.js +4 -2
  12. package/build/data/items.js.map +1 -1
  13. package/build/data/learnsets.js +5 -4
  14. package/build/data/learnsets.js.map +1 -1
  15. package/build/data/mods/gen1/formats-data.js +38 -36
  16. package/build/data/mods/gen1/formats-data.js.map +1 -1
  17. package/build/data/mods/gen1/scripts.js +1 -1
  18. package/build/data/mods/gen1/scripts.js.map +1 -1
  19. package/build/data/mods/gen2/items.js +28 -0
  20. package/build/data/mods/gen2/items.js.map +1 -1
  21. package/build/data/mods/gen2/moves.js +2 -2
  22. package/build/data/mods/gen2/moves.js.map +1 -1
  23. package/build/data/mods/gen3/items.js +28 -0
  24. package/build/data/mods/gen3/items.js.map +1 -1
  25. package/build/data/mods/gen4/abilities.js +20 -0
  26. package/build/data/mods/gen4/abilities.js.map +1 -1
  27. package/build/data/mods/gen4/items.js +28 -0
  28. package/build/data/mods/gen4/items.js.map +1 -1
  29. package/build/data/mods/gen4/moves.js +14 -6
  30. package/build/data/mods/gen4/moves.js.map +1 -1
  31. package/build/data/mods/gen5/items.js +0 -4
  32. package/build/data/mods/gen5/items.js.map +1 -1
  33. package/build/data/mods/gen6/formats-data.js +3 -3
  34. package/build/data/mods/gen6/formats-data.js.map +1 -1
  35. package/build/data/mods/gen6/items.js +24 -0
  36. package/build/data/mods/gen6/items.js.map +1 -1
  37. package/build/data/mods/gen7/abilities.js +31 -0
  38. package/build/data/mods/gen7/abilities.js.map +1 -1
  39. package/build/data/mods/gen7/items.js +12 -0
  40. package/build/data/mods/gen7/items.js.map +1 -1
  41. package/build/data/mods/gen7/moves.js +14 -0
  42. package/build/data/mods/gen7/moves.js.map +1 -1
  43. package/build/data/moves.js +45 -19
  44. package/build/data/moves.js.map +1 -1
  45. package/build/data/rulesets.js +72 -1
  46. package/build/data/rulesets.js.map +1 -1
  47. package/build/data/tags.js +3 -3
  48. package/build/data/tags.js.map +1 -1
  49. package/build/data/text/moves.js +8 -8
  50. package/build/data/text/moves.js.map +1 -1
  51. package/build/sim/battle-queue.d.ts +2 -2
  52. package/build/sim/battle-queue.js +8 -0
  53. package/build/sim/battle-queue.js.map +1 -1
  54. package/build/sim/battle.js +42 -2
  55. package/build/sim/battle.js.map +1 -1
  56. package/build/sim/dex-conditions.d.ts +2 -2
  57. package/build/sim/dex-conditions.js +1 -0
  58. package/build/sim/dex-conditions.js.map +1 -1
  59. package/build/sim/dex-data.js +1 -0
  60. package/build/sim/dex-data.js.map +1 -1
  61. package/build/sim/dex-formats.js +1 -0
  62. package/build/sim/dex-formats.js.map +1 -1
  63. package/build/sim/dex-items.js +1 -0
  64. package/build/sim/dex-items.js.map +1 -1
  65. package/build/sim/dex-moves.d.ts +1 -0
  66. package/build/sim/dex-moves.js +1 -0
  67. package/build/sim/dex-moves.js.map +1 -1
  68. package/build/sim/dex-species.js +1 -0
  69. package/build/sim/dex-species.js.map +1 -1
  70. package/build/sim/pokemon.js +18 -5
  71. package/build/sim/pokemon.js.map +1 -1
  72. package/build/sim/team-validator.js +1 -1
  73. package/build/sim/team-validator.js.map +1 -1
  74. package/config/formats.ts +169 -154
  75. package/data/abilities.ts +2 -2
  76. package/data/aliases.ts +2 -2
  77. package/data/conditions.ts +4 -1
  78. package/data/formats-data.ts +2 -2
  79. package/data/items.ts +4 -2
  80. package/data/learnsets.ts +5 -4
  81. package/data/mods/gen1/formats-data.ts +38 -36
  82. package/data/mods/gen1/scripts.ts +1 -1
  83. package/data/mods/gen2/items.ts +28 -0
  84. package/data/mods/gen2/moves.ts +2 -2
  85. package/data/mods/gen3/items.ts +28 -0
  86. package/data/mods/gen4/abilities.ts +20 -0
  87. package/data/mods/gen4/items.ts +28 -0
  88. package/data/mods/gen4/moves.ts +14 -7
  89. package/data/mods/gen5/items.ts +0 -4
  90. package/data/mods/gen6/formats-data.ts +3 -3
  91. package/data/mods/gen6/items.ts +24 -0
  92. package/data/mods/gen7/abilities.ts +31 -0
  93. package/data/mods/gen7/items.ts +12 -0
  94. package/data/mods/gen7/moves.ts +14 -0
  95. package/data/moves.ts +45 -18
  96. package/data/rulesets.ts +71 -1
  97. package/data/tags.ts +3 -3
  98. package/data/text/moves.ts +8 -8
  99. package/package.json +3 -3
  100. package/sim/battle-queue.ts +10 -2
  101. package/sim/battle.ts +39 -2
  102. package/sim/dex-conditions.ts +7 -2
  103. package/sim/dex-data.ts +1 -0
  104. package/sim/dex-formats.ts +1 -0
  105. package/sim/dex-items.ts +1 -0
  106. package/sim/dex-moves.ts +2 -0
  107. package/sim/dex-species.ts +1 -0
  108. package/sim/pokemon.ts +19 -7
  109. package/sim/team-validator.ts +1 -1
package/sim/battle.ts CHANGED
@@ -1419,6 +1419,20 @@ export class Battle {
1419
1419
  this.turn++;
1420
1420
  this.lastSuccessfulMoveThisTurn = null;
1421
1421
 
1422
+ const dynamaxEnding: Pokemon[] = [];
1423
+ for (const pokemon of this.getAllActive()) {
1424
+ if (pokemon.volatiles['dynamax']?.turns === 3) {
1425
+ dynamaxEnding.push(pokemon);
1426
+ }
1427
+ }
1428
+ if (dynamaxEnding.length > 1) {
1429
+ this.updateSpeed();
1430
+ this.speedSort(dynamaxEnding);
1431
+ }
1432
+ for (const pokemon of dynamaxEnding) {
1433
+ pokemon.removeVolatile('dynamax');
1434
+ }
1435
+
1422
1436
  const trappedBySide: boolean[] = [];
1423
1437
  const stalenessBySide: ('internal' | 'external' | undefined)[] = [];
1424
1438
  for (const side of this.sides) {
@@ -1548,6 +1562,23 @@ export class Battle {
1548
1562
  if (this.gen === 2) this.quickClawRoll = this.randomChance(60, 256);
1549
1563
  if (this.gen === 3) this.quickClawRoll = this.randomChance(1, 5);
1550
1564
 
1565
+ // Crazyhouse Progress checker because sidebars has trouble keeping track of Pokemon.
1566
+ // Please remove me once there is client support.
1567
+ if (this.ruleTable.has('crazyhouserule')) {
1568
+ for (const side of this.sides) {
1569
+ let buf = `raw|${side.name}'s team:<br />`;
1570
+ for (const pokemon of side.pokemon) {
1571
+ if (!buf.endsWith('<br />')) buf += '/</span>&#8203;';
1572
+ if (pokemon.fainted) {
1573
+ buf += `<span style="white-space:nowrap;"><span style="opacity:.3"><psicon pokemon="${pokemon.species.id}" /></span>`;
1574
+ } else {
1575
+ buf += `<span style="white-space:nowrap"><psicon pokemon="${pokemon.species.id}" />`;
1576
+ }
1577
+ }
1578
+ this.add(`${buf}</span>`);
1579
+ }
1580
+ }
1581
+
1551
1582
  this.makeRequest('move');
1552
1583
  }
1553
1584
 
@@ -2422,7 +2453,7 @@ export class Battle {
2422
2453
  action.pokemon.side.dynamaxUsed = true;
2423
2454
  if (action.pokemon.side.allySide) action.pokemon.side.allySide.dynamaxUsed = true;
2424
2455
  break;
2425
- case 'beforeTurnMove': {
2456
+ case 'beforeTurnMove':
2426
2457
  if (!action.pokemon.isActive) return false;
2427
2458
  if (action.pokemon.fainted) return false;
2428
2459
  this.debug('before turn callback: ' + action.move.id);
@@ -2431,7 +2462,13 @@ export class Battle {
2431
2462
  if (!action.move.beforeTurnCallback) throw new Error(`beforeTurnMove has no beforeTurnCallback`);
2432
2463
  action.move.beforeTurnCallback.call(this, action.pokemon, target);
2433
2464
  break;
2434
- }
2465
+ case 'priorityChargeMove':
2466
+ if (!action.pokemon.isActive) return false;
2467
+ if (action.pokemon.fainted) return false;
2468
+ this.debug('priority charge callback: ' + action.move.id);
2469
+ if (!action.move.priorityChargeCallback) throw new Error(`priorityChargeMove has no priorityChargeCallback`);
2470
+ action.move.priorityChargeCallback.call(this, action.pokemon);
2471
+ break;
2435
2472
 
2436
2473
  case 'event':
2437
2474
  this.runEvent(action.event!, action.pokemon);
@@ -635,11 +635,16 @@ export class Condition extends BasicEffect implements
635
635
  declare readonly durationCallback?: (this: Battle, target: Pokemon, source: Pokemon, effect: Effect | null) => number;
636
636
  declare readonly onCopy?: (this: Battle, pokemon: Pokemon) => void;
637
637
  declare readonly onEnd?: (this: Battle, target: Pokemon) => void;
638
- declare readonly onRestart?: (this: Battle, target: Pokemon, source: Pokemon, sourceEffect: Effect) => void;
639
- declare readonly onStart?: (this: Battle, target: Pokemon, source: Pokemon, sourceEffect: Effect) => void;
638
+ declare readonly onRestart?: (
639
+ this: Battle, target: Pokemon, source: Pokemon, sourceEffect: Effect
640
+ ) => boolean | null | void;
641
+ declare readonly onStart?: (
642
+ this: Battle, target: Pokemon, source: Pokemon, sourceEffect: Effect
643
+ ) => boolean | null | void;
640
644
 
641
645
  constructor(data: AnyObject) {
642
646
  super(data);
647
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
643
648
  data = this;
644
649
  this.effectType = (['Weather', 'Status'].includes(data.effectType) ? data.effectType : 'Condition');
645
650
  }
package/sim/dex-data.ts CHANGED
@@ -148,6 +148,7 @@ export class Nature extends BasicEffect implements Readonly<BasicEffect & Nature
148
148
  readonly minus?: StatIDExceptHP;
149
149
  constructor(data: AnyObject) {
150
150
  super(data);
151
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
151
152
  data = this;
152
153
 
153
154
  this.fullname = `nature: ${this.name}`;
@@ -435,6 +435,7 @@ export class Format extends BasicEffect implements Readonly<BasicEffect> {
435
435
 
436
436
  constructor(data: AnyObject) {
437
437
  super(data);
438
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
438
439
  data = this;
439
440
 
440
441
  this.mod = Utils.getString(data.mod) || 'gen8';
package/sim/dex-items.ts CHANGED
@@ -113,6 +113,7 @@ export class Item extends BasicEffect implements Readonly<BasicEffect> {
113
113
 
114
114
  constructor(data: AnyObject) {
115
115
  super(data);
116
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
116
117
  data = this;
117
118
 
118
119
  this.fullname = `item: ${this.name}`;
package/sim/dex-moves.ts CHANGED
@@ -105,6 +105,7 @@ export interface MoveEventMethods {
105
105
  beforeMoveCallback?: (this: Battle, pokemon: Pokemon, target: Pokemon | null, move: ActiveMove) => boolean | void;
106
106
  beforeTurnCallback?: (this: Battle, pokemon: Pokemon, target: Pokemon) => void;
107
107
  damageCallback?: (this: Battle, pokemon: Pokemon, target: Pokemon) => number | false;
108
+ priorityChargeCallback?: (this: Battle, pokemon: Pokemon) => void;
108
109
 
109
110
  onAfterHit?: CommonHandlers['VoidSourceMove'];
110
111
  onAfterSubDamage?: (this: Battle, damage: number, target: Pokemon, source: Pokemon, move: ActiveMove) => void;
@@ -470,6 +471,7 @@ export class DataMove extends BasicEffect implements Readonly<BasicEffect & Move
470
471
 
471
472
  constructor(data: AnyObject) {
472
473
  super(data);
474
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
473
475
  data = this;
474
476
 
475
477
  this.fullname = `move: ${this.name}`;
@@ -242,6 +242,7 @@ export class Species extends BasicEffect implements Readonly<BasicEffect & Speci
242
242
 
243
243
  constructor(data: AnyObject) {
244
244
  super(data);
245
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
245
246
  data = this;
246
247
 
247
248
  this.fullname = `pokemon: ${data.name}`;
package/sim/pokemon.ts CHANGED
@@ -809,9 +809,12 @@ export class Pokemon {
809
809
  }
810
810
 
811
811
  ignoringItem() {
812
- return !!((this.battle.gen >= 5 && !this.isActive) ||
812
+ return !!(
813
+ this.itemState.knockedOff || // Gen 3-4
814
+ (this.battle.gen >= 5 && !this.isActive) ||
813
815
  (this.hasAbility('klutz') && !this.getItem().ignoreKlutz) ||
814
- this.volatiles['embargo'] || this.battle.field.pseudoWeather['magicroom']);
816
+ this.volatiles['embargo'] || this.battle.field.pseudoWeather['magicroom']
817
+ );
815
818
  }
816
819
 
817
820
  deductPP(move: string | Move, amount?: number | null, target?: Pokemon | null | false) {
@@ -1198,7 +1201,15 @@ export class Pokemon {
1198
1201
  }
1199
1202
  let boostName: BoostID;
1200
1203
  for (boostName in pokemon.boosts) {
1201
- this.boosts[boostName] = pokemon.boosts[boostName]!;
1204
+ this.boosts[boostName] = pokemon.boosts[boostName];
1205
+ if (this.battle.gen <= 1) {
1206
+ if (boostName === 'evasion' || boostName === 'accuracy') continue;
1207
+ if (this.boosts[boostName] >= 0) {
1208
+ this.modifyStat!(boostName, [1, 1.5, 2, 2.5, 3, 3.5, 4][this.boosts[boostName]]);
1209
+ } else {
1210
+ this.modifyStat!(boostName, [100, 66, 50, 40, 33, 28, 25][-this.boosts[boostName]] / 100);
1211
+ }
1212
+ }
1202
1213
  }
1203
1214
  if (this.battle.gen >= 6) {
1204
1215
  const volatilesToCopy = ['focusenergy', 'gmaxchistrike', 'laserfocus'];
@@ -1596,7 +1607,7 @@ export class Pokemon {
1596
1607
  }
1597
1608
 
1598
1609
  eatItem(force?: boolean, source?: Pokemon, sourceEffect?: Effect) {
1599
- if (!this.item) return false;
1610
+ if (!this.item || this.itemState.knockedOff) return false;
1600
1611
  if ((!this.hp && this.item !== 'jabocaberry' && this.item !== 'rowapberry') || !this.isActive) return false;
1601
1612
 
1602
1613
  if (!sourceEffect && this.battle.effect) sourceEffect = this.battle.effect;
@@ -1636,7 +1647,7 @@ export class Pokemon {
1636
1647
 
1637
1648
  useItem(source?: Pokemon, sourceEffect?: Effect) {
1638
1649
  if ((!this.hp && !this.getItem().isGem) || !this.isActive) return false;
1639
- if (!this.item) return false;
1650
+ if (!this.item || this.itemState.knockedOff) return false;
1640
1651
 
1641
1652
  if (!sourceEffect && this.battle.effect) sourceEffect = this.battle.effect;
1642
1653
  if (!source && this.battle.event && this.battle.event.target) source = this.battle.event.target;
@@ -1672,11 +1683,11 @@ export class Pokemon {
1672
1683
 
1673
1684
  takeItem(source?: Pokemon) {
1674
1685
  if (!this.isActive) return false;
1675
- if (!this.item) return false;
1686
+ if (!this.item || this.itemState.knockedOff) return false;
1676
1687
  if (!source) source = this;
1677
1688
  if (this.battle.gen === 4) {
1678
1689
  if (toID(this.ability) === 'multitype') return false;
1679
- if (source && toID(source.ability) === 'multitype') return false;
1690
+ if (toID(source.ability) === 'multitype') return false;
1680
1691
  }
1681
1692
  const item = this.getItem();
1682
1693
  if (this.battle.runEvent('TakeItem', this, source, null, item)) {
@@ -1690,6 +1701,7 @@ export class Pokemon {
1690
1701
 
1691
1702
  setItem(item: string | Item, source?: Pokemon, effect?: Effect) {
1692
1703
  if (!this.hp || !this.isActive) return false;
1704
+ if (this.itemState.knockedOff) return false;
1693
1705
  if (typeof item === 'string') item = this.battle.dex.items.get(item);
1694
1706
 
1695
1707
  const effectid = this.battle.effect ? this.battle.effect.id : '';
@@ -1564,7 +1564,7 @@ export class TeamValidator {
1564
1564
 
1565
1565
  setHas['ability:' + ability.id] = true;
1566
1566
 
1567
- if (this.format.id === 'gen8pokebilities') {
1567
+ if (this.format.id.startsWith('gen8pokebilities')) {
1568
1568
  const species = dex.species.get(set.species);
1569
1569
  const unSeenAbilities = Object.keys(species.abilities)
1570
1570
  .filter(key => key !== 'S' && (key !== 'H' || !species.unreleasedHidden))