-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd4b004
commit 9e3e9c1
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {PRNG} from "../sim/prng"; | ||
import {deepClone} from "../lib/utils"; | ||
|
||
interface DraftPokemonSet extends Partial<PokemonSet> { | ||
teraCaptain?: boolean; | ||
} | ||
|
||
const sampleData: [DraftPokemonSet[], DraftPokemonSet[]][] = [ | ||
[ | ||
[ | ||
{ | ||
name: 'Fred', | ||
species: 'Furret', | ||
item: 'Choice Scarf', | ||
ability: 'Frisk', | ||
moves: ['trick', 'doubleedge', 'knockoff', 'uturn'], | ||
nature: 'Jolly', | ||
evs: {hp: 8, atk: 252, def: 0, spa: 0, spd: 0, spe: 252}, | ||
teraCaptain: true, | ||
teraType: 'Normal', | ||
}, | ||
], | ||
[ | ||
{ | ||
species: 'Ampharos', | ||
item: 'Choice Specs', | ||
ability: 'Static', | ||
moves: ['dazzlinggleam', 'thunderbolt', 'focusblast', 'voltswitch'], | ||
nature: 'Modest', | ||
evs: {hp: 248, atk: 0, def: 8, spa: 252, spd: 0, spe: 0}, | ||
}, | ||
], | ||
], | ||
]; | ||
|
||
export default class DraftFactory { | ||
dex: ModdedDex; | ||
format: Format; | ||
prng: PRNG; | ||
matchup?: [DraftPokemonSet[], DraftPokemonSet[]]; | ||
playerIndex: number; | ||
swapTeams: boolean; | ||
constructor(format: Format | string, seed: PRNG | PRNGSeed | null) { | ||
this.dex = Dex.forFormat(format); | ||
this.format = Dex.formats.get(format); | ||
this.prng = seed instanceof PRNG ? seed : new PRNG(seed); | ||
this.playerIndex = 0; | ||
this.swapTeams = this.prng.randomChance(1, 2); | ||
} | ||
|
||
setSeed(seed: PRNGSeed) { | ||
this.prng.seed = seed; | ||
} | ||
|
||
getTeam(options?: PlayerOptions | null): PokemonSet[] { | ||
if (this.playerIndex > 1) throw new Error("Can't generate more than 2 teams"); | ||
|
||
if (!this.matchup) { | ||
this.matchup = deepClone(sampleData[this.prng.next(sampleData.length)]); | ||
if (this.swapTeams) this.matchup!.push(this.matchup!.shift()!); | ||
} | ||
|
||
const team: PokemonSet[] = this.matchup![this.playerIndex] as PokemonSet[]; | ||
|
||
this.playerIndex++; | ||
return team; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const assert = require('../assert'); | ||
const common = require('../common'); | ||
const DraftFactory = require('../../dist/data/draft-factory').default; | ||
|
||
let battle; | ||
|
||
describe.only('Draft Factory', () => { | ||
afterEach(() => battle.destroy()); | ||
|
||
it('should only allow the designated Tera Captains to Terastallize', () => { | ||
battle = common.createBattle({formatid: 'gen9draftfactory'}); | ||
// Manually create a team generator instance and rig it with data | ||
battle.teamGenerator = new DraftFactory(battle.format, null); | ||
battle.teamGenerator.swapTeams = false; | ||
battle.teamGenerator.matchup = [ | ||
[ | ||
{ | ||
species: 'Furret', | ||
ability: 'keeneye', | ||
moves: ['sleeptalk'], | ||
teraCaptain: true, | ||
teraType: 'Normal', | ||
}, | ||
{ | ||
species: 'Ampharos', | ||
ability: 'static', | ||
moves: ['sleeptalk'], | ||
}, | ||
], | ||
[ | ||
{ | ||
species: 'Nincada', | ||
ability: 'compoundeyes', | ||
moves: ['sleeptalk'], | ||
}, | ||
{ | ||
species: 'Marshtomp', | ||
ability: 'torrent', | ||
moves: ['sleeptalk'], | ||
teraCaptain: true, | ||
teraType: 'Fighting', | ||
}, | ||
], | ||
]; | ||
battle.setPlayer('p1', {}); | ||
battle.setPlayer('p2', {}); | ||
battle.makeChoices(); // team preview | ||
assert.throws(() => { battle.choose('p2', 'move 1 terastallize'); }, `${battle.p2.pokemon[0].name} should not be able to tera`); | ||
battle.makeChoices('move 1 terastallize', 'switch 2'); | ||
battle.makeChoices('auto', 'move 1 terastallize'); | ||
}); | ||
}); |