Skip to content

Commit

Permalink
Allow passing teams to random formats
Browse files Browse the repository at this point in the history
The team validator will now complain if try to bring a team to a random
format. Also, if you bypass the validator (such as with
`/importinputlog` or using the JS API directly), you can now use custom
teams in random formats.

Fixes #8144
  • Loading branch information
Zarel committed Mar 29, 2021
1 parent d18c0a4 commit d4b6ba4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/team-validator-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const PM = new QueryProcessManager<{
team,
});
problems = [
`Your team crashed the validator. We'll fix this crash within a few minutes (we're automatically notified),` +
`Your team crashed the validator. We'll fix this crash within a few hours (we're automatically notified),` +
` but if you don't want to wait, just use a different team for now.`,
];
}
Expand Down
2 changes: 1 addition & 1 deletion sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2611,7 +2611,7 @@ export class Battle {
getTeam(options: PlayerOptions): PokemonSet[] {
let team = options.team;
if (typeof team === 'string') team = Dex.fastUnpackTeam(team);
if ((!this.format.team || this.deserialized) && team) return team;
if (team) return team;

if (!options.seed) {
options.seed = PRNG.generateSeed();
Expand Down
16 changes: 14 additions & 2 deletions sim/team-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,22 @@ export class TeamValidator {
let problems: string[] = [];
const ruleTable = this.ruleTable;
if (format.team) {
if (team) {
return [
`This format doesn't let you use your own team.`,
`If you're not using a custom client, please report this as a bug. If you are, remember to use \`/utm null\` before starting a game in this format.`,
];
}
return null;
}
if (!team || !Array.isArray(team)) {
return [`You sent invalid team data. If you're not using a custom client, please report this as a bug.`];
if (!team) {
return [
`This format requires you to use your own team.`,
`If you're not using a custom client, please report this as a bug.`,
];
}
if (!Array.isArray(team)) {
throw new Error(`Invalid team data`);
}

let [minSize, maxSize] = format.teamLength && format.teamLength.validate || [1, 6];
Expand Down

0 comments on commit d4b6ba4

Please sign in to comment.