@pkmn/sim 0.9.34 → 0.9.35

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 (41) hide show
  1. package/build/cjs/config/formats.js +27 -67
  2. package/build/cjs/config/formats.js.map +1 -1
  3. package/build/cjs/data/aliases.js +2 -2
  4. package/build/cjs/data/aliases.js.map +1 -1
  5. package/build/cjs/data/formats-data.js +1 -1
  6. package/build/cjs/data/mods/gen2/formats-data.js +6 -6
  7. package/build/cjs/data/mods/gen2/formats-data.js.map +1 -1
  8. package/build/cjs/data/mods/gen3/moves.js +2 -2
  9. package/build/cjs/data/mods/gen3/moves.js.map +1 -1
  10. package/build/cjs/data/mods/gen4/moves.js +2 -2
  11. package/build/cjs/data/mods/gen4/moves.js.map +1 -1
  12. package/build/cjs/data/moves.js +3 -3
  13. package/build/cjs/data/moves.js.map +1 -1
  14. package/build/cjs/data/text/abilities.js +5 -8
  15. package/build/cjs/data/text/abilities.js.map +1 -1
  16. package/build/cjs/data/text/moves.js +1 -0
  17. package/build/cjs/data/text/moves.js.map +1 -1
  18. package/build/cjs/sim/battle.d.ts +1 -0
  19. package/build/cjs/sim/battle.js +24 -56
  20. package/build/cjs/sim/battle.js.map +1 -1
  21. package/build/esm/config/formats.mjs +27 -67
  22. package/build/esm/config/formats.mjs.map +1 -1
  23. package/build/esm/data/aliases.mjs +2 -2
  24. package/build/esm/data/aliases.mjs.map +1 -1
  25. package/build/esm/data/formats-data.mjs +1 -1
  26. package/build/esm/data/mods/gen2/formats-data.mjs +6 -6
  27. package/build/esm/data/mods/gen2/formats-data.mjs.map +1 -1
  28. package/build/esm/data/mods/gen3/moves.mjs +2 -2
  29. package/build/esm/data/mods/gen3/moves.mjs.map +1 -1
  30. package/build/esm/data/mods/gen4/moves.mjs +2 -2
  31. package/build/esm/data/mods/gen4/moves.mjs.map +1 -1
  32. package/build/esm/data/moves.mjs +3 -3
  33. package/build/esm/data/moves.mjs.map +1 -1
  34. package/build/esm/data/text/abilities.mjs +5 -8
  35. package/build/esm/data/text/abilities.mjs.map +1 -1
  36. package/build/esm/data/text/moves.mjs +1 -0
  37. package/build/esm/data/text/moves.mjs.map +1 -1
  38. package/build/esm/sim/battle.d.mts +1 -0
  39. package/build/esm/sim/battle.mjs +24 -56
  40. package/build/esm/sim/battle.mjs.map +1 -1
  41. package/package.json +2 -2
@@ -841,6 +841,19 @@ class Battle {
841
841
  }
842
842
  return handler;
843
843
  }
