Merge branch 'master' into challenges
This commit is contained in:
+46
-55
@@ -313,16 +313,6 @@ updateStats = (user, newStats, options={}) ->
|
|||||||
gp = 0.0 if (!gp? or gp < 0)
|
gp = 0.0 if (!gp? or gp < 0)
|
||||||
user.stats.gp = newStats.gp
|
user.stats.gp = newStats.gp
|
||||||
|
|
||||||
###
|
|
||||||
Test if we should run cron
|
|
||||||
{user} pass in the user object
|
|
||||||
{now} optional - we can decide which time is "now", which is especially helpful in tests
|
|
||||||
###
|
|
||||||
obj.shouldCron = (user, options={}) ->
|
|
||||||
now = options.now || +new Date
|
|
||||||
return true if !user.lastCron? or user.lastCron is 'new' or helpers.daysBetween(user.lastCron, now, user.preferences?.dayStart) > 0
|
|
||||||
return false
|
|
||||||
|
|
||||||
###
|
###
|
||||||
At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
|
At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
|
||||||
For incomplete Dailys, deduct experience
|
For incomplete Dailys, deduct experience
|
||||||
@@ -339,56 +329,57 @@ obj.cron = (user, options={}) ->
|
|||||||
return
|
return
|
||||||
|
|
||||||
daysMissed = helpers.daysBetween(user.lastCron, now, user.preferences?.dayStart)
|
daysMissed = helpers.daysBetween(user.lastCron, now, user.preferences?.dayStart)
|
||||||
if daysMissed > 0
|
return unless daysMissed > 0
|
||||||
user.lastCron = now; paths['lastCron'] = true
|
|
||||||
|
|
||||||
# User is resting at the inn. Used to be we un-checked each daily without performing calculation (see commits before fb29e35)
|
user.lastCron = now; paths['lastCron'] = true
|
||||||
# but to prevent abusing the inn (http://goo.gl/GDb9x) we now do *not* calculate dailies, and simply set lastCron to today
|
|
||||||
return if user.flags.rest is true
|
|
||||||
|
|
||||||
# Tally each task
|
# User is resting at the inn. Used to be we un-checked each daily without performing calculation (see commits before fb29e35)
|
||||||
todoTally = 0
|
# but to prevent abusing the inn (http://goo.gl/GDb9x) we now do *not* calculate dailies, and simply set lastCron to today
|
||||||
user.todos.concat(user.dailys).forEach (task) ->
|
return if user.flags.rest is true
|
||||||
{id, type, completed, repeat} = task
|
|
||||||
# Deduct experience for missed Daily tasks, but not for Todos (just increase todo's value)
|
|
||||||
unless completed
|
|
||||||
scheduleMisses = daysMissed
|
|
||||||
# for dailys which have repeat dates, need to calculate how many they've missed according to their own schedule
|
|
||||||
if (type is 'daily') and repeat
|
|
||||||
scheduleMisses = 0
|
|
||||||
_.times daysMissed, (n) ->
|
|
||||||
thatDay = moment(now).subtract('days', n + 1)
|
|
||||||
scheduleMisses++ if helpers.shouldDo(thatDay, repeat, {dayStart:obj.preferences?.dayStart})
|
|
||||||
obj.score(user, task, 'down', {times:scheduleMisses, cron:true, paths:paths}) if scheduleMisses > 0
|
|
||||||
|
|
||||||
switch type
|
# Tally each task
|
||||||
when 'daily'
|
todoTally = 0
|
||||||
(task.history ?= []).push({ date: +new Date, value: task.value }); paths["tasks.#{task.id}.history"] = true
|
user.todos.concat(user.dailys).forEach (task) ->
|
||||||
task.completed = false; paths["tasks.#{task.id}.completed"] = true;
|
{id, type, completed, repeat} = task
|
||||||
when 'todo'
|
# Deduct experience for missed Daily tasks, but not for Todos (just increase todo's value)
|
||||||
#get updated value
|
unless completed
|
||||||
absVal = if (completed) then Math.abs(task.value) else task.value
|
scheduleMisses = daysMissed
|
||||||
todoTally += absVal
|
# for dailys which have repeat dates, need to calculate how many they've missed according to their own schedule
|
||||||
|
if (type is 'daily') and repeat
|
||||||
|
scheduleMisses = 0
|
||||||
|
_.times daysMissed, (n) ->
|
||||||
|
thatDay = moment(now).subtract('days', n + 1)
|
||||||
|
scheduleMisses++ if helpers.shouldDo(thatDay, repeat, {dayStart:obj.preferences?.dayStart})
|
||||||
|
obj.score(user, task, 'down', {times:scheduleMisses, cron:true, paths:paths}) if scheduleMisses > 0
|
||||||
|
|
||||||
user.habits.forEach (task) -> # slowly reset 'onlies' value to 0
|
switch type
|
||||||
if task.up is false or task.down is false
|
when 'daily'
|
||||||
if Math.abs(task.value) < 0.1
|
(task.history ?= []).push({ date: +new Date, value: task.value }); paths["tasks.#{task.id}.history"] = true
|
||||||
task.value = 0
|
task.completed = false; paths["tasks.#{task.id}.completed"] = true;
|
||||||
else
|
when 'todo'
|
||||||
task.value = task.value / 2
|
#get updated value
|
||||||
paths["tasks.#{task.id}.value"] = true
|
absVal = if (completed) then Math.abs(task.value) else task.value
|
||||||
|
todoTally += absVal
|
||||||
|
|
||||||
|
user.habits.forEach (task) -> # slowly reset 'onlies' value to 0
|
||||||
|
if task.up is false or task.down is false
|
||||||
|
if Math.abs(task.value) < 0.1
|
||||||
|
task.value = 0
|
||||||
|
else
|
||||||
|
task.value = task.value / 2
|
||||||
|
paths["tasks.#{task.id}.value"] = true
|
||||||
|
|
||||||
|
|
||||||
# Finished tallying
|
# Finished tallying
|
||||||
((user.history ?= {}).todos ?= []).push { date: now, value: todoTally }
|
((user.history ?= {}).todos ?= []).push { date: now, value: todoTally }
|
||||||
# tally experience
|
# tally experience
|
||||||
expTally = user.stats.exp
|
expTally = user.stats.exp
|
||||||
lvl = 0 #iterator
|
lvl = 0 #iterator
|
||||||
while lvl < (user.stats.lvl - 1)
|
while lvl < (user.stats.lvl - 1)
|
||||||
lvl++
|
lvl++
|
||||||
expTally += obj.tnl(lvl)
|
expTally += obj.tnl(lvl)
|
||||||
(user.history.exp ?= []).push { date: now, value: expTally }
|
(user.history.exp ?= []).push { date: now, value: expTally }
|
||||||
paths["history"] = true
|
paths["history"] = true
|
||||||
user
|
user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -33,7 +33,7 @@ items = module.exports.items =
|
|||||||
{index: 0, text: "No Shield", classes: 'shield_0', notes:'No Shield.', defense: 0, value:0}
|
{index: 0, text: "No Shield", classes: 'shield_0', notes:'No Shield.', defense: 0, value:0}
|
||||||
{index: 1, text: "Wooden Shield", classes: 'shield_1', notes:'Decreases HP loss by 3%', defense: 3, value:20}
|
{index: 1, text: "Wooden Shield", classes: 'shield_1', notes:'Decreases HP loss by 3%', defense: 3, value:20}
|
||||||
{index: 2, text: "Buckler", classes: 'shield_2', notes:'Decreases HP loss by 4%.', defense: 4, value:35}
|
{index: 2, text: "Buckler", classes: 'shield_2', notes:'Decreases HP loss by 4%.', defense: 4, value:35}
|
||||||
{index: 3, text: "Enforced Shield", classes: 'shield_3', notes:'Decreases HP loss by 5%.', defense: 5, value:55}
|
{index: 3, text: "Reinforced Shield", classes: 'shield_3', notes:'Decreases HP loss by 5%.', defense: 5, value:55}
|
||||||
{index: 4, text: "Red Shield", classes: 'shield_4', notes:'Decreases HP loss by 7%.', defense: 7, value:70}
|
{index: 4, text: "Red Shield", classes: 'shield_4', notes:'Decreases HP loss by 7%.', defense: 7, value:70}
|
||||||
{index: 5, text: "Golden Shield", classes: 'shield_5', notes:'Decreases HP loss by 8%.', defense: 8, value:90}
|
{index: 5, text: "Golden Shield", classes: 'shield_5', notes:'Decreases HP loss by 8%.', defense: 8, value:90}
|
||||||
{index: 6, text: "Tormented Skull", classes: 'shield_6', notes:'Decreases HP loss by 9%.', defense: 9, value:120}
|
{index: 6, text: "Tormented Skull", classes: 'shield_6', notes:'Decreases HP loss by 9%.', defense: 9, value:120}
|
||||||
@@ -106,4 +106,4 @@ module.exports.updateStore = (user) ->
|
|||||||
else if i is items[type].length
|
else if i is items[type].length
|
||||||
showNext = false
|
showNext = false
|
||||||
changes[type] = if showNext then items[type][i] else {hide:true}
|
changes[type] = if showNext then items[type][i] else {hide:true}
|
||||||
return changes
|
return changes
|
||||||
|
|||||||
Reference in New Issue
Block a user