Giter Site home page Giter Site logo

ps's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ps's Issues

Unable to easily add custom formats

Users get confused when formats are missing as the documentation does not make clear that @pkmn/sim contains a different set of configured formats than upstream Pokémon Showdown by design. Documentation should call this out, explain that config/formats.ts is in fact configuration that depends on arbitrary project preferences and thus something you can not always depend on, and also show how to easily augment the default formats with ones preferred formats (or those formats which are present on https://github.com/smogon/pokemon-showdown).

Sadly, this last part is not working as intended today due to some intersection of #21 and #25, so really all three of the issues will probably get addressed at the same time.

Protocol: Support `|deinit` message

This message type isn't in the PROTOCOL docs, but is handled by the client when leaving a room. The fix seems simple enough so I could open up a quick PR if needed.

Could there be other unsupported message types? Another one I found is |noinit for rejecting room joins, though I'm not sure how far this project wants to go into the undocumented parts of the protocol by reverse-engineering it.

@pkmn/sim: Running `Dex.formats.getRuleTable(Dex.formats.get('gen9lc'))` crashes

Describe the bug:

Running Dex.formats.getRuleTable(Dex.formats.get('gen9lc')) crashes on @pkmn/sim:0.7.57 with the error:

Uncaught Error: Rule "-Stantler" in "[Gen 9] LC" already exists in "Little Cup"
    at DexFormats.getRuleTable (/home/jet/workspace/pkmnsimtest/node_modules/@pkmn/sim/build/cjs/sim/dex-formats.js:514:27)

Example:

import { Dex } from '@pkmn/sim'
Dex.includeFormats();
console.log(Dex.formats.getRuleTable(Dex.formats.get('gen9lc')));

Expected behavior:

Dex.formats.getRuleTable should have returned the rule table and not crashed.

Additional context:

Running the equivalent code on smogon/pokemon-showdown@813f2ef works as expected.

Discord conversation: https://discord.com/channels/689316505560809576/689316506265321535/1170051792818667621

Unexpected Token error when loading pkmn/sim library?

Hi there!

I've been experiencing an issue here with trying to compile a script with specifically @pkmn/sim installed. (Doesn't seem to happen with other @pkmn libraries from what I can see.)

My setup is using Vue+Typescript / webpack.

Here's the specific error I'm getting:

in ./node_modules/@pkmn/sim/build/sim/dex.js

Module parse failed: Unexpected token (102:20)
You may need an additional loader to handle the result of these loaders.
|             return dexes['base'];
|         const modid = exports.toID(mod);
>         if (modData?.Types && !modData.TypeChart)
|             modData.TypeChart = modData.Types;
|         if (modData?.Species && !modData.Pokedex)

It also returns the same error (Unexpected token) in multiple other files (battle-stream.js(163:40), teams.js(31:42), streams.js(340:17), etc.)

In the code itself, I simply have import dex from '@pkmn/sim' at the top of my file. No other code there yet (Besides default vue items), so it's failing on the import for some reason. I've noticed this happens no matter what class I load from sim as well. If I load BattleStreams, RandomPlayerAI, etc. they will all return the same error at the same location.

This doesn't happen when I use import dex from '@pkmn/dex' ironically, so I think it's something specific with the sim library itself.

Any help on this would be greatly appreciated!

Thanks

gen7vgc2017 team validation

I've found this weird thing while playing around with the team validator in the sim package.
I pass a team to validate in showdown's export syntax and the format's validation string (in this case 'gen7vgc2017') and it returns this error:
TypeError: Cannot read property 'includeData' of undefined
[1] at ModdedDex.forFormat (C:\Users\Zuech\Documents\GitHub\TeamBuilder-Project\node_modules\@pkmn\sim\build\sim\dex.js:129:39)
[1] at new TeamValidator (C:\Users\Zuech\Documents\GitHub\TeamBuilder-Project\node_modules\@pkmn\sim\build\sim\team-validator.js:141:30)

The code used server-side for validation is just this:

const pkg1 = require('@pkmn/sets');
const pkg2 = require('@pkmn/sim');

const {Team} = pkg1;
const {TeamValidator} = pkg2;

