@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
@@ -837,6 +837,19 @@ export class Battle {
837
837
  }
838
838
  return handler;
839
839
  }
840
+ getCallback(target, effect, callbackName) {
841
+ let callback = effect[callbackName];
842
+ // Abilities and items Start at different times during the SwitchIn event, so we run their onStart handlers
843
+ // during the SwitchIn event instead of running the Start event during switch-ins
844
+ // gens 4 and before still use the old system, though
845
+ if (callback === undefined && target instanceof Pokemon && this.gen >= 5 && callbackName === 'onSwitchIn' &&
846
+ !effect.onAnySwitchIn && (['Ability', 'Item'].includes(effect.effectType) || (
847
+ // Innate abilities/items
848
+ effect.effectType === 'Status' && ['ability', 'item'].includes(effect.id.split(':')[0])))) {
849
+ callback = effect.onStart;
850
+ }
851
+ return callback;
852
+ }
840
853
  findEventHandlers(target, eventName, source) {
841
854
  let handlers = [];
842
855
  if (Array.isArray(target)) {
@@ -891,8 +904,7 @@ export class Battle {
891
904
  findPokemonEventHandlers(pokemon, callbackName, getKey) {
892
905
  const handlers = [];
893
906
  const status = pokemon.getStatus();
894
- // @ts-expect-error dynamic lookup
895
- let callback = status[callbackName];
907
+ let callback = this.getCallback(pokemon, status, callbackName);
896
908
  if (callback !== undefined || (getKey && pokemon.statusState[getKey])) {
897
909
  handlers.push(this.resolvePriority({
898
910
  effect: status, callback, state: pokemon.statusState, end: pokemon.clearStatus, effectHolder: pokemon,
@@ -901,67 +913,29 @@ export class Battle {
901
913
  for (const id in pokemon.volatiles) {
902
914
  const volatileState = pokemon.volatiles[id];
903
915
  const volatile = this.dex.conditions.getByID(id);
904
- // @ts-expect-error dynamic lookup
905
- callback = volatile[callbackName];
916
+ callback = this.getCallback(pokemon, volatile, callbackName);
906
917
  if (callback !== undefined || (getKey && volatileState[getKey])) {
907
918
  handlers.push(this.resolvePriority({
908
919
  effect: volatile, callback, state: volatileState, end: pokemon.removeVolatile, effectHolder: pokemon,
909
920
  }, callbackName));
910
921
  }
911
- else if (['ability', 'item'].includes(volatile.id.split(':')[0])) {
912
- // Innate abilities/items; see comment below
913
- // @ts-expect-error dynamic lookup
914
- if (this.gen >= 5 && callbackName === 'onSwitchIn' && !volatile.onAnySwitchIn) {
915
- callback = volatile.onStart;
916
- if (callback !== undefined || (getKey && volatileState[getKey])) {
917
- handlers.push(this.resolvePriority({
918
- effect: volatile, callback, state: volatileState, end: pokemon.removeVolatile, effectHolder: pokemon,
919
- }, callbackName));
920
- }
921
- }
922
- }
923
922
  }
924
- // Abilities and items Start at different times during the SwitchIn event, so we run their onStart handlers
925
- // during the SwitchIn event instead of running the Start event during switch-ins
926
- // gens 4 and before still use the old system, though
927
923
  const ability = pokemon.getAbility();
928
- // @ts-expect-error dynamic lookup
929
- callback = ability[callbackName];
924
+ callback = this.getCallback(pokemon, ability, callbackName);
930
925
  if (callback !== undefined || (getKey && pokemon.abilityState[getKey])) {
931
926
  handlers.push(this.resolvePriority({
932
927
  effect: ability, callback, state: pokemon.abilityState, end: pokemon.clearAbility, effectHolder: pokemon,
933
928
  }, callbackName));
934
- // @ts-expect-error dynamic lookup
935
- }
936
- else if (this.gen >= 5 && callbackName === 'onSwitchIn' && !ability.onAnySwitchIn) {
937
- // @ts-expect-error dynamic lookup
938
- callback = ability.onStart;
939
- if (callback !== undefined || (getKey && pokemon.abilityState[getKey])) {
940
- handlers.push(this.resolvePriority({
941
- effect: ability, callback, state: pokemon.abilityState, end: pokemon.clearAbility, effectHolder: pokemon,
942
- }, callbackName));
943
- }
944
929
  }
945
930
  const item = pokemon.getItem();
946
- // @ts-expect-error dynamic lookup
947
- callback = item[callbackName];
931
+ callback = this.getCallback(pokemon, item, callbackName);
948
932
  if (callback !== undefined || (getKey && pokemon.itemState[getKey])) {
949
933
  handlers.push(this.resolvePriority({
950
934
  effect: item, callback, state: pokemon.itemState, end: pokemon.clearItem, effectHolder: pokemon,
951
935
  }, callbackName));
952
- // @ts-expect-error dynamic lookup
953
- }
954
- else if (this.gen >= 5 && callbackName === 'onSwitchIn' && !item.onAnySwitchIn) {
955
- callback = item.onStart;
956
- if (callback !== undefined || (getKey && pokemon.itemState[getKey])) {
957
- handlers.push(this.resolvePriority({
958
- effect: item, callback, state: pokemon.itemState, end: pokemon.clearItem, effectHolder: pokemon,
959
- }, callbackName));
960
- }
961
936
  }
962
937
  const species = pokemon.baseSpecies;
963
- // @ts-expect-error dynamic lookup
964
- callback = species[callbackName];
938
+ callback = this.getCallback(pokemon, species, callbackName);
965
939
  if (callback !== undefined) {
966
940
  handlers.push(this.resolvePriority({
967
941
  effect: species, callback, state: pokemon.speciesState, end() { }, effectHolder: pokemon,
@@ -971,8 +945,7 @@ export class Battle {
971
945
  for (const conditionid in side.slotConditions[pokemon.position]) {
972
946
  const slotConditionState = side.slotConditions[pokemon.position][conditionid];
973
947
  const slotCondition = this.dex.conditions.getByID(conditionid);
974
- // @ts-expect-error dynamic lookup
975
- callback = slotCondition[callbackName];
948
+ callback = this.getCallback(pokemon, slotCondition, callbackName);
976
949
  if (callback !== undefined || (getKey && slotConditionState[getKey])) {
977
950
  handlers.push(this.resolvePriority({
978
951
  effect: slotCondition,
@@ -990,8 +963,7 @@ export class Battle {
990
963
  const handlers = [];
991
964
  let callback;
992
965
  const format = this.format;
993
- // @ts-expect-error dynamic lookup
994
- callback = format[callbackName];
966
+ callback = this.getCallback(this, format, callbackName);
995
967
  if (callback !== undefined || (getKey && this.formatData[getKey])) {
996
968
  handlers.push(this.resolvePriority({
997
969
  effect: format, callback, state: this.formatData, end: null, effectHolder: customHolder || this,
@@ -1014,8 +986,7 @@ export class Battle {
1014
986
  for (const id in field.pseudoWeather) {
1015
987
  const pseudoWeatherState = field.pseudoWeather[id];
1016
988
  const pseudoWeather = this.dex.conditions.getByID(id);
1017
- // @ts-expect-error dynamic lookup
1018
- callback = pseudoWeather[callbackName];
989
+ callback = this.getCallback(field, pseudoWeather, callbackName);
1019
990
  if (callback !== undefined || (getKey && pseudoWeatherState[getKey])) {
1020
991
  handlers.push(this.resolvePriority({
1021
992
  effect: pseudoWeather, callback, state: pseudoWeatherState,
@@ -1024,8 +995,7 @@ export class Battle {
1024
995
  }
1025
996
  }
1026
997
  const weather = field.getWeather();
1027
- // @ts-expect-error dynamic lookup
1028
- callback = weather[callbackName];
998
+ callback = this.getCallback(field, weather, callbackName);
1029
999
  if (callback !== undefined || (getKey && this.field.weatherState[getKey])) {
1030
1000
  handlers.push(this.resolvePriority({
1031
1001
  effect: weather, callback, state: this.field.weatherState,
@@ -1033,8 +1003,7 @@ export class Battle {
1033
1003
  }, callbackName));
1034
1004
  }
1035
1005
  const terrain = field.getTerrain();
1036
- // @ts-expect-error dynamic lookup
1037
- callback = terrain[callbackName];
1006
+ callback = this.getCallback(field, terrain, callbackName);
1038
1007
  if (callback !== undefined || (getKey && field.terrainState[getKey])) {
1039
1008
  handlers.push(this.resolvePriority({
1040
1009
  effect: terrain, callback, state: field.terrainState,
@@ -1048,8 +1017,7 @@ export class Battle {
1048
1017
  for (const id in side.sideConditions) {
1049
1018
  const sideConditionData = side.sideConditions[id];
1050
1019
  const sideCondition = this.dex.conditions.getByID(id);
1051
- // @ts-expect-error dynamic lookup
1052
- const callback = sideCondition[callbackName];
1020
+ const callback = this.getCallback(side, sideCondition, callbackName);
1053
1021
  if (callback !== undefined || (getKey && sideConditionData[getKey])) {
1054
1022
  handlers.push(this.resolvePriority({
1055
1023
  effect: sideCondition, callback, state: sideConditionData,