fixed cron bug using underscore instead of lodash

This commit is contained in:
Tyler Renelle 2013-01-20 19:35:31 -05:00
parent 4d93f51d55
commit 95b5324329
5 changed files with 42 additions and 42 deletions

View file

@ -19,7 +19,8 @@
"async": "*",
"lodash": "*",
"coffee-script": "*",
"toobusy": "~0.2.0"
"toobusy": "~0.2.0",
"underscore": "*"
},
"private": true,
"subdomain": "habitrpg",

View file

@ -12,7 +12,7 @@ schema = require './schema'
helpers = require './helpers'
helpers.viewHelpers view
browser = require './browser'
_ = require('lodash')
_ = require('underscore')
# ========== ROUTES ==========

View file

@ -1,10 +1,10 @@
content = require './content'
moment = require 'moment'
_ = require 'lodash'
_ = require 'underscore'
module.exports.userSchema = ->
# deep clone, else further new users get duplicate objects
newUser = _.cloneDeep
newUser = require('lodash').cloneDeep
balance: 2
stats: { money: 0, exp: 0, lvl: 1, hp: 50 }
items: { itemsEnabled: false, armor: 0, weapon: 0 }

View file

@ -1,6 +1,6 @@
async = require 'async'
moment = require 'moment'
_ = require 'lodash'
_ = require 'underscore'
content = require './content'
helpers = require './helpers'
browser = require './browser'
@ -121,7 +121,7 @@ updateStats = (newStats, update) ->
# {times} # times to call score on this task (1 unless cron, usually)
# {update} if we're running updates en-mass (eg, cron on server) pass in userObj
score = (taskId, direction, times, update) ->
times ||= 1
times ?= 1
userObj = update || user.get()
{money, hp, exp, lvl} = userObj.stats
@ -192,17 +192,18 @@ score = (taskId, direction, times, update) ->
# For incomplete Dailys, deduct experience
cron = (userObj) ->
today = new Date()
userObj.lastCron ||= today
userObj.lastCron ?= today
lastCron = userObj.lastCron
daysPassed = helpers.daysBetween(today, lastCron)
if daysPassed > 0
todoTally = 0
userObj.history ||= {}; userObj.history.todos ||= []; userObj.history.exp ||= []
userObj.history ?= {}; userObj.history.todos ?= []; userObj.history.exp ?= []
# Tally each task
tasks = _.toArray(userObj.tasks)
_.each tasks, (taskObj) ->
return unless taskObj? and taskObj.id? # a task had a null id during cron, this should not be happening
_.each userObj.tasks, (taskObj) ->
#FIXME remove broken tasks
if taskObj.id? # a task had a null id during cron, this should not be happening
console.log taskObj
{id, type, completed, repeat} = taskObj
if type in ['todo', 'daily']
# Deduct experience for missed Daily tasks,
@ -222,14 +223,14 @@ cron = (userObj) ->
value = userObj.tasks[taskObj.id].value #get updated value
if type == 'daily'
userObj.tasks[taskObj.id].history ||= []
userObj.tasks[taskObj.id].history ?= []
userObj.tasks[taskObj.id].history.push { date: today, value: value }
userObj.tasks[taskObj.id].completed = false
else
absVal = if (completed) then Math.abs(value) else value
todoTally += absVal
# Finished tallying, this is the 'completed' callback
# Finished tallying
userObj.history.todos.push { date: today, value: todoTally }
# tally experience
expTally = userObj.stats.exp
@ -239,8 +240,6 @@ cron = (userObj) ->
expTally += (lvl*100)/5
userObj.history.exp.push { date: today, value: expTally }
userObj.lastCron = today # reset cron
return userObj
module.exports = {
setModel: setModel

View file

@ -1,5 +1,5 @@
scoring = require('../app/scoring')
_ = require('lodash')
_ = require('underscore')
module.exports = (expressApp, root, derby) ->