function teamValidate(teamStr, format) {
const validator = new TeamValidator(format);
return validator.validateTeam(Team.import(teamStr).team);
}

module.exports = {
teamValidate: teamValidate,
}

I've tested the code with different teams for gen7vgc2018 and gen7vgc2019@@@-Blue Orb,-Red Orb,Z-Move Clause,-Mega,-Dragon Ascent and it seems to work fine in these formats.

I'll also try to simulate vgc17's ruleset and banlist using custum rules, I'll let you know if the same problem comes out again.

provide event based battle handling for /client

Is your feature request related to a problem? Please describe:
Sort of yes. Working with streams is to be blunt a real pain in the ass. It's hard to parse out whatever is going on and to figure out what response it wants.

A clear and concise description of what the problem is.
Accessibility. Working with streams just really is very displeasing.
Describe the solution you'd like:

An eventemitter based way of handling battles with structures being emitted that allow manipulation of the battle.

client.on('request', data => {
  if (data.request === "format") data.send(format);
  if (data.request === "players") data.send(players);
  if (data.request === "move") data.send(move);
}

client.on('log', data => {
  console.log(data.spectator);
  console.log(data.p1);
  console.log(data.p2);
}

A clear and concise description of what you want to happen.

A user friendly way of simulating a showdown battle and receiving the battle log irt.

Describe alternatives you've considered:
A clear and concise description of any alternative solutions or features you've considered.

Open to anything that provides a simple interface to simulate a battle, eventemitters where the first thing that came to mind

@pkmn/client: Only the set info for the first Pokemon on each side is propagated

Describe the bug:

Only the set info for the first Pokemon on each side is propagated to the Pokemon.

Example:

import {Battle} from '@pkmn/client';
import {Generations} from '@pkmn/data';
import {Dex} from '@pkmn/dex';
import {BattleStreams, RandomPlayerAI, Teams} from '@pkmn/sim';
 
const streams = BattleStreams.getPlayerStreams(new BattleStreams.BattleStream());
const spec = {formatid: 'gen9customgame'};
 
const p1spec = {name: 'Bot 1', team: `Lycanroc|LycanrocMidnight|LifeOrb|NoGuard|knockoff,stealthrock,psychicfangs,stoneedge||85,85,85,85,85,85||||89|,,,,,Rock]Iron Valiant||LifeOrb|QuarkDrive|swordsdance,closecombat,spiritbreak,knockoff||85,85,85,85,85,85|N|||79|,,,,,Fighting]Venomoth||HeavyDutyBoots|TintedLens|quiverdance,sludgebomb,bugbuzz,sleeppowder||85,,85,85,85,85||,0,,,,||85|,,,,,Water]Skeledirge||HeavyDutyBoots|Unaware|flamecharge,slackoff,torchsong,shadowball||85,85,85,85,85,85||||79|,,,,,Fire]Annihilape||ChestoBerry|Defiant|drainpunch,ragefist,rest,bulkup||85,85,85,85,85,85||||76|,,,,,Ghost]Braviary|BraviaryHisui|LifeOrb|SheerForce|agility,heatwave,psychic,hurricane||85,,85,85,85,85|M|,0,,,,||84|,,,,,Fairy`};
const p2spec = {name: 'Bot 2', team: `Milotic||Leftovers|Competitive|recover,icebeam,haze,scald||85,,85,85,85,85||,0,,,,||84|,,,,,Dragon]Cetitan||LifeOrb|SheerForce|iciclecrash,playrough,iceshard,liquidation||85,85,85,85,85,85||||82|,,,,,Fairy]Magnezone||ChoiceScarf|MagnetPull|flashcannon,voltswitch,bodypress,thunderbolt||85,,85,85,85,85|N|,0,,,,||84|,,,,,Flying]Torkoal||HeavyDutyBoots|Drought|yawn,lavaplume,stealthrock,earthquake||85,85,85,85,85,85||||88|,,,,,Dragon]Azelf||LifeOrb|Levitate|psychic,fireblast,knockoff,taunt||85,85,85,85,85,85|N|||82|,,,,,Psychic]Noctowl||HeavyDutyBoots|TintedLens|defog,haze,roost,hurricane||85,,85,85,85,85||,0,,,,||91|,,,,,Steel`};
 
const p1 = new RandomPlayerAI(streams.p1);
const p2 = new RandomPlayerAI(streams.p2);
 
void p1.start();
void p2.start();
 
const battle = new Battle(new Generations(Dex), null, [p1spec.team, p2spec.team].map(t => Teams.import(t)!));
 
void (async () => {
  for await (const chunk of streams.omniscient) {
    for (const line of chunk.split('\n')) {
      battle.add(line);
    }
    battle.update();
  }
})().then(() => {
  for (const poke of battle.p1.team) {
    console.log(poke.name, poke.evs);
  }
  for (const poke of battle.p2.team) {
    console.log(poke.name, poke.evs);
  }
});
 
void streams.omniscient.write(`>start ${JSON.stringify(spec)}
>player p1 ${JSON.stringify(p1spec)}
>player p2 ${JSON.stringify(p2spec)}`);

Expected behavior:

poke.evs (and other set info like poke.ivs have the same issue) would print correctly for each Pokemon.

ditto sometimes fails to be interpreted by @poke/client battle

Having ditto on a team can cause the error below sometimes.

TypeError: Cannot read properties of undefined (reading 'types')
    at Pokemon.copyTypesFrom (/home/ubuntu/dev/ps/ps-env/node_modules/@pkmn/client/build/index.js:1402:82)
    at Handler.|-transform| (/home/ubuntu/dev/ps/ps-env/node_modules/@pkmn/client/build/index.js:708:10)
    at Battle2.add (/home/ubuntu/dev/ps/ps-env/node_modules/@pkmn/client/build/index.js:1839:24)

Here's a repro

import { BattleStreams, Dex, Teams, toID } from "@pkmn/sim";
import { TeamGenerators } from "@pkmn/randoms";
import { Generations } from "@pkmn/data";
import * as Client from "@pkmn/client";

Teams.setGeneratorFactory(TeamGenerators);

const streams = BattleStreams.getPlayerStreams(
  new BattleStreams.BattleStream()
);

void streams.omniscient.write([
  '>start {"formatid":"gen9randombattle","seed":[35268,60808,6898,43784]}',
  '>player p1 {"name":"Bot 1","team":"Ditto||ChoiceScarf|Imposter|transform||85,85,85,85,85,85|N|||88|,,,,,Fire]Mudsdale||ChoiceBand|Stamina|earthquake,bodypress,heavyslam,stoneedge||85,85,85,85,85,85||||86|,,,,,Fighting]Grumpig||Leftovers|ThickFat|psychic,focusblast,earthpower,nastyplot||85,,85,85,85,85||,0,,,,||88|,,,,,Psychic]Camerupt||Leftovers|SolidRock|earthquake,lavaplume,stealthrock,yawn||85,85,85,85,85,85||||88|,,,,,Water]Passimian||ChoiceBand|Defiant|closecombat,knockoff,uturn,rockslide||85,85,85,85,85,85||||86|,,,,,Dark]Dragapult||ChoiceSpecs|Infiltrator|dracometeor,shadowball,thunderbolt,fireblast||85,,85,85,85,85||,0,,,,||80|,,,,,Dragon"}',
  '>player p2 {"name":"Bot 2","team":"Greninja||LifeOrb|Protean|hydropump,darkpulse,gunkshot,toxicspikes||85,85,85,85,85,85||||80|,,,,,Poison]Clodsire||Leftovers|Unaware|curse,earthquake,gunkshot,recover||85,85,85,85,85,85||||80|,,,,,Flying]Coalossal||HeavyDutyBoots|FlameBody|stoneedge,overheat,willowisp,rapidspin||85,85,85,85,85,85||||88|,,,,,Water]Mesprit||ChoiceScarf|Levitate|psychic,thunderbolt,uturn,trick||85,85,85,85,85,85|N|||86|,,,,,Electric]Moltres||HeavyDutyBoots|FlameBody|fireblast,bravebird,roost,willowisp||85,85,85,85,85,85|N|||84|,,,,,Ground]Vespiquen||HeavyDutyBoots|Unnerve|airslash,roost,uturn,toxicspikes||85,85,85,85,85,85|F|||90|,,,,,Steel"}'
].join('\n'));

const p1Bat = new Client.Battle(new Generations(Dex), toID("p1"));

for await (const chunk of streams.p1) {
  for (const line of chunk.split("\n")) {
    p1Bat.add(line);
  }
}

Initializing BattleStream class in Javascript

Hello, I've been toying around with the @pkmn/sim package for a few days, and I cannot seem to initialize the BattleStream class because sim.BattleStream is not recognized as a constructor:

var sim = require('@pkmn/sim');
var battle = new sim.BattleStream();

I've tried initializing the Battle class instead. This class works, but cannot be initialized when the "p1" and "p2" fields in a BattleOptions object are included because the getTeamGenerator() method in dex.ts is incomplete.

I was wondering if there are any solutions to initializing either a BattleStream or Battle class, with team data included, in Javascript. Any insight on this issue would be greatly appreciated.

I think the issue with BattleStream not being recognized as a constructor has something to do with the BattleStream class in battle-stream.ts extending Streams.ObjectReadWriteStream. Some solutions online (https://stackoverflow.com/questions/34844519/typescript-extending-class-in-another-file) say that module loader like Webpack can be used to convert the Typescript files to Javascript, but I have been unable to do this successfully.

Questions about learnset data

Hello,

I'm trying to put together a damage calculator/team builder tool. I'd like to be able to only show valid moves that can be learned for a particular gen. But, I'm not familiar with the format of data that the learnset returns.

      expect((await gens.get(8).learnsets.get('bulbasaur'))!.learnset!.leafstorm)
        .toEqual(['8M', '7E', '6E', '5E', '4E']);

I'm thinking the number is a Gen number, but it doesn't seem to match up with if the move is valid or not. For example, Gengar lists astonish: ["6S4"] but, this is an egg move from Gen 3 to Gen 8.

Also, what does the letter mean? My deduction is that is probably Egg move, TM, TR and so on, but what are all of the codes used?

PocketMon

Is PocketMon playable? Will it ever be? Is a dead project or are you still working on it? I'd really love to play that, competetive pokemon vs AI is something I've dreamed of. Would like to receive any news, here or via mail at [email protected]

Would be really appreciated.

team validator

I hope i'm asking this thing in the correct place, if not i'm sorry.

I have a project i'm working on as an hobby and i would like to use the team validation in the sim package, but i'm having some troubles on understanding how it works.
By looking in the test folder I've made a general idea on how to get it to work, but i would like to know if it's possible to adapt it for custom formats and ban lists (and if it is, where should i look to understand how to do this?).

Also, a small off topic: i think that creating a package just for team validation might be pretty useful, as I've asked around and I'm not the only one who is interested in an easy way to import team validation in a project.

Thanks in advance for the patience and great work with these packages!

Protocol typings: Challenges and SearchState interfaces are swapped

Hi, I'm writing a PS bot that needs to respond to battle challenges. Looking through the @pkmn/protocol typings, I come across these two interfaces:

ps/protocol/src/index.ts

Lines 244 to 247 in c615c86

export interface Challenges {
searching: ID[];
games: { [roomid in RoomID]: RoomTitle};
}

ps/protocol/src/index.ts

Lines 271 to 274 in c615c86

export interface SearchState {
challengesFrom: { [userid in ID]: ID };
challengeTo: null | { o: Username; format: ID };
}

It seems that these two JSON interfaces have their contents swapped? A fix for this would be appreciated.

@pkmn/data: `Learnsets.learnable` results are overwritten instead of merged for evolved species

Describe the bug:

Learnsets.learnable uses Learnsets.all to get learnsets of the species, its pre evolution(s) and possibly other alternative formes.

But instead of merging the data together it's overwritten on every iteration, meaning the last one wins (usually the prevo). As a result some data is lost.

Example:

        expect((await Gen(4).learnsets.learnable('Hitmonlee'))!['megakick'])
          .toEqual(['4L49', '3T', '3L46', '3S0']);

Expected behavior:

Hitmonlee's learnset in gen 4 for Mega Kick is expected to be ['4L49', '3T', '3L46', '3S0']

Instead ['3T'] is returned, which is the the filtered learnset for Tyrogue (Hitmonlee's pre-evolution). It was ['8M', '3T'] before filtering for gen 4.

Additional context:

https://raw.githubusercontent.com/pkmn/ps/master/dex/data/learnsets.json Line 35625 has the correct data:

        "megakick": [
          "8M",
          "8L32",
          "8V",
          "7L1",
          "7V",
          "6L1",
          "5L53",
          "4L49",
          "3T",
          "3L46",
          "3S0"
        ],

I verified the data here:

Impact:

  • Affects most species in some way
  • Gen 1 Alakazam learning Psychic and Reflect by level up in addition to TM
  • Venusaur learning Frenzy Plant by move tutor starting in gen 3
  • ...

Pack/Unpack does not follow showdown formatting when including team name, format and folder.

Describe the bug:

When packing, unpacking, or exporting a Team, the name, format and folder are all ignored...

Example:

An example of this is trying to import a saved team from the Showdown's localStorage.

The packed team (from LocalStorage) looks like this:

gen9vgc2023series2]Team Name|Nickname|amoonguss||effectspore|||||||50|

The imported Team looks like this:

{
  "data": undefined,
  "folder": undefined,
  "format": undefined,
  "name": undefined,
  "team": [
    {
      "name": "gen9vgc2023series2]Team Name",
      "species": "Nickname",
      "item": "amoonguss",
      "ability": "",
      "moves": [
        "effectspore"
      ],
      "nature": "",
      "evs": {
        "hp": 0,
        "atk": 0,
        "def": 0,
        "spa": 0,
        "spd": 0,
        "spe": 0
      },
      "ivs": {
        "hp": 31,
        "atk": 31,
        "def": 31,
        "spa": 31,
        "spd": 31,
        "spe": 31
      },
      "happiness": null,
      "hpType": "",
      "pokeball": "",
      "gigantamax": false,
      "dynamaxLevel": 10,
      "teraType": ""
    }
  ]
}

Expected behavior:

I would expect the imported Team to look like this instead

{
  "data": undefined,
  "folder": undefined,
  "format": "gen9vgc2023series2",
  "name": "Team Name",
  "team": [
    {
      "name": "Nickname",
      "species": "amoonguss",
      "item": "",
      "ability": "effectspore",
      "moves": [ ],
      "nature": "",
      "evs": {
        "hp": 0,
        "atk": 0,
        "def": 0,
        "spa": 0,
        "spd": 0,
        "spe": 0
      },
      "ivs": {
        "hp": 31,
        "atk": 31,
        "def": 31,
        "spa": 31,
        "spd": 31,
        "spe": 31
      }
    }
  ]
}

I would also expect the export to include those details as well.

The import method seems to work correctly when using === [format] team name === but the export does not add those details.

=== [gen9vgc2023series2] Team Name ===

Nickname (Amoonguss)  
Ability: Effect Spore  
Level: 50  
Tera Type: Grass  

@pkmn/client: Level is always overwritten to be 100

Describe the bug:

Level is always overwritten to be 100.

Example:

import {Battle} from '@pkmn/client';
import {Generations} from '@pkmn/data';
import {Dex} from '@pkmn/dex';
import {BattleStreams, RandomPlayerAI, Teams} from '@pkmn/sim';

const streams = BattleStreams.getPlayerStreams(new BattleStreams.BattleStream());
const spec = {formatid: 'gen9customgame'};

const p1spec = {name: 'Bot 1', team: `Lycanroc|LycanrocMidnight|LifeOrb|NoGuard|knockoff,stealthrock,psychicfangs,stoneedge||85,85,85,85,85,85||||89|,,,,,Rock]Iron Valiant||LifeOrb|QuarkDrive|swordsdance,closecombat,spiritbreak,knockoff||85,85,85,85,85,85|N|||79|,,,,,Fighting]Venomoth||HeavyDutyBoots|TintedLens|quiverdance,sludgebomb,bugbuzz,sleeppowder||85,,85,85,85,85||,0,,,,||85|,,,,,Water]Skeledirge||HeavyDutyBoots|Unaware|flamecharge,slackoff,torchsong,shadowball||85,85,85,85,85,85||||79|,,,,,Fire]Annihilape||ChestoBerry|Defiant|drainpunch,ragefist,rest,bulkup||85,85,85,85,85,85||||76|,,,,,Ghost]Braviary|BraviaryHisui|LifeOrb|SheerForce|agility,heatwave,psychic,hurricane||85,,85,85,85,85|M|,0,,,,||84|,,,,,Fairy`};
const p2spec = {name: 'Bot 2', team: `Milotic||Leftovers|Competitive|recover,icebeam,haze,scald||85,,85,85,85,85||,0,,,,||84|,,,,,Dragon]Cetitan||LifeOrb|SheerForce|iciclecrash,playrough,iceshard,liquidation||85,85,85,85,85,85||||82|,,,,,Fairy]Magnezone||ChoiceScarf|MagnetPull|flashcannon,voltswitch,bodypress,thunderbolt||85,,85,85,85,85|N|,0,,,,||84|,,,,,Flying]Torkoal||HeavyDutyBoots|Drought|yawn,lavaplume,stealthrock,earthquake||85,85,85,85,85,85||||88|,,,,,Dragon]Azelf||LifeOrb|Levitate|psychic,fireblast,knockoff,taunt||85,85,85,85,85,85|N|||82|,,,,,Psychic]Noctowl||HeavyDutyBoots|TintedLens|defog,haze,roost,hurricane||85,,85,85,85,85||,0,,,,||91|,,,,,Steel`};

const p1 = new RandomPlayerAI(streams.p1);
const p2 = new RandomPlayerAI(streams.p2);

void p1.start();
void p2.start();

const battle = new Battle(new Generations(Dex), null, [p1spec.team, p2spec.team].map(t => Teams.import(t)!));

void (async () => {
  for await (const chunk of streams.omniscient) {
    console.log(chunk);
    for (const line of chunk.split('\n')) {
      battle.add(line);
    }
    battle.update();
  }
})().then(() => {
  for (const poke of battle.p1.team) {
    console.log(poke.level);
  }
  for (const poke of battle.p2.team) {
    console.log(poke.level);
  }
});

void streams.omniscient.write(`>start ${JSON.stringify(spec)}
>player p1 ${JSON.stringify(p1spec)}
>player p2 ${JSON.stringify(p2spec)}`);

Expected behavior:

The correct levels would be printed as written in the packed team.

Additional context:

https://github.com/pkmn/ps/blob/main/client/src/pokemon.ts#L137
https://github.com/pkmn/ps/blob/main/client/src/pokemon.ts#L146

@pkmn/dex: G-Max Move Handling Changed Unexpectedly

Describe the bug:

G-Max moves in showdown are classified as isNonstandard: "Gigantamax" (see https://github.com/smogon/pokemon-showdown/blob/master/data/moves.ts#L6756) which was also the case in @pkmn/dex as of version 0.6.4.

In 0.7.1 they are now isNonstandard: "Future" even in gen 8.

Example:

expect(Dex.forGen(8).moves.get("G-Max Befuddle").isNonstandard).toBe("Gigantamax");

// Expected: "Gigantamax"
// Received: "Future"

console.log(Dex.forGen(8).moves.get("G-Max Befuddle"));

Expected behavior:

It should still be "Gigantamax".

Additional context:

I think the issue is caused by this line: https://github.com/pkmn/ps/blob/main/dex/index.ts#L593
It sets the value to 'Future' because move.gen is 9 which is greater than 8.
The line seems correct but gen shouldn't be 9 here.

In https://github.com/pkmn/ps/blob/main/dex/index.ts#L528 the gen for moves is set based on their number. Seems fine but for some reason all G-Max moves in showdown have number 1000 and now this breaks the logic.

Thanks for updating this for gen 9 btw!

@pkmn/sim: Running `Dex.formats.getRuleTable(Dex.formats.get('gen9vgc2023regulatione'))` crashes

Describe the bug:

Running Dex.formats.getRuleTable(Dex.formats.get('gen9vgc2023regulatione')) crashes on @pkmn/sim:0.7.57 with the error:

Uncaught Error: Unrecognized rule "Open Team Sheets"
    at DexFormats.validateRule (/home/jet/workspace/pkmnsimtest/node_modules/@pkmn/sim/build/cjs/sim/dex-formats.js:696:27)
    at DexFormats.getRuleTable (/home/jet/workspace/pkmnsimtest/node_modules/@pkmn/sim/build/cjs/sim/dex-formats.js:486:35)

Example:

import { Dex } from '@pkmn/sim'
Dex.includeFormats();
console.log(Dex.formats.getRuleTable(Dex.formats.get('gen9vgc2023regulatione')));

Expected behavior:

Dex.formats.getRuleTable should have returned the rule table and not crashed.

Additional context:

Running the equivalent code on smogon/pokemon-showdown@e5dfd61 works as expected.

Potentially related to #25?

@pkmn/dex: CAP Pokemon Chuggalong does not exist in version 0.9.6

Describe the bug:

In version 0.9.6 of @pkmn/dex CAP Pokemon Chuggalong does not exist as a specie.

Example:

import {Dex} from '@pkmn/dex';

console.log(Dex.forGen(9).species.get('Chuggalong').exists);
❯ node a.mjs
false

Expected behavior:

I expected Dex.forGen(9).species.get('Chuggalong').exists to return true.

Additional context:

Interestingly, in version 0.9.5 of @pkmn/dex the above code sample returns true. So maybe stale code was published for version 0.9.6?

No way to load a ModdedDex into battle simulator

Hey, I'm trying to use this library to do showdown battle simulations that included modded data, and as far as I can tell there's no way to actually start a simulator battle from a modded dex. After a lot of code searching, I believe I've narrowed it down to this difference in @pkmn/dex vs @pkmn/sim (bottom of issue). In the sim version of the Dex.mod function, it does not commit the new dex into the dexes constant, so when a new Battle() is created, it cannot find the newly made dex, and I get various errors. I do have a workaround that seems to work that involves just overwriting everything after the battle is made, but I feel like it should be enough to just added new mods to the list, or maybe passing in a ModdedDex somewhere on creation.

export const MyModDex = Dex.mod('modded' as ID, MyModData as ModData);
const formatid = 'moddedformatid';

const newBattle = new BattleStreams.BattleStream();
this.streams = BattleStreams.getPlayerStreams(newBattle);

const battleSpec = {
    format: MyModDex.formats.get(formatid as ID),
    formatid: formatid as ID
};
this.streams.omniscient.write(`>start ${JSON.stringify(battleSpec)}`);
this.battle = newBattle.battle;
//@ts-ignore
this.battle.format = MyModDex.formats.get(formatid as ID);
this.battle.dex = MyModDex;

this.streams.omniscient.write(`>player p1 ${JSON.stringify(p1)}`);
this.streams.omniscient.write(`>player p2 ${JSON.stringify(p2)}`);

I'd submit a PR to fix but I'm pretty scared about the whole way this system is designed with the whole automatic code merging and all, so I'm hoping I just overlooked something and there's already a way to do this that I missed. Thank you for making this repo!

@pkmn/dex - Overwrites the dexes constant

ps/dex/index.ts

Lines 1243 to 1246 in ab700ad

mod(modid: GenID | T.ID, modData?: ModData) {
if (modid in dexes) return modData ? new ModdedDex(modid, modData) : dexes[modid];
return (dexes[modid] = new ModdedDex(modid as T.ID, modData));
}

@pkmn/sim - Does not overwrite the dexes constant

ps/sim/sim/dex.ts

Lines 219 to 227 in ab700ad

mod(mod: string | undefined, modData?: DeepPartial<ModdedDex['data']>): ModdedDex {
if (!mod) return dexes['base'];
const modid = toID(mod);
if (modData?.Types && !modData.TypeChart) modData.TypeChart = modData.Types;
if (modData?.Species && !modData.Pokedex) modData.Pokedex = modData.Species;
const dex = (modid in dexes) && !modData ? dexes[modid] : new ModdedDex(modid);
dex.loadData(modData);
return dex;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.