pokemon-showdown/sim/index.js
Guangcong Luo 22186f1903 Improve TypeScript typing
sim/dex.js and sim/prng.js are now valid strict TypeScript! Also they
have slightly less "any" use than before.
2017-05-08 02:58:55 -05:00

45 lines
1.1 KiB
JavaScript

/**
* Simulator process
* Pokemon Showdown - http://pokemonshowdown.com/
*
* This file is where the battle simulation itself happens.
*
* The most important part of the simulation happens in runEvent -
* see that function's definition for details.
*
* @license MIT license
*/
'use strict';
const Dex = require('./dex');
global.toId = Dex.getId;
const PRNG = require('./prng');
const Battle = require('./battle');
const Side = require('./side');
const Pokemon = require('./pokemon');
let battleProtoCache = new Map();
exports.construct = function (format, rated, send, prng) {
format = Dex.getFormat(format);
const mod = format.mod || 'base';
if (!battleProtoCache.has(mod)) {
// Scripts overrides Battle overrides Dex
const dex = Dex.mod(mod);
const proto = Object.create(Battle.prototype);
Object.assign(proto, dex);
for (let i in dex.data.Scripts) {
proto[i] = dex.data.Scripts[i];
}
battleProtoCache.set(mod, proto);
}
const battle = Object.create(battleProtoCache.get(mod));
Battle.prototype.init.call(battle, format, rated, send, prng);
return battle;
};
exports.Pokemon = Pokemon;
exports.Side = Side;
exports.Battle = Battle;