2015-07-18 17:57:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
(function(){
|
|
|
|
|
angular
|
|
|
|
|
.module('habitrpg')
|
|
|
|
|
.factory('Stats', statsFactory);
|
|
|
|
|
|
|
|
|
|
statsFactory.$inject = [
|
|
|
|
|
'Content',
|
|
|
|
|
'Shared'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function statsFactory(Content, Shared) {
|
|
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
function classBonus(user, stat) {
|
|
|
|
|
var computedStats = user._statsComputed;
|
2015-07-18 18:12:11 +00:00
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
if(computedStats) {
|
|
|
|
|
var bonus = computedStats[stat]
|
|
|
|
|
- user.stats.buffs[stat]
|
|
|
|
|
- levelBonus(user.stats.lvl)
|
|
|
|
|
- equipmentStatBonus(stat, user.items.gear.equipped)
|
|
|
|
|
- user.stats[stat];
|
2015-07-18 18:12:11 +00:00
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
return bonus;
|
|
|
|
|
}
|
2015-07-18 19:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
function equipmentStatBonus(stat, equipped) {
|
|
|
|
|
var gear = Content.gear.flat;
|
|
|
|
|
var total = 0;
|
2015-07-18 19:08:25 +00:00
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
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;
|
2015-07-18 19:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-18 19:50:02 +00:00
|
|
|
function expDisplay(user) {
|
|
|
|
|
var exp = Math.floor(user.stats.exp);
|
|
|
|
|
var toNextLevel = Shared.tnl(user.stats.lvl);
|
2015-07-18 19:53:14 +00:00
|
|
|
var display = _formatOutOfTotalDisplay(exp, toNextLevel);
|
2015-07-18 19:50:02 +00:00
|
|
|
|
|
|
|
|
return display;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
function goldDisplay(gold) {
|
|
|
|
|
var display = Math.floor(gold);
|
|
|
|
|
return display;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hpDisplay(hp) {
|
|
|
|
|
var remainingHP = Math.ceil(hp);
|
|
|
|
|
var totalHP = Shared.maxHealth;
|
|
|
|
|
var display = _formatOutOfTotalDisplay(remainingHP, totalHP);
|
|
|
|
|
|
|
|
|
|
return display;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 17:57:54 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
var levelOrMaxLevel = Math.min((level - 1), Shared.maxLevel);
|
|
|
|
|
var levelDividedByTwo = levelOrMaxLevel / 2;
|
|
|
|
|
var bonus = Math.ceil(levelDividedByTwo );
|
|
|
|
|
|
|
|
|
|
return bonus;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
function mpDisplay(user) {
|
|
|
|
|
var remainingMP = Math.floor(user.stats.mp);
|
|
|
|
|
var totalMP = user._statsComputed.maxMP;
|
|
|
|
|
var display = _formatOutOfTotalDisplay(remainingMP, totalMP);
|
2015-07-18 17:57:54 +00:00
|
|
|
|
2015-07-20 01:19:16 +00:00
|
|
|
return display;
|
2015-07-18 17:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-20 01:40:15 +00:00
|
|
|
function totalPetCount(pets) {
|
|
|
|
|
var total = _.size(pets);
|
|
|
|
|
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function totalMountCount(mounts) {
|
|
|
|
|
var total = _.size(mounts);
|
|
|
|
|
|
|
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 19:53:14 +00:00
|
|
|
function _formatOutOfTotalDisplay(stat, totalStat) {
|
|
|
|
|
var display = stat + "/" + totalStat;
|
|
|
|
|
return display;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 17:57:54 +00:00
|
|
|
return {
|
|
|
|
|
classBonus: classBonus,
|
|
|
|
|
equipmentStatBonus: equipmentStatBonus,
|
2015-07-18 19:50:02 +00:00
|
|
|
expDisplay: expDisplay,
|
2015-07-18 19:29:40 +00:00
|
|
|
goldDisplay: goldDisplay,
|
2015-07-18 18:12:11 +00:00
|
|
|
hpDisplay: hpDisplay,
|
2015-07-18 19:08:25 +00:00
|
|
|
levelBonus: levelBonus,
|
2015-07-20 01:40:15 +00:00
|
|
|
mpDisplay: mpDisplay,
|
|
|
|
|
totalPetCount: totalPetCount,
|
|
|
|
|
totalMountCount: totalMountCount
|
2015-07-18 17:57:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}());
|