diff --git a/battles.js b/battles.js index c165478775..6173482c02 100644 --- a/battles.js +++ b/battles.js @@ -130,6 +130,13 @@ var BattlePokemon = (function() { this.battle = side.battle; if (typeof set === 'string') set = {name: set}; + // "prebound" function for nicer syntax (avoids use of `bind`) + this.getHealth = (function(self) { + return function(side) { + return BattlePokemon.getHealth.call(self, side); + }; + })(this); + this.set = set; this.baseTemplate = this.battle.getTemplate(set.species || set.name); @@ -284,9 +291,10 @@ var BattlePokemon = (function() { if (this.isActive) return fullname.substr(0,2) + positionList[this.position] + fullname.substr(2); return fullname; }; - BattlePokemon.prototype.getDetails = function() { - if (this.illusion) return this.illusion.details + '|' + this.getHealth(); - return this.details + '|' + this.getHealth(); + // "static" function + BattlePokemon.getDetails = function(side) { + if (this.illusion) return this.illusion.details + '|' + this.getHealth(side); + return this.details + '|' + this.getHealth(side); }; BattlePokemon.prototype.update = function(init) { // reset for Light Metal etc @@ -921,19 +929,11 @@ var BattlePokemon = (function() { this.update(); return true; }; - BattlePokemon.prototype.getHealth = function(realHp) { - if (!realHp) { - for (var i in this.battle.sides) { - if (this.battle.sides[i] === this.side) { - this.battle.sides[i].exactHealth.push(''+this.hp+'/'+this.maxhp+' '+this.status); - } else { - this.battle.sides[i].exactHealth.push(''); - } - } - } + // "static" function + BattlePokemon.getHealth = function(side) { if (!this.hp) return '0 fnt'; var hpstring; - if (realHp || this.battle.getFormat().debug) { + if ((this.side === side) || this.battle.getFormat().debug) { hpstring = ''+this.hp+'/'+this.maxhp; } else { var ratio = this.hp / this.maxhp; @@ -991,9 +991,6 @@ var BattleSide = (function() { this.active = [null]; this.sideConditions = {}; - // stores exact health for use in the health queue - this.exactHealth = []; - this.id = (n?'p2':'p1'); switch (this.battle.gameType) { @@ -1024,16 +1021,14 @@ var BattleSide = (function() { BattleSide.prototype.getData = function() { var data = { name: this.name, - pokemon: [], - exactHealth: this.exactHealth.join(',') + pokemon: [] }; - this.exactHealth = []; for (var i=0; i