From bb801769208e7aecf97e6946e91678ef8a571f91 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 29 Dec 2013 21:10:45 -0700 Subject: [PATCH] checklists WIP --- dist/habitrpg-shared.js | 18 +++++++++++++++--- script/index.coffee | 9 ++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index 62bb6474b3..acbb627985 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -11300,7 +11300,10 @@ var process=require("__browserify_process");(function() { if (!(task = user.tasks[(_ref = req.params) != null ? _ref.id : void 0])) { return typeof cb === "function" ? cb("Task not found") : void 0; } - _.merge(task, req.body); + _.merge(task, _.omit(req.body, 'checklist')); + if (req.body.checklist) { + task.checklist = req.body.checklist; + } if (typeof task.markModified === "function") { task.markModified('tags'); } @@ -11684,15 +11687,24 @@ var process=require("__browserify_process");(function() { delta = 0; calculateDelta = function() { return _.times(options.times, function() { - var adjustAmt, currVal, nextDelta, _ref1; + var adjustAmt, currVal, nextDelta, _ref1, _ref2; currVal = task.value < -47.27 ? -47.27 : task.value > 21.27 ? 21.27 : task.value; nextDelta = Math.pow(0.9747, currVal) * (direction === 'down' ? -1 : 1); + if (direction === 'down' && task.type === 'daily' && options.cron && ((_ref1 = task.checklist) != null ? _ref1.length : void 0) > 0) { + nextDelta *= 1 - _.reduce(task.checklist, (function(m, i) { + return m + (i.completed ? 1 : 0); + }), 0) / task.checklist.length; + _.each(task.checklist, (function(i) { + i.completed = false; + return true; + })); + } if (task.type !== 'reward') { adjustAmt = nextDelta; if (direction === 'up' && task.type !== 'reward' && !(task.type === 'habit' && !task.down)) { adjustAmt = nextDelta * (1 + user._statsComputed.str * .004); user.party.quest.progress.up = user.party.quest.progress.up || 0; - if ((_ref1 = task.type) === 'daily' || _ref1 === 'todo') { + if ((_ref2 = task.type) === 'daily' || _ref2 === 'todo') { user.party.quest.progress.up += adjustAmt; } } diff --git a/script/index.coffee b/script/index.coffee index 0171f21b2c..bbed240317 100644 --- a/script/index.coffee +++ b/script/index.coffee @@ -426,7 +426,8 @@ api.wrap = (user) -> updateTask: (req, cb) -> return cb?("Task not found") unless task = user.tasks[req.params?.id] - _.merge task, req.body + _.merge task, _.omit(req.body,'checklist') + task.checklist = req.body.checklist if req.body.checklist task.markModified? 'tags' cb? null, task @@ -686,6 +687,12 @@ api.wrap = (user) -> else if task.value > 21.27 then 21.27 else task.value nextDelta = Math.pow(0.9747, currVal) * (if direction is 'down' then -1 else 1) + + # If the Daily has a checklist, only dock them them a portion based on their checklist completion + if direction is 'down' and task.type is 'daily' and options.cron and task.checklist?.length > 0 + nextDelta *= (1 - _.reduce(task.checklist,((m,i)->m+(if i.completed then 1 else 0)),0) / task.checklist.length) + _.each task.checklist, ((i)->i.completed=false;true) + unless task.type is 'reward' adjustAmt = nextDelta # ===== STRENGTH =====