diff --git a/lib/app/scoring.js b/lib/app/scoring.js index 1b55b9bc96..1dae9caae1 100644 --- a/lib/app/scoring.js +++ b/lib/app/scoring.js @@ -206,10 +206,12 @@ score = function(taskId, direction, options) { } delta = 0; _.times(options.times, function(n) { - delta = taskDeltaFormula(value, direction); + var nextDelta; + nextDelta = taskDeltaFormula(value, direction); if (adjustvalue) { - return value += delta; + value += nextDelta; } + return delta += nextDelta; }); if (type === 'habit') { if (taskObj.value !== value) { diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index 0420613713..3637ff4a9d 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -164,8 +164,12 @@ score = (taskId, direction, options={cron:false, times:1}) -> # If multiple days have passed, multiply times days missed # TODO integrate this multiplier into the formula, so don't have to loop _.times options.times, (n) -> - delta = taskDeltaFormula(value, direction) - value += delta if adjustvalue + # Each iteration calculate the delta (nextDelta), which is then accumulated in delta + # (aka, the total delta). This weirdness won't be necessary when calculating mathematically + # rather than iteratively + nextDelta = taskDeltaFormula(value, direction) + value += nextDelta if adjustvalue + delta += nextDelta if type == 'habit' # Add habit value to habit-history (if different) diff --git a/test/user.mocha.coffee b/test/user.mocha.coffee index c1a1285294..04802e0a5c 100644 --- a/test/user.mocha.coffee +++ b/test/user.mocha.coffee @@ -125,7 +125,7 @@ describe 'User', -> ## Trial 2 freshTask {type: 'habit', text: 'Habit', completed: false} shouldBe = modificationsLookup({lvl:1,armor:0,weapon:0}, 'down', 10) - _.times 10, -> scoring.score(uuid,'down', {times:10}) + scoring.score(uuid,'down', {times:10}) [stats, task] = statsTask() expect(stats.hp).to.be.eql shouldBe.user.stats.hp expect(task.value).to.eql shouldBe.value