FIx crash with Force Monotype (#9467)

This commit is contained in:
Kris Johnson 2023-03-14 17:44:50 -06:00 committed by GitHub
parent f1a252295a
commit efb0433dbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -441,13 +441,21 @@ export const Rulesets: {[k: string]: FormatData} = {
desc: `Forces all teams to have the same type. Usage: Force Monotype = [Type], e.g. "Force Monotype = Water"`,
hasValue: true,
onValidateRule(value) {
if (!this.dex.types.get(value).exists) throw new Error(`Misspelled type "${value}"`);
const type = this.dex.types.get(value);
if (!type.exists) throw new Error(`Misspelled type "${value}"`);
// Temporary hardcode until types support generations
if (
(['Dark', 'Steel'].includes(type.name) && this.dex.gen < 2) ||
(type.name === 'Fairy' && this.dex.gen < 6)
) {
throw new Error(`Invalid type "${type.name}" in Generation ${this.dex.gen}`);
}
},
onValidateSet(set) {
const species = this.dex.species.get(set.species);
const type = this.dex.types.get(this.ruleTable.valueRules.get('forcemonotype')!);
if (!species.types.map(this.toID).includes(type.id)) {
return [`${set.species} must have type ${type.name}`];
return [`${set.species} must have ${type.name} type.`];
}
},
},