diff --git a/sim/team-validator.ts b/sim/team-validator.ts index f36866b52c..12c5d87c2b 100644 --- a/sim/team-validator.ts +++ b/sim/team-validator.ts @@ -340,6 +340,24 @@ export class TeamValidator { return problems; } + getEventOnlyData(species: Species, noRecurse?: boolean): {species: Species, eventData: EventInfo[]} | null { + const dex = this.dex; + const learnset = dex.species.getLearnsetData(species.id); + if (!learnset?.eventOnly) { + if (noRecurse) return null; + return this.getEventOnlyData(dex.species.get(species.prevo), true); + } + + if (!learnset.eventData && species.forme) { + return this.getEventOnlyData(dex.species.get(species.baseSpecies), true); + } + if (!learnset.eventData) { + throw new Error(`Event-only species ${species.name} has no eventData table`); + } + + return {species, eventData: learnset.eventData}; + } + validateSet(set: PokemonSet, teamHas: AnyObject): string[] | null { const format = this.format; const dex = this.dex; @@ -598,6 +616,7 @@ export class TeamValidator { } const learnsetSpecies = dex.species.getLearnsetData(outOfBattleSpecies.id); + let eventOnlyData; if (!setSources.sourcesBefore && setSources.sources.length) { let legal = false; @@ -629,13 +648,8 @@ export class TeamValidator { if (eventProblems) problems.push(...eventProblems); } } - } else if (ruleTable.has('obtainablemisc') && learnsetSpecies.eventOnly) { - const eventSpecies = !learnsetSpecies.eventData && - outOfBattleSpecies.baseSpecies !== outOfBattleSpecies.name ? - dex.species.get(outOfBattleSpecies.baseSpecies) : outOfBattleSpecies; - const eventData = learnsetSpecies.eventData || - dex.species.getLearnsetData(eventSpecies.id).eventData; - if (!eventData) throw new Error(`Event-only species ${species.name} has no eventData table`); + } else if (ruleTable.has('obtainablemisc') && (eventOnlyData = this.getEventOnlyData(outOfBattleSpecies))) { + const {species: eventSpecies, eventData} = eventOnlyData; let legal = false; for (const event of eventData) { if (this.validateEvent(set, event, eventSpecies)) continue; diff --git a/test/sim/team-validator.js b/test/sim/team-validator.js index 555d263bbc..62a561387a 100644 --- a/test/sim/team-validator.js +++ b/test/sim/team-validator.js @@ -651,7 +651,7 @@ describe('Team Validator', function () { assert(illegal); }); - it.skip('should not allow evolutions of Shiny-locked events to be Shiny', function () { + it('should not allow evolutions of Shiny-locked events to be Shiny', function () { const team = [ {species: 'urshifu', ability: 'unseenfist', shiny: true, moves: ['snore'], evs: {hp: 1}}, {species: 'cosmoem', ability: 'sturdy', shiny: true, moves: ['teleport'], evs: {hp: 1}},