mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
refactor: Extract constants into constants file
This commit is contained in:
3
common/script/constants.js
Normal file
3
common/script/constants.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const MAX_HEALTH = 50;
|
||||||
|
export const MAX_LEVEL = 100;
|
||||||
|
export const MAX_STAT_POINTS = MAX_LEVEL;
|
||||||
@@ -2,6 +2,11 @@ import {
|
|||||||
daysSince,
|
daysSince,
|
||||||
shouldDo,
|
shouldDo,
|
||||||
} from '../../common/script/cron';
|
} from '../../common/script/cron';
|
||||||
|
import {
|
||||||
|
MAX_HEALTH,
|
||||||
|
MAX_LEVEL,
|
||||||
|
MAX_STAT_POINTS,
|
||||||
|
} from './constants';
|
||||||
import * as statHelpers from './statHelpers';
|
import * as statHelpers from './statHelpers';
|
||||||
|
|
||||||
var $w, _, api, content, i18n, moment, preenHistory, sortOrder,
|
var $w, _, api, content, i18n, moment, preenHistory, sortOrder,
|
||||||
@@ -20,10 +25,9 @@ api = module.exports = {};
|
|||||||
api.i18n = i18n;
|
api.i18n = i18n;
|
||||||
api.shouldDo = shouldDo;
|
api.shouldDo = shouldDo;
|
||||||
|
|
||||||
api.maxLevel = statHelpers.MAX_LEVEL;
|
api.maxLevel = MAX_LEVEL;
|
||||||
api.maxStatPoints = statHelpers.MAX_STAT_POINTS;
|
|
||||||
api.capByLevel = statHelpers.capByLevel;
|
api.capByLevel = statHelpers.capByLevel;
|
||||||
api.maxHealth = statHelpers.MAX_HEALTH;
|
api.maxHealth = MAX_HEALTH;
|
||||||
api.tnl = statHelpers.toNextLevel;
|
api.tnl = statHelpers.toNextLevel;
|
||||||
api.diminishingReturns = statHelpers.diminishingReturns;
|
api.diminishingReturns = statHelpers.diminishingReturns;
|
||||||
|
|
||||||
@@ -2283,7 +2287,8 @@ api.wrap = function(user, main) {
|
|||||||
tnl = api.tnl(user.stats.lvl);
|
tnl = api.tnl(user.stats.lvl);
|
||||||
user.stats.hp = 50;
|
user.stats.hp = 50;
|
||||||
var userTotalStatPoints = user.stats.str + user.stats.int + user.stats.con + user.stats.per;
|
var userTotalStatPoints = user.stats.str + user.stats.int + user.stats.con + user.stats.per;
|
||||||
if (userTotalStatPoints >= api.maxStatPoints) {
|
|
||||||
|
if (userTotalStatPoints >= MAX_STAT_POINTS) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (user.preferences.automaticAllocation) {
|
if (user.preferences.automaticAllocation) {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
|
import {
|
||||||
|
MAX_LEVEL,
|
||||||
|
} from './constants';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
Level cap
|
Level cap
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const MAX_LEVEL = 100;
|
|
||||||
|
|
||||||
export function capByLevel (lvl) {
|
export function capByLevel (lvl) {
|
||||||
if (lvl > MAX_LEVEL) {
|
if (lvl > MAX_LEVEL) {
|
||||||
return MAX_LEVEL;
|
return MAX_LEVEL;
|
||||||
@@ -14,22 +16,6 @@ export function capByLevel (lvl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
------------------------------------------------------
|
|
||||||
Stats cap
|
|
||||||
------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const MAX_STAT_POINTS = MAX_LEVEL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
------------------------------------------------------
|
|
||||||
Health cap
|
|
||||||
------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const MAX_HEALTH = 50;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
Scoring
|
Scoring
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable camelcase */
|
|
||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
} from '../helpers/common.helper';
|
} from '../helpers/common.helper';
|
||||||
@@ -19,31 +18,29 @@ describe('user.fns.updateStats', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
context('Stat Allocation', () => {
|
context('Stat Allocation', () => {
|
||||||
it('Adds an attibute point when user\'s stat points are less than max level', () => {
|
it('adds an attibute point when user\'s stat points are less than max level', () => {
|
||||||
let stats = {
|
user.stats.exp = 3581;
|
||||||
exp: 3581,
|
|
||||||
};
|
|
||||||
|
|
||||||
user.stats.lvl = 99;
|
user.stats.lvl = 99;
|
||||||
user.stats.str = 25;
|
user.stats.str = 25;
|
||||||
user.stats.int = 25;
|
user.stats.int = 25;
|
||||||
user.stats.con = 25;
|
user.stats.con = 25;
|
||||||
user.stats.per = 24;
|
user.stats.per = 24;
|
||||||
user.fns.updateStats(stats);
|
|
||||||
|
user.fns.updateStats(user.stats);
|
||||||
|
|
||||||
expect(user.stats.points).to.eql(1);
|
expect(user.stats.points).to.eql(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Does not add an attibute point when user\'s stat points are equal to max level', () => {
|
it('does not add an attibute point when user\'s stat points are equal to max level', () => {
|
||||||
let stats = {
|
user.stats.exp = 3581;
|
||||||
exp: 3581,
|
|
||||||
};
|
|
||||||
|
|
||||||
user.stats.lvl = 99;
|
user.stats.lvl = 99;
|
||||||
user.stats.str = 25;
|
user.stats.str = 25;
|
||||||
user.stats.int = 25;
|
user.stats.int = 25;
|
||||||
user.stats.con = 25;
|
user.stats.con = 25;
|
||||||
user.stats.per = 25;
|
user.stats.per = 25;
|
||||||
user.fns.updateStats(stats);
|
|
||||||
|
user.fns.updateStats(user.stats);
|
||||||
|
|
||||||
expect(user.stats.points).to.eql(0);
|
expect(user.stats.points).to.eql(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user