diff --git a/lib/app/index.js b/lib/app/index.js index 0b061e07e2..66527d851a 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -504,32 +504,35 @@ ready(function(model) { }); expTally = user.get('stats.exp'); lvl = 0; - _(user.get('stats.lvl') - 1).times(function() { + while (lvl < (user.get('stats.lvl') - 1)) { lvl++; - return expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200; - }); + expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200; + } return model.push('_user.history.exp', { date: new Date(), value: expTally }); }; exports.poormanscron = poormanscron = function() { - var DAY, daysPassed, lastCron, today; + var DAY, daysPassed, lastCron, n, today, _k, _results; model.setNull('_user.lastCron', new Date()); lastCron = new Date((new Date(model.get('_user.lastCron'))).toDateString()); today = new Date((new Date).toDateString()); DAY = 1000 * 60 * 60 * 24; daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY); if (daysPassed > 0) { - _(daysPassed).times(function() { - return endOfDayTally(); - }); model.set('_user.lastCron', today); - return console.log({ - today: today, - lastCron: lastCron, - daysPassed: daysPassed - }, 'cron debugging'); + _results = []; + for (n = _k = 1; 1 <= daysPassed ? _k <= daysPassed : _k >= daysPassed; n = 1 <= daysPassed ? ++_k : --_k) { + console.log({ + today: today, + lastCron: lastCron, + daysPassed: daysPassed, + n: n + }, "[debug] Cron (" + today + ", " + n + ")"); + _results.push(endOfDayTally()); + } + return _results; } }; poormanscron(); diff --git a/src/app/index.coffee b/src/app/index.coffee index f67f502c2c..5aa68fa686 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -387,7 +387,7 @@ ready (model) -> # tally experience expTally = user.get 'stats.exp' lvl = 0 #iterator - _(user.get('stats.lvl')-1).times -> + 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 } @@ -401,10 +401,10 @@ ready (model) -> DAY = 1000 * 60 * 60 * 24 daysPassed = Math.floor((today.getTime() - lastCron.getTime()) / DAY) if daysPassed > 0 - _(daysPassed).times -> - endOfDayTally() model.set('_user.lastCron', today) # reset cron - console.log {today: today, lastCron: lastCron, daysPassed: daysPassed}, 'cron debugging' + for n in [1..daysPassed] + console.log {today: today, lastCron: lastCron, daysPassed: daysPassed, n:n}, "[debug] Cron (#{today}, #{n})" + endOfDayTally() poormanscron() # Run once on refresh setInterval (-> # Then run once every hour poormanscron()