Second Pass at cleaning up the code. These are pretty safe edits that include adding 0 to decimal values, fixing variables that are declared multiple times, and removing duplicate keys

This commit is contained in:
Tyler Stark 2014-02-09 23:26:44 -06:00
parent b6f63bdd22
commit bff353cc58
11 changed files with 36 additions and 29 deletions

2
app.js
View File

@ -226,7 +226,7 @@ global.ResourceMonitor = {
else if (typeof value === 'number') bytes += 8;
else if (typeof value === 'object' && objectList.indexOf( value ) === -1) {
objectList.push( value );
for (i in value) stack.push( value[ i ] );
for (var i in value) stack.push( value[ i ] );
}
}

View File

@ -1046,6 +1046,7 @@ var BattlePokemon = (function() {
return this.battle.getNature(this.set.nature);
};
BattlePokemon.prototype.addVolatile = function(status, source, sourceEffect) {
var result;
if (!this.hp) return false;
status = this.battle.getEffect(status);
if (this.battle.event) {
@ -1058,7 +1059,7 @@ var BattlePokemon = (function() {
return this.battle.singleEvent('Restart', status, this.volatiles[status.id], this, source, sourceEffect);
}
if (!this.runImmunity(status.id)) return false;
var result = this.battle.runEvent('TryAddVolatile', this, source, sourceEffect, status);
result = this.battle.runEvent('TryAddVolatile', this, source, sourceEffect, status);
if (!result) {
this.battle.debug('add volatile ['+status.id+'] interrupted');
return result;
@ -1078,7 +1079,7 @@ var BattlePokemon = (function() {
if (status.durationCallback) {
this.volatiles[status.id].duration = status.durationCallback.call(this.battle, this, source, sourceEffect);
}
var result = this.battle.singleEvent('Start', status, this.volatiles[status.id], this, source, sourceEffect);
result = this.battle.singleEvent('Start', status, this.volatiles[status.id], this, source, sourceEffect);
if (!result) {
// cancel
delete this.volatiles[status.id];
@ -3205,6 +3206,8 @@ var Battle = (function() {
return false;
};
Battle.prototype.runDecision = function(decision) {
var pokemon;
// returns whether or not we ended in a callback
switch (decision.choice) {
case 'start':
@ -3220,11 +3223,11 @@ var Battle = (function() {
this.switchIn(this.p2.pokemon[pos], pos);
}
for (var pos=0; pos<this.p1.pokemon.length; pos++) {
var pokemon = this.p1.pokemon[pos];
pokemon = this.p1.pokemon[pos];
this.singleEvent('Start', this.getEffect(pokemon.species), pokemon.speciesData, pokemon);
}
for (var pos=0; pos<this.p2.pokemon.length; pos++) {
var pokemon = this.p2.pokemon[pos];
pokemon = this.p2.pokemon[pos];
this.singleEvent('Start', this.getEffect(pokemon.species), pokemon.speciesData, pokemon);
}
this.midTurn = true;
@ -3272,7 +3275,7 @@ var Battle = (function() {
}
if (i == 0) return;
var pokemon = decision.side.pokemon[i];
pokemon = decision.side.pokemon[i];
if (!pokemon) return;
decision.side.pokemon[i] = decision.side.pokemon[0];
decision.side.pokemon[0] = pokemon;

View File

@ -313,7 +313,7 @@ var commands = exports.commands = {
if (target === 'all') {
if (this.broadcasting) {
return this.sendReply('A search with the parameter "all" cannot be broadcast.')
return this.sendReply('A search with the parameter "all" cannot be broadcast.');
}
showAll = true;
continue;

View File

@ -23,7 +23,7 @@ module.exports = (function() {
lastCrashLog = datenow;
var transport;
try {
var transport = require('nodemailer').createTransport(
transport = require('nodemailer').createTransport(
config.crashguardemail.transport,
config.crashguardemail.options
);

View File

@ -736,7 +736,7 @@ exports.BattleFormatsData = {
tier: "Limbo C"
},
lickitung: {
viableMoves: {"wish":1,"protect":1,"dragontail":1,"curse":1,"bodyslam":1,"return":1,"powerwhip":1,"swordsdance":1,"earthquake":1,"toxic":1,"healbell":1,"earthquake":1},
viableMoves: {"wish":1,"protect":1,"dragontail":1,"curse":1,"bodyslam":1,"return":1,"powerwhip":1,"swordsdance":1,"earthquake":1,"toxic":1,"healbell":1},
eventPokemon: [
{"generation":3,"level":5,"moves":["healbell","wish"]},
{"generation":3,"level":38,"moves":["helpinghand","doubleedge","defensecurl","rollout"]}
@ -1319,7 +1319,7 @@ exports.BattleFormatsData = {
tier: "OU"
},
natu: {
viableMoves: {"thunderwave":1,"roost":1,"toxic":1,"reflect":1,"lightscreen":1,"uturn":1,"wish":1,"psychic":1,"nightshade":1,"uturn":1},
viableMoves: {"thunderwave":1,"roost":1,"toxic":1,"reflect":1,"lightscreen":1,"uturn":1,"wish":1,"psychic":1,"nightshade":1},
eventPokemon: [
{"generation":3,"level":22,"moves":["batonpass","futuresight","nightshade","aerialace"]}
],
@ -3591,7 +3591,7 @@ exports.BattleFormatsData = {
tier: "Limbo"
},
dwebble: {
viableMoves: {"stealthrock":1,"spikes":1,"shellsmash":1,"earthquake":1,"rockblast":1,"xscissor":1,"stoneedge":1.},
viableMoves: {"stealthrock":1,"spikes":1,"shellsmash":1,"earthquake":1,"rockblast":1,"xscissor":1,"stoneedge":1},
tier: "LC"
},
crustle: {

View File

@ -1835,7 +1835,7 @@ exports.BattleItems = {
pokemon.negateImmunity['Ground'] = true;
},
onModifySpe: function(speMod) {
return this.chain(speMod, .5);
return this.chain(speMod, 0.5);
},
num: 278,
gen: 4,

View File

@ -85,7 +85,7 @@ module.exports = (function() {
res.on('end', function() {
var data = null;
try {
var data = parseJSON(buffer);
data = parseJSON(buffer);
} catch (e) {}
callback(data, res.statusCode);
this.openRequests--;
@ -184,7 +184,7 @@ module.exports = (function() {
//console.log('RESPONSE: '+buffer);
var data = null;
try {
var data = parseJSON(buffer);
data = parseJSON(buffer);
} catch (e) {}
for (var i=0,len=requestCallbacks.length; i<len; i++) {
if (data) {

View File

@ -350,7 +350,7 @@ var GlobalRoom = (function() {
return true;
};
GlobalRoom.prototype.deregisterChatRoom = function(id) {
var id = toId(id);
id = toId(id);
var room = rooms[id];
if (!room) return false; // room doesn't exist
if (!room.chatRoomData) return false; // room isn't registered
@ -369,7 +369,7 @@ var GlobalRoom = (function() {
return true;
};
GlobalRoom.prototype.delistChatRoom = function(id) {
var id = toId(id);
id = toId(id);
if (!rooms[id]) return false; // room doesn't exist
for (var i=this.chatRooms.length-1; i>=0; i--) {
if (id === this.chatRooms[i].id) {
@ -379,7 +379,7 @@ var GlobalRoom = (function() {
}
};
GlobalRoom.prototype.removeChatRoom = function(id) {
var id = toId(id);
id = toId(id);
var room = rooms[id];
if (!room) return false; // room doesn't exist
room.destroy();
@ -620,13 +620,14 @@ var BattleRoom = (function() {
var oldacre = Math.round(data.p1rating.oldacre);
var acre = Math.round(data.p1rating.acre);
var reasons = ''+(acre-oldacre)+' for '+(p1score>.99?'winning':(p1score<.01?'losing':'tying'));
var reasons = ''+(acre-oldacre)+' for '+(p1score>0.99?'winning':(p1score<0.01?'losing':'tying'));
if (reasons.substr(0,1) !== '-') reasons = '+'+reasons;
self.addRaw(sanitize(p1)+'\'s rating: '+oldacre+' &rarr; <strong>'+acre+'</strong><br />('+reasons+')');
var oldacre = Math.round(data.p2rating.oldacre);
var acre = Math.round(data.p2rating.acre);
var reasons = ''+(acre-oldacre)+' for '+(p1score>.99?'losing':(p1score<.01?'winning':'tying'));
oldacre = Math.round(data.p2rating.oldacre);
acre = Math.round(data.p2rating.acre);
reasons = ''+(acre-oldacre)+' for '+(p1score>0.99?'losing':(p1score<0.01?'winning':'tying'));
reasons = ''+(acre-oldacre)+' for '+(p1score>0.99?'losing':(p1score<0.01?'winning':'tying'));
if (reasons.substr(0,1) !== '-') reasons = '+'+reasons;
self.addRaw(sanitize(p2)+'\'s rating: '+oldacre+' &rarr; <strong>'+acre+'</strong><br />('+reasons+')');
@ -1056,7 +1057,7 @@ var BattleRoom = (function() {
this.kickInactiveUpdate();
};
BattleRoom.prototype.joinBattle = function(user, team) {
var slot = undefined;
var slot;
if (this.rated) {
if (this.rated.p1 === user.userid) {
slot = 0;

View File

@ -137,6 +137,7 @@ var Simulator = (function(){
Simulator.prototype.rqid = '';
Simulator.prototype.inactiveQueued = false;
Simulator.prototype.receive = function(lines) {
var player;
ResourceMonitor.activeIp = this.activeIp;
switch (lines[1]) {
case 'update':
@ -159,14 +160,14 @@ var Simulator = (function(){
break;
case 'callback':
var player = this.getPlayer(lines[2]);
player = this.getPlayer(lines[2]);
if (player) {
player.sendTo(this.id, '|callback|' + lines[3]);
}
break;
case 'request':
var player = this.getPlayer(lines[2]);
player = this.getPlayer(lines[2]);
var rqid = lines[3];
if (player) {
this.requests[player.userid] = lines[4];

View File

@ -720,10 +720,11 @@ var Validator = (function() {
if (sourcesBefore || lsetData.sourcesBefore) {
// having sourcesBefore is the equivalent of having everything before that gen
// in sources, so we fill the other array in preparation for intersection
var learned;
if (sourcesBefore && lsetData.sources) {
if (!sources) sources = [];
for (var i=0, len=lsetData.sources.length; i<len; i++) {
var learned = lsetData.sources[i];
learned = lsetData.sources[i];
if (parseInt(learned.substr(0,1),10) <= sourcesBefore) {
sources.push(learned);
}
@ -733,7 +734,7 @@ var Validator = (function() {
if (lsetData.sourcesBefore && sources) {
if (!lsetData.sources) lsetData.sources = [];
for (var i=0, len=sources.length; i<len; i++) {
var learned = sources[i];
learned = sources[i];
if (parseInt(learned.substr(0,1),10) <= lsetData.sourcesBefore) {
lsetData.sources.push(learned);
}

View File

@ -467,17 +467,18 @@ module.exports = (function () {
banlistTable[subformat.banlist[i]] = subformat.name || true;
banlistTable[toId(subformat.banlist[i])] = subformat.name || true;
var plusPos = subformat.banlist[i].indexOf('+');
var plusPos = subformat.banlist[i].indexOf('+'),
complexList;
if (plusPos && plusPos > 0) {
var plusPlusPos = subformat.banlist[i].indexOf('++');
if (plusPlusPos && plusPlusPos > 0) {
var complexList = subformat.banlist[i].split('++');
complexList = subformat.banlist[i].split('++');
for (var j=0; j<complexList.length; j++) {
complexList[j] = toId(complexList[j]);
}
format.teamBanTable.push(complexList);
} else {
var complexList = subformat.banlist[i].split('+');
complexList = subformat.banlist[i].split('+');
for (var j=0; j<complexList.length; j++) {
complexList[j] = toId(complexList[j]);
}