Move stat calc scripts to angular service

This commit is contained in:
Blade Barringer
2015-07-18 12:57:54 -05:00
parent 3926a6e95a
commit f9304bd28f
6 changed files with 81 additions and 61 deletions
-2
View File
@@ -33,8 +33,6 @@ api.planGemLimits =
convRate: 20 #how much does a gem cost?
convCap: 25 #how many gems can be converted / month?
api.statCalc = require('./methods/statCalculations')
###
------------------------------------------------------
Time / Day
-53
View File
@@ -1,53 +0,0 @@
'use strict';
var Content = require('../content.coffee');
function levelBonus(level) {
// Level bonus is derived by taking the level, subtracting one,
// taking the smaller of it or maxLevel (100),
// dividing that by two and then raising it to a whole number
// TODO: 100 is a magic number, extract from script.index into own module and call here
var levelOrMaxLevel = Math.min((level - 1), 100)
var levelDividedByTwo = levelOrMaxLevel / 2
var statBonus = Math.ceil(levelDividedByTwo )
return statBonus;
}
function equipmentStatBonus(stat, equipped) {
var gear = Content.gear.flat;
var total = 0;
var equipmentTypes = ['weapon', 'armor', 'head', 'shield'];
_(equipmentTypes).each(function(type) {
var equippedItem = equipped[type]
if(gear[equippedItem]) {
var equipmentStat = gear[equippedItem][stat];
total += equipmentStat;
}
});
return total;
}
function classBonus(user, stat) {
var computedStats = user._statsComputed;
if(computedStats) {
var bonus = computedStats[stat]
- user.stats.buffs[stat]
- levelBonus(user.stats.lvl)
- equipmentStatBonus(stat, user.items.gear.equipped)
- user.stats[stat]
return bonus;
}
}
module.exports = {
classBonus: classBonus,
equipmentStatBonus: equipmentStatBonus,
levelBonus: levelBonus
}