Allow passing teams to random formats

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
This commit is contained in:
Guangcong Luo 2021-03-29 01:28:32 -07:00
parent d18c0a4e1f
commit d4b6ba4c0f
3 changed files with 16 additions and 4 deletions

View File

@ -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.`,
];
}

View File

@ -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();

View File

@ -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];