Skip to content

Commit

Permalink
Implement EV Limits rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed May 6, 2021
1 parent dff797c commit 32a88d8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions data/rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,45 @@ export const Rulesets: {[k: string]: FormatData} = {
}
},
},
evlimits: {
effectType: 'ValidatorRule',
name: 'EV Limits',
desc: "Require EVs to be in specific ranges, such as: \"EV Limits = Atk 0-124 / Def 100-252\"",
hasValue: true,
onValidateRule(value) {
if (!value) throw new Error(`To remove EV limits, use "! EV Limits"`);

const slashedParts = value.split('/');
const UINT_REGEX = /^[0-9]{1,4}$/;
return slashedParts.map(slashedPart => {
const parts = slashedPart.replace('-', ' - ').replace(/ +/g, ' ').trim().split(' ');
const [stat, low, hyphen, high] = parts;
if (parts.length !== 4 || !UINT_REGEX.test(low) || hyphen !== '-' || !UINT_REGEX.test(high)) {
throw new Error(`EV limits should be in the format "EV Limits = Atk 0-124 / Def 100-252"`);
}
const statid = toID(stat) as StatID;
if (!this.dex.stats.ids().includes(statid)) {
throw new Error(`Unrecognized stat name "${stat}" in "${value}"`);
}
return `${statid} ${low}-${high}`;
}).join(' / ');
},
onValidateSet(set) {
const limits = this.ruleTable.valueRules.get('evlimits')!;
const problems = [];

for (const limit of limits.split(' / ')) {
const [statid, range] = limit.split(' ') as [StatID, string];
const [low, high] = range.split('-').map(num => parseInt(num));
const ev = set.evs[statid];

if (ev < low || ev > high) {
problems.push(`${set.name || set.species}'s ${this.dex.stats.names[statid]} EV (${ev}) must be ${low}-${high}`);
}
}
return problems;
},
},
teampreview: {
effectType: 'Rule',
name: 'Team Preview',
Expand Down

0 comments on commit 32a88d8

Please sign in to comment.