844
+ getCallback(target, effect, callbackName) {
845
+ let callback = effect[callbackName];
846
+ // Abilities and items Start at different times during the SwitchIn event, so we run their onStart handlers
847
+ // during the SwitchIn event instead of running the Start event during switch-ins
848
+ // gens 4 and before still use the old system, though
849
+ if (callback === undefined && target instanceof pokemon_1.Pokemon && this.gen >= 5 && callbackName === 'onSwitchIn' &&
850
+ !effect.onAnySwitchIn && (['Ability', 'Item'].includes(effect.effectType) || (
851
+ // Innate abilities/items
852
+ effect.effectType === 'Status' && ['ability', 'item'].includes(effect.id.split(':')[0])))) {
853
+ callback = effect.onStart;
854
+ }
855
+ return callback;
856
+ }
844
857
  findEventHandlers(target, eventName, source) {
845
858
  let handlers = [];
846
859
  if (Array.isArray(target)) {
@@ -895,8 +908,7 @@ class Battle {
895
908
  findPokemonEventHandlers(pokemon, callbackName, getKey) {
896
909
  const handlers = [];
897
910
  const status = pokemon.getStatus();
898
- // @ts-expect-error dynamic lookup
899
- let callback = status[callbackName];
911
+ let callback = this.getCallback(pokemon, status, callbackName);
900
912
  if (callback !== undefined || (getKey && pokemon.statusState[getKey])) {
901
913
  handlers.push(this.resolvePriority({
902
914
  effect: status, callback, state: pokemon.statusState, end: pokemon.clearStatus, effectHolder: pokemon,
@@ -905,67 +917,29 @@ class Battle {
905
917
  for (const id in pokemon.volatiles) {
906
918
  const volatileState = pokemon.volatiles[id];
907
919
  const volatile = this.dex.conditions.getByID(id);
908
- // @ts-expect-error dynamic lookup
909
- callback = volatile[callbackName];
920
+ callback = this.getCallback(pokemon, volatile, callbackName);
910
921
  if (callback !== undefined || (getKey && volatileState[getKey])) {
911
922
  handlers.push(this.resolvePriority({
912
923
  effect: volatile, callback, state: volatileState, end: pokemon.removeVolatile, effectHolder: pokemon,
913
924
  }, callbackName));
914
925
  }
915
- else if (['ability', 'item'].includes(volatile.id.split(':')[0])) {
916
- // Innate abilities/items; see comment below
917
- // @ts-expect-error dynamic lookup
918
- if (this.gen >= 5 && callbackName === 'onSwitchIn' && !volatile.onAnySwitchIn) {
919
- callback = volatile.onStart;
920
- if (callback !== undefined || (getKey && volatileState[getKey])) {
921
- handlers.push(this.resolvePriority({
922
- effect: volatile, callback, state: volatileState, end: pokemon.removeVolatile, effectHolder: pokemon,
923
- }, callbackName));
924
- }
925
- }
926
- }
927
926
  }
928
- // Abilities and items Start at different times during the SwitchIn event, so we run their onStart handlers
929
- // during the SwitchIn event instead of running the Start event during switch-ins
930
- // gens 4 and before still use the old system, though
931
927
  const ability = pokemon.getAbility();
932
- // @ts-expect-error dynamic lookup
933
- callback = ability[callbackName];
928
+ callback = this.getCallback(pokemon, ability, callbackName);
934
929
  if (callback !== undefined || (getKey && pokemon.abilityState[getKey])) {
935
930
  handlers.push(this.resolvePriority({
936
931
  effect: ability, callback, state: pokemon.abilityState, end: pokemon.clearAbility, effectHolder: pokemon,
937
932
  }, callbackName));
938
- // @ts-expect-error dynamic lookup
939
- }
940
- else if (this.gen >= 5 && callbackName === 'onSwitchIn' && !ability.onAnySwitchIn) {
941
- // @ts-expect-error dynamic lookup
942
- callback = ability.onStart;
943
- if (callback !== undefined || (getKey && pokemon.abilityState[getKey])) {
944
- handlers.push(this.resolvePriority({
945
- effect: ability, callback, state: pokemon.abilityState, end: pokemon.clearAbility, effectHolder: pokemon,
946
- }, callbackName));
947
- }
948
933
  }
949
934
  const item = pokemon.getItem();
950
- // @ts-expect-error dynamic lookup
951
- callback = item[callbackName];
935
+ callback = this.getCallback(pokemon, item, callbackName);
952
936
  if (callback !== undefined || (getKey && pokemon.itemState[getKey])) {
953
937
  handlers.push(this.resolvePriority({
954
938
  effect: item, callback, state: pokemon.itemState, end: pokemon.clearItem, effectHolder: pokemon,
955
939
  }, callbackName));
956
- // @ts-expect-error dynamic lookup
957
- }
958
- else if (this.gen >= 5 && callbackName === 'onSwitchIn' && !item.onAnySwitchIn) {
959
- callback = item.onStart;
960
- if (callback !== undefined || (getKey && pokemon.itemState[getKey])) {
961
- handlers.push(this.resolvePriority({
962
- effect: item, callback, state: pokemon.itemState, end: pokemon.clearItem, effectHolder: pokemon,
963
- }, callbackName));
964
- }
965
940
  }
966
941
  const species = pokemon.baseSpecies;
967
- // @ts-expect-error dynamic lookup
968
- callback = species[callbackName];
942
+ callback = this.getCallback(pokemon, species, callbackName);
969
943
  if (callback !== undefined) {
970
944
  handlers.push(this.resolvePriority({
971
945
  effect: species, callback, state: pokemon.speciesState, end() { }, effectHolder: pokemon,
@@ -975,8 +949,7 @@ class Battle {
975
949
  for (const conditionid in side.slotConditions[pokemon.position]) {
976
950
  const slotConditionState = side.slotConditions[pokemon.position][conditionid];
977
951
  const slotCondition = this.dex.conditions.getByID(conditionid);
978
- // @ts-expect-error dynamic lookup
979
- callback = slotCondition[callbackName];
952
+ callback = this.getCallback(pokemon, slotCondition, callbackName);
980
953
  if (callback !== undefined || (getKey && slotConditionState[getKey])) {
981
954
  handlers.push(this.resolvePriority({
982
955
  effect: slotCondition,
@@ -994,8 +967,7 @@ class Battle {
994
967
  const handlers = [];
995
968
  let callback;
996
969
  const format = this.format;
997
- // @ts-expect-error dynamic lookup
998
- callback = format[callbackName];
970
+ callback = this.getCallback(this, format, callbackName);
999
971
  if (callback !== undefined || (getKey && this.formatData[getKey])) {
1000
972
  handlers.push(this.resolvePriority({
1001
973
  effect: format, callback, state: this.formatData, end: null, effectHolder: customHolder || this,
@@ -1018,8 +990,7 @@ class Battle {
1018
990
  for (const id in field.pseudoWeather) {
1019
991
  const pseudoWeatherState = field.pseudoWeather[id];
1020
992
  const pseudoWeather = this.dex.conditions.getByID(id);
1021
- // @ts-expect-error dynamic lookup
1022
- callback = pseudoWeather[callbackName];
993
+ callback = this.getCallback(field, pseudoWeather, callbackName);
1023
994
  if (callback !== undefined || (getKey && pseudoWeatherState[getKey])) {
1024
995
  handlers.push(this.resolvePriority({
1025
996
  effect: pseudoWeather, callback, state: pseudoWeatherState,
@@ -1028,8 +999,7 @@ class Battle {
1028
999
  }
1029
1000
  }
1030
1001
  const weather = field.getWeather();
1031
- // @ts-expect-error dynamic lookup
1032
- callback = weather[callbackName];
1002
+ callback = this.getCallback(field, weather, callbackName);
1033
1003
  if (callback !== undefined || (getKey && this.field.weatherState[getKey])) {
1034
1004
  handlers.push(this.resolvePriority({
1035
1005
  effect: weather, callback, state: this.field.weatherState,
@@ -1037,8 +1007,7 @@ class Battle {
1037
1007
  }, callbackName));
1038
1008
  }
1039
1009
  const terrain = field.getTerrain();
1040
- // @ts-expect-error dynamic lookup
1041
- callback = terrain[callbackName];
1010
+ callback = this.getCallback(field, terrain, callbackName);
1042
1011
  if (callback !== undefined || (getKey && field.terrainState[getKey])) {
1043
1012
  handlers.push(this.resolvePriority({
1044
1013
  effect: terrain, callback, state: field.terrainState,
@@ -1052,8 +1021,7 @@ class Battle {
1052
1021
  for (const id in side.sideConditions) {
1053
1022
  const sideConditionData = side.sideConditions[id];
1054
1023
  const sideCondition = this.dex.conditions.getByID(id);
1055
- // @ts-expect-error dynamic lookup
1056
- const callback = sideCondition[callbackName];
1024
+ const callback = this.getCallback(side, sideCondition, callbackName);
1057
1025
  if (callback !== undefined || (getKey && sideConditionData[getKey])) {
1058
1026
  handlers.push(this.resolvePriority({
1059
1027
  effect: sideCondition, callback, state: sideConditionData,