diff --git a/lib/app/index.js b/lib/app/index.js index 09d35a9925..6402b42b43 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -302,17 +302,17 @@ ready(function(model) { daysPassed = helpers.daysBetween(lastCron, today); if (daysPassed > 0) { model.set('_user.lastCron', today); - return _.times(daysPassed, (function() { - return scoring.tally(model); - })); + return _(daysPassed).times(function() { + return scoring.tally(model.at('_user')); + }); } }; - setTimeout((function() { + setTimeout(function() { return poormanscron(); - }), 2000); - setInterval((function() { + }, 2000); + setInterval(function() { return poormanscron(); - }), 3600000); + }, 3600000); exports.endOfDayTally = function(e, el) { return scoring.tally(model); }; diff --git a/lib/app/scoring.js b/lib/app/scoring.js index 09b7a4e20e..7a44e5e21a 100644 --- a/lib/app/scoring.js +++ b/lib/app/scoring.js @@ -108,9 +108,8 @@ module.exports.score = score = function(spec) { return delta; }; -module.exports.tally = function(model) { - var expTally, lvl, todoTally, user; - user = model.at('_user'); +module.exports.tally = function(user) { + var expTally, lvl, todoTally; todoTally = 0; _.each(user.get('tasks'), function(taskObj, taskId, list) { var absVal, completed, task, type, value, _ref; @@ -144,7 +143,7 @@ module.exports.tally = function(model) { } } }); - model.push('_user.history.todos', { + user.push('history.todos', { date: new Date(), value: todoTally }); @@ -154,7 +153,7 @@ module.exports.tally = function(model) { lvl++; expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200; } - return model.push('_user.history.exp', { + return user.push('history.exp', { date: new Date(), value: expTally }); diff --git a/src/app/index.coffee b/src/app/index.coffee index 140c597561..e6ee34e04e 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -54,7 +54,8 @@ get '/:uidParam?', (page, model, {uidParam}) -> reroll: content.items.reroll # http://tibia.wikia.com/wiki/Formula - model.fn '_user._tnl', '_user.stats.lvl', (lvl) -> 50 * Math.pow(lvl, 2) - 150 * lvl + 200 + model.fn '_user._tnl', '_user.stats.lvl', (lvl) -> + 50 * Math.pow(lvl, 2) - 150 * lvl + 200 # Default Tasks model.refList "_habitList", "_user.tasks", "_user.habitIds" @@ -250,17 +251,16 @@ ready (model) -> daysPassed = helpers.daysBetween(lastCron, today) if daysPassed > 0 model.set('_user.lastCron', today) # reset cron - _.times daysPassed, (-> - scoring.tally(model) - ) + _(daysPassed).times () -> + scoring.tally(model.at('_user')) # FIXME seems can't call poormanscron() instantly, have to call after some time (2s here) # Doesn't do anything otherwise. Don't know why... model not initialized enough yet? - setTimeout (-> # Run once on refresh + setTimeout () -> # Run once on refresh poormanscron() - ), 2000 - setInterval (-> # Then run once every hour + , 2000 + setInterval () -> # Then run once every hour poormanscron() - ), 3600000 + , 3600000 # ========== DEBUGGING ========== diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index 290b437761..a1ba8ac6df 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -98,8 +98,7 @@ module.exports.score = score = (spec = {user:null, task:null, direction:null, cr # At end of day, add value to all incomplete Daily & Todo tasks (further incentive) # For incomplete Dailys, deduct experience -module.exports.tally = (model) -> - user = model.at '_user' +module.exports.tally = (user) -> todoTally = 0 _.each user.get('tasks'), (taskObj, taskId, list) -> #FIXME is it hiccuping here? taskId == "$_65255f4e-3728-4d50-bade-3b05633639af_2", & taskObj.id = undefined @@ -116,7 +115,7 @@ module.exports.tally = (model) -> absVal = if (completed) then Math.abs(value) else value todoTally += absVal task.pass({cron:true}).set('completed', false) if type == 'daily' - model.push '_user.history.todos', { date: new Date(), value: todoTally } + user.push 'history.todos', { date: new Date(), value: todoTally } # tally experience expTally = user.get 'stats.exp' @@ -124,4 +123,4 @@ module.exports.tally = (model) -> while lvl < (user.get('stats.lvl')-1) lvl++ expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200 - model.push '_user.history.exp', { date: new Date(), value: expTally } \ No newline at end of file + user.push 'history.exp', { date: new Date(), value: expTally } \ No newline at end of file