From fc14eadc088a7d2eb393df6d0119dbc1b78bedc2 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Mon, 27 May 2013 14:37:57 +0100 Subject: [PATCH] habitrpg-shared: fix cron, so it doesn't run fully for new users --- src/app/index.coffee | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/app/index.coffee b/src/app/index.coffee index a7c03cd9a2..69efcc842c 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -135,17 +135,21 @@ ready (model) -> require('./unlock').app(exports, model) require('./filters').app(exports, model) + ### + Cron + ### uObj = misc.hydrate(user.get()) - cron = -> - #return setTimeout(cron, 1) if model._txnQueue.length > 0 - # habitrpg-shared/algos requires uObj.habits, uObj.dailys etc instead of uObj.tasks - _.each ['habit','daily','todo','reward'], (type) -> - uObj["#{type}s"] = _.where(uObj.tasks, {type:type}); true - paths = {} - algos.cron(uObj, {paths:paths}) - lostHp = delete paths['stats.hp'] # we'll set this manually so we can get a cool animation - _.each paths, (v,k) -> user.pass({cron:true}).set(k,helpers.dotGet(k, uObj)); true - if lostHp - browser.resetDom(model) - setTimeout (-> user.set('stats.hp', uObj.stats.hp)), 750 - cron() if algos.shouldCron(uObj) + # habitrpg-shared/algos requires uObj.habits, uObj.dailys etc instead of uObj.tasks + _.each ['habit','daily','todo','reward'], (type) -> + uObj["#{type}s"] = _.where(uObj.tasks, {type:type}); true + paths = {} + algos.cron(uObj, {paths:paths}) + if !_.isEmpty(paths) + if paths['lastCron'] and _.size(paths) is 1 + user.set "lastCron", uObj.lastCron + else + lostHp = delete paths['stats.hp'] # we'll set this manually so we can get a cool animation + _.each paths, (v,k) -> user.pass({cron:true}).set(k,helpers.dotGet(k, uObj)); true + if lostHp + browser.resetDom(model) + setTimeout (-> user.set('stats.hp', uObj.stats.hp)), 750 \ No newline at end of file