mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-05-19 04:08:44 +00:00
Organize stat functions alphabetically
This commit is contained in:
parent
a139ca8ba5
commit
89bfc83b95
2 changed files with 163 additions and 163 deletions
|
|
@ -15,122 +15,6 @@ describe('Stats Service', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('hpDisplay', function() {
|
||||
it('displays hp as "hp / totalHP"', function() {
|
||||
var hp = 34;
|
||||
var hpDisplay = statCalc.hpDisplay(hp);
|
||||
|
||||
expect(hpDisplay).to.eql('34/50');
|
||||
});
|
||||
|
||||
it('Rounds hp up when given a decimal', function() {
|
||||
|
||||
var hp = 34.4;
|
||||
var hpDisplay = statCalc.hpDisplay(hp);
|
||||
|
||||
expect(hpDisplay).to.eql('35/50');
|
||||
});
|
||||
});
|
||||
|
||||
describe('mpDisplay', function() {
|
||||
it('displays mp as "mp / totalMP"', function() {
|
||||
user._statsComputed = { maxMP: 100 };
|
||||
user.stats.mp = 30;
|
||||
var mpDisplay = statCalc.mpDisplay(user);
|
||||
|
||||
expect(mpDisplay).to.eql('30/100');
|
||||
});
|
||||
|
||||
it('Rounds mp down when given a decimal', function() {
|
||||
user._statsComputed = { maxMP: 100 };
|
||||
user.stats.mp = 30.99;
|
||||
var mpDisplay = statCalc.mpDisplay(user);
|
||||
|
||||
expect(mpDisplay).to.eql('30/100');
|
||||
});
|
||||
});
|
||||
|
||||
describe('goldDisplay', function() {
|
||||
it('displays gold', function() {
|
||||
var gold = 30;
|
||||
var goldDisplay = statCalc.goldDisplay(gold);
|
||||
|
||||
expect(goldDisplay).to.eql(30);
|
||||
});
|
||||
|
||||
it('Rounds gold down when given a decimal', function() {
|
||||
var gold = 30.999;
|
||||
var goldDisplay = statCalc.goldDisplay(gold);
|
||||
|
||||
expect(goldDisplay).to.eql(30);
|
||||
});
|
||||
});
|
||||
|
||||
describe('expDisplay', function() {
|
||||
it('displays exp as "exp / toNextLevelExp"', function() {
|
||||
user.stats.exp = 10;
|
||||
user.stats.lvl = 29;
|
||||
var expDisplay = statCalc.expDisplay(user);
|
||||
|
||||
expect(expDisplay).to.eql('10/640');
|
||||
});
|
||||
|
||||
it('Rounds exp down when given a decimal', function() {
|
||||
user.stats.exp = 10.999;
|
||||
user.stats.lvl = 29;
|
||||
var expDisplay = statCalc.expDisplay(user);
|
||||
|
||||
expect(expDisplay).to.eql('10/640');
|
||||
});
|
||||
});
|
||||
|
||||
describe('levelBonus', function() {
|
||||
it('calculates bonus as half of level for even numbered level under 100', function() {
|
||||
var level = 50;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(25);
|
||||
});
|
||||
|
||||
it('calculates bonus as half of level, rounded down, for odd numbered level under 100', function() {
|
||||
var level = 51;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(25);
|
||||
});
|
||||
|
||||
it('calculates bonus as 50 for levels >= 100', function() {
|
||||
var level = 150;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(50);
|
||||
});
|
||||
|
||||
it('calculates bonus as 0 for level 1', function() {
|
||||
var level = 1;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('equipmentStatBonus', function() {
|
||||
it('tallies up stats from euqipment that is equipped', function() {
|
||||
var equippedGear = {
|
||||
"weapon" : "weapon_special_1",
|
||||
"shield" : "shield_special_1",
|
||||
"head" : "head_special_1",
|
||||
"armor" : "armor_special_1"
|
||||
};
|
||||
|
||||
var strStat = statCalc.equipmentStatBonus('str', equippedGear);
|
||||
var conStat = statCalc.equipmentStatBonus('con', equippedGear);
|
||||
var intStat = statCalc.equipmentStatBonus('int', equippedGear);
|
||||
var perStat = statCalc.equipmentStatBonus('per', equippedGear);
|
||||
|
||||
expect(strStat).to.eql(24);
|
||||
expect(conStat).to.eql(24);
|
||||
expect(intStat).to.eql(24);
|
||||
expect(perStat).to.eql(24);
|
||||
});
|
||||
});
|
||||
|
||||
describe('classBonus', function() {
|
||||
it('calculates class bonus', function() {
|
||||
var equippedGear = {
|
||||
|
|
@ -179,4 +63,120 @@ describe('Stats Service', function() {
|
|||
expect(classBonus).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe('expDisplay', function() {
|
||||
it('displays exp as "exp / toNextLevelExp"', function() {
|
||||
user.stats.exp = 10;
|
||||
user.stats.lvl = 29;
|
||||
var expDisplay = statCalc.expDisplay(user);
|
||||
|
||||
expect(expDisplay).to.eql('10/640');
|
||||
});
|
||||
|
||||
it('Rounds exp down when given a decimal', function() {
|
||||
user.stats.exp = 10.999;
|
||||
user.stats.lvl = 29;
|
||||
var expDisplay = statCalc.expDisplay(user);
|
||||
|
||||
expect(expDisplay).to.eql('10/640');
|
||||
});
|
||||
});
|
||||
|
||||
describe('equipmentStatBonus', function() {
|
||||
it('tallies up stats from euqipment that is equipped', function() {
|
||||
var equippedGear = {
|
||||
"weapon" : "weapon_special_1",
|
||||
"shield" : "shield_special_1",
|
||||
"head" : "head_special_1",
|
||||
"armor" : "armor_special_1"
|
||||
};
|
||||
|
||||
var strStat = statCalc.equipmentStatBonus('str', equippedGear);
|
||||
var conStat = statCalc.equipmentStatBonus('con', equippedGear);
|
||||
var intStat = statCalc.equipmentStatBonus('int', equippedGear);
|
||||
var perStat = statCalc.equipmentStatBonus('per', equippedGear);
|
||||
|
||||
expect(strStat).to.eql(24);
|
||||
expect(conStat).to.eql(24);
|
||||
expect(intStat).to.eql(24);
|
||||
expect(perStat).to.eql(24);
|
||||
});
|
||||
});
|
||||
|
||||
describe('goldDisplay', function() {
|
||||
it('displays gold', function() {
|
||||
var gold = 30;
|
||||
var goldDisplay = statCalc.goldDisplay(gold);
|
||||
|
||||
expect(goldDisplay).to.eql(30);
|
||||
});
|
||||
|
||||
it('Rounds gold down when given a decimal', function() {
|
||||
var gold = 30.999;
|
||||
var goldDisplay = statCalc.goldDisplay(gold);
|
||||
|
||||
expect(goldDisplay).to.eql(30);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hpDisplay', function() {
|
||||
it('displays hp as "hp / totalHP"', function() {
|
||||
var hp = 34;
|
||||
var hpDisplay = statCalc.hpDisplay(hp);
|
||||
|
||||
expect(hpDisplay).to.eql('34/50');
|
||||
});
|
||||
|
||||
it('Rounds hp up when given a decimal', function() {
|
||||
|
||||
var hp = 34.4;
|
||||
var hpDisplay = statCalc.hpDisplay(hp);
|
||||
|
||||
expect(hpDisplay).to.eql('35/50');
|
||||
});
|
||||
});
|
||||
|
||||
describe('levelBonus', function() {
|
||||
it('calculates bonus as half of level for even numbered level under 100', function() {
|
||||
var level = 50;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(25);
|
||||
});
|
||||
|
||||
it('calculates bonus as half of level, rounded down, for odd numbered level under 100', function() {
|
||||
var level = 51;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(25);
|
||||
});
|
||||
|
||||
it('calculates bonus as 50 for levels >= 100', function() {
|
||||
var level = 150;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(50);
|
||||
});
|
||||
|
||||
it('calculates bonus as 0 for level 1', function() {
|
||||
var level = 1;
|
||||
var bonus = statCalc.levelBonus(level);
|
||||
expect(bonus).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mpDisplay', function() {
|
||||
it('displays mp as "mp / totalMP"', function() {
|
||||
user._statsComputed = { maxMP: 100 };
|
||||
user.stats.mp = 30;
|
||||
var mpDisplay = statCalc.mpDisplay(user);
|
||||
|
||||
expect(mpDisplay).to.eql('30/100');
|
||||
});
|
||||
|
||||
it('Rounds mp down when given a decimal', function() {
|
||||
user._statsComputed = { maxMP: 100 };
|
||||
user.stats.mp = 30.99;
|
||||
var mpDisplay = statCalc.mpDisplay(user);
|
||||
|
||||
expect(mpDisplay).to.eql('30/100');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,45 +12,18 @@
|
|||
|
||||
function statsFactory(Content, Shared) {
|
||||
|
||||
function hpDisplay(hp) {
|
||||
var remainingHP = Math.ceil(hp);
|
||||
var totalHP = Shared.maxHealth;
|
||||
var display = _formatOutOfTotalDisplay(remainingHP, totalHP);
|
||||
function classBonus(user, stat) {
|
||||
var computedStats = user._statsComputed;
|
||||
|
||||
return display;
|
||||
}
|
||||
if(computedStats) {
|
||||
var bonus = computedStats[stat]
|
||||
- user.stats.buffs[stat]
|
||||
- levelBonus(user.stats.lvl)
|
||||
- equipmentStatBonus(stat, user.items.gear.equipped)
|
||||
- user.stats[stat];
|
||||
|
||||
function goldDisplay(gold) {
|
||||
var display = Math.floor(gold);
|
||||
return display;
|
||||
}
|
||||
|
||||
function mpDisplay(user) {
|
||||
var remainingMP = Math.floor(user.stats.mp);
|
||||
var totalMP = user._statsComputed.maxMP;
|
||||
var display = _formatOutOfTotalDisplay(remainingMP, totalMP);
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
function expDisplay(user) {
|
||||
var exp = Math.floor(user.stats.exp);
|
||||
var toNextLevel = Shared.tnl(user.stats.lvl);
|
||||
var display = _formatOutOfTotalDisplay(exp, toNextLevel);
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
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;
|
||||
return bonus;
|
||||
}
|
||||
}
|
||||
|
||||
function equipmentStatBonus(stat, equipped) {
|
||||
|
|
@ -71,18 +44,45 @@
|
|||
return total;
|
||||
}
|
||||
|
||||
function classBonus(user, stat) {
|
||||
var computedStats = user._statsComputed;
|
||||
function expDisplay(user) {
|
||||
var exp = Math.floor(user.stats.exp);
|
||||
var toNextLevel = Shared.tnl(user.stats.lvl);
|
||||
var display = _formatOutOfTotalDisplay(exp, toNextLevel);
|
||||
|
||||
if(computedStats) {
|
||||
var bonus = computedStats[stat]
|
||||
- user.stats.buffs[stat]
|
||||
- levelBonus(user.stats.lvl)
|
||||
- equipmentStatBonus(stat, user.items.gear.equipped)
|
||||
- user.stats[stat];
|
||||
return display;
|
||||
}
|
||||
|
||||
return bonus;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function mpDisplay(user) {
|
||||
var remainingMP = Math.floor(user.stats.mp);
|
||||
var totalMP = user._statsComputed.maxMP;
|
||||
var display = _formatOutOfTotalDisplay(remainingMP, totalMP);
|
||||
|
||||
return display;
|
||||
}
|
||||
|
||||
function _formatOutOfTotalDisplay(stat, totalStat) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue