From 9142bba77989878213f760ef17dfe5d2950f9af2 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Fri, 13 Dec 2013 17:50:09 -0700 Subject: [PATCH] classes: add level-up stat point & auto-allocation handling --- dist/habitrpg-shared.js | 26 ++++++++++++++++++++++++-- script/index.coffee | 11 +++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index 1c81897873..115fc176e3 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -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; diff --git a/script/index.coffee b/script/index.coffee index 1e45790c5f..1b6ca17ebe 100644 --- a/script/index.coffee +++ b/script/index.coffee @@ -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