mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-02 04:00:36 +00:00
classes: add level-up stat point & auto-allocation handling
This commit is contained in:
parent
2f8b4c552b
commit
9142bba779
2 changed files with 35 additions and 2 deletions
26
dist/habitrpg-shared.js
vendored
26
dist/habitrpg-shared.js
vendored
|
|
@ -10267,7 +10267,8 @@ var process=require("__browserify_process");(function() {
|
|||
text: '',
|
||||
notes: '',
|
||||
priority: 1,
|
||||
challenge: {}
|
||||
challenge: {},
|
||||
attribute: 'str'
|
||||
};
|
||||
_.defaults(task, defaults);
|
||||
if (task.type === 'habit') {
|
||||
|
|
@ -11114,7 +11115,7 @@ var process=require("__browserify_process");(function() {
|
|||
*/
|
||||
|
||||
updateStats: function(stats) {
|
||||
var tnl;
|
||||
var suggested, tallies, tnl;
|
||||
if (stats.hp <= 0) {
|
||||
return user.stats.hp = 0;
|
||||
}
|
||||
|
|
@ -11132,6 +11133,27 @@ var process=require("__browserify_process");(function() {
|
|||
stats.exp -= tnl;
|
||||
user.stats.lvl++;
|
||||
tnl = api.tnl(user.stats.lvl);
|
||||
if (user.preferences.automaticAllocation) {
|
||||
tallies = _.reduce(user.tasks, (function(m, v) {
|
||||
m[v.attribute || 'str'] += v.value;
|
||||
return m;
|
||||
}), {
|
||||
str: 0,
|
||||
int: 0,
|
||||
con: 0,
|
||||
per: 0
|
||||
});
|
||||
suggested = _.reduce(tallies, (function(m, v, k) {
|
||||
if (v > tallies[m]) {
|
||||
return k;
|
||||
} else {
|
||||
return m;
|
||||
}
|
||||
}), 'str');
|
||||
user.stats[suggested]++;
|
||||
} else {
|
||||
user.stats.points = user.stats.lvl - (user.stats.con + user.stats.str + user.stats.per + user.stats.int);
|
||||
}
|
||||
}
|
||||
if (user.stats.lvl === 100) {
|
||||
stats.exp = 0;
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ api.taskDefaults = (task) ->
|
|||
notes: ''
|
||||
priority: 1
|
||||
challenge: {}
|
||||
attribute: 'str'
|
||||
_.defaults task, defaults
|
||||
_.defaults(task, {up:true,down:true}) if task.type is 'habit'
|
||||
_.defaults(task, {history: []}) if task.type in ['habit', 'daily']
|
||||
|
|
@ -806,6 +807,16 @@ api.wrap = (user) ->
|
|||
stats.exp -= tnl
|
||||
user.stats.lvl++
|
||||
tnl = api.tnl(user.stats.lvl)
|
||||
|
||||
# Auto-allocate a point, or give them a new manual point
|
||||
if user.preferences.automaticAllocation
|
||||
tallies = _.reduce user.tasks, ((m,v)-> m[v.attribute or 'str'] += v.value;m), {str:0,int:0,con:0,per:0}
|
||||
suggested = _.reduce tallies, ((m,v,k)-> if v>tallies[m] then k else m), 'str'
|
||||
user.stats[suggested]++
|
||||
else
|
||||
# add new allocatable points. We could do user.stats.points++, but this does a fail-safe just in case
|
||||
user.stats.points = user.stats.lvl - (user.stats.con + user.stats.str + user.stats.per + user.stats.int);
|
||||
|
||||
if user.stats.lvl == 100
|
||||
stats.exp = 0
|
||||
user.stats.hp = 50
|
||||
|
|
|
|||
Loading…
Reference in a new issue