sim/battle.js
// This function is called by this process's 'message' event.
This function is called by this process's 'message' event.
This function is called by this process ' s ' message ' event .
receive(data, more) {
		this.messageLog.push(data.join(' '));
		let logPos = this.log.length;
		let alreadyEnded = this.ended;
		switch (data[1]) {
		case 'join': {
			let team;
			if (more) team = Dex.fastUnpackTeam(more);
			this.join(data[2], data[3], data[4], team);
			break;
		}
		case 'win':
		case 'tie':
			this.win(data[2]);
			break;
		case 'choose':
			this.choose(data[2], data[3]);
			break;
		case 'undo':
			this.undoChoice(data[2]);
			break;
		case 'eval': {
			let battle = this;
			let p1 = this.p1;
			let p2 = this.p2;
			let p1active = p1 ? p1.active[0] : null;
			let p2active = p2 ? p2.active[0] : null;
			let target = data.slice(2).join('|').replace(/\f/g, '\n');
			this.add('', '>>> ' + target);
			try {
				this.add('', '<<< ' + eval(target));
			} catch (e) {
				this.add('', '<<< error: ' + e.message);
			}
			break;
		}
		default:
		}
		this.sendUpdates(logPos, alreadyEnded);
	}
receive ( data , more ) { this . messageLog . push ( data . join ( ' ' ) ) ; let logPos = this . log . length ; let alreadyEnded = this . ended ; switch ( data [ 1 ] ) { case 'join' : { let team ; if ( more ) team = Dex . fastUnpackTeam ( more ) ; this . join ( data [ 2 ] , data [ 3 ] , data [ 4 ] , team ) ; break ; } case 'win' : case 'tie' : this . win ( data [ 2 ] ) ; break ; case 'choose' : this . choose ( data [ 2 ] , data [ 3 ] ) ; break ; case 'undo' : this . undoChoice ( data [ 2 ] ) ; break ; case 'eval' : { let battle = this ; let p1 = this . p1 ; let p2 = this . p2 ; let p1active = p1 ? p1 . active [ 0 ] : null ; let p2active = p2 ? p2 . active [ 0 ] : null ; let target = data . slice ( 2 ) . join ( '|' ) . replace ( / \f / g , '\n' ) ; this . add ( '' , '>>> ' + target ) ; try { this . add ( '' , '<<< ' + eval ( target ) ) ; } catch ( e ) { this . add ( '' , '<<< error: ' + e . message ) ; } break ; } default : } this . sendUpdates ( logPos , alreadyEnded ) ; }
This function is called by this process's 'message' event.
This function is called by this process ' s ' message ' event .
/* eslint-disable no-eval, no-unused-vars */ /* eslint-enable no-eval, no-unused-vars */ // unhandled