Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Record effective damage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjsaylor committed Oct 15, 2013
1 parent 1ecea0a commit c0b6174
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/attack_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ module.exports = (function(){
}
damage = Math.ceil(damage);

return { enemyId : enemyId, damage : damage, position : position };
return {
enemyId: enemyId,
damage: damage,
effectiveDamage: damage > enemy.hp ? enemy.hp : damage,
position: position
};
};
return AttackMode;
}());
}());
3 changes: 2 additions & 1 deletion lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ var Game = (function() {
data = {
username: player.name(),
round: this.round,
kills: player.kills()
kills: player.kills(),
damage: player.effectiveDamage()
};
resultsCollection.insert(data, _.bind(function(err) {
callback(err, this);
Expand Down
27 changes: 22 additions & 5 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = (function() {
this._hp = _baseHP;
this._username = username;
this._attack_mode = config.defaultAttackMode;
this._kills = 0;
this._kills = this._damage = 0;
}

/**
Expand All @@ -35,10 +35,17 @@ module.exports = (function() {
*
* @param Enemy enemy
* @param Array collections [EnemyCollection, ...]
* @return Number
* @return array
*/
Player.prototype.attackEnemy = function(enemy, collections) {
return Player.attack_modes[this._attack_mode].attack(enemy._id, collections);
var attacks;
// Record effective damage
attacks = Player.attack_modes[this._attack_mode].attack(enemy._id, collections);
this._damage += _.reduce(attacks, function(memo, attack) {
return memo + attack.effectiveDamage;
}, 0);

return attacks;
};

/**
Expand Down Expand Up @@ -92,10 +99,19 @@ module.exports = (function() {
}
};

/**
* Get the amount of effective damage the player has done.
*
* @return Number
*/
Player.prototype.effectiveDamage = function() {
return this._damage;
};

/**
* Returns the current attack mode's defense modifier.
*
* @return {[type]}
* @return Number
*/
Player.prototype.getDefenseMod = function(){
return Player.attack_modes[this._attack_mode].get('defenseMod');
Expand Down Expand Up @@ -139,7 +155,8 @@ module.exports = (function() {
return {
name: this._username,
health: this._hp,
kills: this._kills
kills: this._kills,
damage: this._damage
};
};

Expand Down

0 comments on commit c0b6174

Please sign in to comment.