');
- if (selfR.me.side) {
- selfR.controlsElem.html('
');
- }
- if (selfR.joinElem) {
- selfR.joinElem.remove();
- }
- } else if (selfR.battle.mySide.initialized && selfR.battle.yourSide.initialized) {
- if (selfR.joinElem) {
- selfR.joinElem.remove();
- }
- selfR.joinElem = null;
- } else if (selfR.me.side) {
- if (selfR.joinElem) {
- selfR.joinElem.remove();
- }
- selfR.joinElem = null;
- if (selfR.battle.kickingInactive) {
- selfR.controlsElem.html('
← Your opponent has disconnected. Click this to delay your victory.
');
- } else {
- selfR.controlsElem.html('
← Your opponent has disconnected. Click this if they don\'t reconnect.
');
- }
- } else {
- if (selfR.joinElem) {
- selfR.joinElem.remove();
- }
- selfR.battleElem.append('');
- selfR.joinElem = selfR.battleElem.children().last();
- }
- },
- // Same as send, but appends the rqid to the message so that the server
- // can verify that the decision is sent in response to the correct request.
- sendDecision: function(message) {
- this.send(message + '|' + this.me.request.rqid);
- },
- request: null,
- receiveRequest: function(request) {
- this.request = request; // currently unused
- request.requestType = 'move';
- var notifyObject = null;
- if (request.forceSwitch) {
- request.requestType = 'switch';
- notifyObject = {
- type: 'yourSwitch',
- room: selfR.id
- };
- } else if (request.teamPreview) {
- request.requestType = 'team';
- notifyObject = {
- type: 'yourSwitch',
- room: selfR.id
- };
- } else if (request.wait) {
- request.requestType = 'wait';
- } else {
- notifyObject = {
- type: 'yourMove',
- room: selfR.id
- };
- }
- // if (notifyObject) {
- // var doNotify = function() {
- // notify(notifyObject);
- // selfR.notifying = true;
- // updateRoomList();
- // };
- // if (selfR.battle.yourSide.initialized) {
- // // The opponent's name is already known.
- // notifyObject.user = selfR.battle.yourSide.name;
- // doNotify();
- // } else {
- // // The opponent's name isn't known yet, so wait until it is
- // // known before sending the notification, so that it can include
- // // the opponent's name.
- // var callback = selfR.battle.stagnateCallback;
- // selfR.battle.stagnateCallback = function(battle) {
- // notifyObject.user = battle.yourSide.name;
- // doNotify();
- // battle.stagnateCallback = callback;
- // if (callback) callback(battle);
- // };
- // }
- // }
- },
- updateSide: function(sideData, midBattle) {
- var sidesSwitched = false;
- selfR.me.sideData = sideData; // just for easy debugging
- if (selfR.battle.sidesSwitched !== !!(selfR.me.side === 'p2')) {
- sidesSwitched = true;
- selfR.battle.reset();
- selfR.battle.switchSides();
- }
- for (var i = 0; i < sideData.pokemon.length; i++) {
- var pokemonData = sideData.pokemon[i];
- var pokemon;
- if (i == 0) {
- pokemon = selfR.battle.getPokemon(''+pokemonData.ident, pokemonData.details);
- pokemon.slot = 0;
- pokemon.side.pokemon = [pokemon];
- // if (pokemon.side.active[0] && pokemon.side.active[0].ident == pokemon.ident) pokemon.side.active[0] = pokemon;
- } else if (i < selfR.battle.mySide.active.length) {
- pokemon = selfR.battle.getPokemon('new: '+pokemonData.ident, pokemonData.details);
- pokemon.slot = i;
- // if (pokemon.side.active[i] && pokemon.side.active[i].ident == pokemon.ident) pokemon.side.active[i] = pokemon;
- if (pokemon.side.active[i] && pokemon.side.active[i].ident == pokemon.ident) {
- pokemon.side.active[i].item = pokemon.item;
- pokemon.side.active[i].ability = pokemon.ability;
- pokemon.side.active[i].baseAbility = pokemon.baseAbility;
- }
- } else {
- pokemon = selfR.battle.getPokemon('new: '+pokemonData.ident, pokemonData.details);
- }
- pokemon.healthParse(pokemonData.condition);
- if (pokemonData.baseAbility) {
- pokemon.baseAbility = pokemonData.baseAbility;
- if (!pokemon.ability) pokemon.ability = pokemon.baseAbility;
- }
- pokemon.item = pokemonData.item;
- pokemon.moves = pokemonData.moves;
- }
- selfR.battle.mySide.updateSidebar();
- if (sidesSwitched) {
- if (midBattle) {
- selfR.battle.fastForwardTo(-1);
- } else {
- selfR.battle.play();
- }
- }
- },
- callback: function (battle, type, moveTarget) {
- if (!battle) battle = selfR.battle;
- selfR.notifying = false;
- if (type === 'restart') {
- selfR.me.callbackWaiting = false;
- selfR.battleEnded = true;
- updateRoomList();
+
+ if (this.battle.playbackState === 5) {
+
+ // battle is seeking
+ this.$controls.html('');
return;
- } else if (type === 'trapped') {
+
+ } else if (this.battle.playbackState === 2) {
+
+ // battle is playing
+ this.$controls.html('');
+ return;
+
+ }
+
+ // tooltips
+ var myActive = this.battle.mySide.active;
+ var yourActive = this.battle.yourSide.active;
+ var buf = '';
+ if (yourActive[1]) {
+ buf += '';
+ }
+ if (yourActive[0]) {
+ buf += '';
+ }
+ if (myActive[0]) {
+ buf += '';
+ }
+ if (myActive[1]) {
+ buf += '';
+ }
+ this.$foeHint.html(buf);
+
+ if (this.battle.done) {
+
+ // battle has ended
+ this.$controls.html('
');
+
+ } else if (this.side) {
+
+ // player
+ this.updateControlsForPlayer()
+
+ } else if (this.battle.mySide.initialized && this.battle.yourSide.initialized) {
+
+ // full battle
+ this.$controls.html('Waiting for players...');
+
+ } else {
+
+ // empty battle
+ this.$join = $('');
+ this.$battle.append(this.$join);
+
+ }
+ },
+ updateControlsForPlayer: function() {
+ if (!this.request) {
+ if (this.battle.kickingInactive) {
+ this.$controls.html('
← Your opponent has disconnected. Click this to delay your victory.
');
+ } else {
+ this.$controls.html('
← Your opponent has disconnected. Click this if they don\'t reconnect.
');
+ }
+ }
+
+ var battle = this.battle;
+ // this.notifying = false;
+
+ if (!this.choice) {
+ this.updateSide(this.request.side);
+ }
+
+ // updated trappedness
+ if (false && 'trapped') {
var idx = parseInt(moveTarget[1], 10); // moveTarget is a poor name now...
- if (selfR.me.request && selfR.me.request.active &&
- selfR.me.request.active[idx]) {
+ if (this.request && this.request.active &&
+ this.request.active[idx]) {
// This pokemon is now known to be trapped.
- selfR.me.request.active[idx].trapped = true;
+ this.request.active[idx].trapped = true;
// TODO: Maybe a more sophisticated UI for this.
// In singles, this isn't really necessary because the switch UI will be
// immediately disabled. However, in doubles it might not be obvious why
// the player is being asked to make a new decision without this message.
- selfR.battle.add(selfR.battle.mySide.active[idx].getName() + ' is trapped!');
+ this.battle.add(this.battle.mySide.active[idx].getName() + ' is trapped!');
}
}
- var myActive = selfR.battle.mySide.active;
- var yourActive = selfR.battle.yourSide.active;
- var text = '';
- if (yourActive[1]) {
- text += '';
- }
- if (yourActive[0]) {
- text += '';
- }
- if (myActive[0]) {
- text += '';
- }
- if (myActive[1]) {
- text += '';
- }
- selfR.foeHintElem.html(text);
-
- if (!selfR.me.request) {
- selfR.controlsElem.html('
Waiting for players...
');
- selfR.updateJoinButton();
- updateRoomList();
- return;
- }
- if (selfR.me.request.side) {
- selfR.updateSide(selfR.me.request.side, true);
- }
- selfR.me.callbackWaiting = true;
- var active = selfR.battle.mySide.active[0];
+ this.callbackWaiting = true;
+ var active = this.battle.mySide.active[0];
if (!active) active = {};
- if (selfR.battle.kickingInactive) {
- selfR.controlsElem.html('
Waiting for opponent...
');
- } else {
- selfR.controlsElem.html('
Waiting for opponent...
');
- }
+
var act = '';
var switchables = [];
-
- if (selfR.me.request) {
- act = selfR.me.request.requestType;
- if (selfR.me.request.side) {
- switchables = selfR.battle.mySide.pokemon;
+ if (this.request) {
+ act = this.request.requestType;
+ if (this.request.side) {
+ switchables = this.battle.mySide.pokemon;
}
}
+
+ var type = '';
+ var moveTarget = '';
+ if (this.choice) {
+ type = this.choice.type;
+ moveTarget = this.choice.moveTarget;
+ if (this.choice.waiting) act = '';
+ }
+ // The choice object:
+ // !this.choice = nothing has been chosen
+ // this.choice.choices = array of choice strings
+ // this.choice.switchFlags = dict of pokemon indexes that have a switch pending
+
switch (act) {
case 'move':
{
- if (type !== 'move2' && type !== 'movetarget') {
- selfR.choices = [];
- selfR.choiceSwitchFlags = {};
- while (switchables[selfR.choices.length] && switchables[selfR.choices.length].fainted) selfR.choices.push('pass');
- }
- var pos = selfR.choices.length - (type === 'movetarget'?1:0);
- var hpbar = '';
- {
- if (switchables[pos].hp * 5 / switchables[pos].maxhp < 1) {
- hpbar = '';
- } else if (switchables[pos].hp * 2 / switchables[pos].maxhp < 1) {
- hpbar = '';
- } else {
- hpbar = '';
+ if (!this.choice) {
+ this.choice = {
+ choices: [],
+ switchFlags: {}
+ }
+ while (switchables[this.choice.choices.length] && switchables[this.choice.choices.length].fainted) {
+ this.choice.choices.push('pass');
}
- hpbar += ''+switchables[pos].hp+'/'+switchables[pos].maxhp+'';
}
- var active = selfR.me.request;
+ var pos = this.choice.choices.length - (type === 'movetarget'?1:0);
+
+ // hp bar
+ var hpbar = '';
+ if (switchables[pos].hp * 5 / switchables[pos].maxhp < 1) {
+ hpbar = '';
+ } else if (switchables[pos].hp * 2 / switchables[pos].maxhp < 1) {
+ hpbar = '';
+ } else {
+ hpbar = '';
+ }
+ hpbar += ''+switchables[pos].hp+'/'+switchables[pos].maxhp+'';
+
+ var active = this.request;
if (active.active) active = active.active[pos];
var moves = active.moves;
var trapped = active.trapped;
- selfR.me.finalDecision = active.maybeTrapped || false;
- if (selfR.me.finalDecision) {
- for (var i = pos + 1; i < selfR.battle.mySide.active.length; ++i) {
- var p = selfR.battle.mySide.active[i];
+ this.finalDecision = active.maybeTrapped || false;
+ if (this.finalDecision) {
+ for (var i = pos + 1; i < this.battle.mySide.active.length; ++i) {
+ var p = this.battle.mySide.active[i];
if (p && !p.fainted) {
- selfR.me.finalDecision = false;
+ this.finalDecision = false;
}
}
}
var controls = '
';
+ break;
+ case 'pokemon':
+ var pokemon = curRoom.battle.getPokemon(thing);
+ if (!pokemon) return;
+ //fallthrough
+ case 'sidepokemon':
+ if (!pokemon) pokemon = curRoom.battle.mySide.pokemon[parseInt(thing)];
+ text = '
';
+ text += '
' + pokemon.getFullName() + (pokemon.level !== 100 ? ' L' + pokemon.level + '' : '') + ' ';
+
+ var types = pokemon.types;
+ var template = pokemon;
+ if (pokemon.volatiles.transform && pokemon.volatiles.formechange) {
+ template = Tools.getTemplate(pokemon.volatiles.formechange[2]);
+ types = template.types;
+ text += '(Transformed into '+pokemon.volatiles.formechange[2]+') ';
+ } else if (pokemon.volatiles.formechange) {
+ template = Tools.getTemplate(pokemon.volatiles.formechange[2]);
+ types = template.types;
+ text += '(Forme: '+pokemon.volatiles.formechange[2]+') ';
+ }
+ if (pokemon.volatiles.typechange) {
+ text += '(Type changed) ';
+ types = [pokemon.volatiles.typechange[2]];
+ }
+ text += Tools.getTypeIcon(types[0]);
+ if (types[1]) {
+ text += ' '+Tools.getTypeIcon(types[1]);
+ }
+ text += '
';
+ var exacthp = '';
+ if (pokemon.maxhp != 100 && pokemon.maxhp != 1000 && pokemon.maxhp != 48) exacthp = ' ('+pokemon.hp+'/'+pokemon.maxhp+')';
+ if (pokemon.maxhp == 48 && isActive) exacthp = ' ('+pokemon.hp+'/'+pokemon.maxhp+' pixels)';
+ text += '
';
+ if (!pokemon.baseAbility && !pokemon.ability) {
+ text += '
Possible abilities: ' + Tools.getAbility(template.abilities['0']).name;
+ if (template.abilities['1']) text += ', ' + Tools.getAbility(template.abilities['1']).name;
+ if (template.abilities['DW']) text += ', ' + Tools.getAbility(template.abilities['DW']).name;
+ text += '