feat(scoring): MP gain from Habits and Dailies

Turns MP gain from tasks into a function, and calls the function with varying inputs from Habits (1/4 gain), Dailies (normal gain), and To-Dos (normal gain multiplied by checklist completion).
This commit is contained in:
Sabe Jones
2014-12-10 21:21:09 -06:00
parent 935dc2cd2e
commit 7b22244f01
+9 -6
View File
@@ -1052,6 +1052,7 @@ api.wrap = (user, main=true) ->
switch task.type
when 'habit'
changeTaskValue()
gainMP(_.max([0.25, (.0025 * user._statsComputed.maxMP)]) * if direction is 'down' then -1 else 1)
# Add habit value to habit-history (if different)
if (delta > 0) then addPoints() else subtractPoints()
@@ -1070,6 +1071,7 @@ api.wrap = (user, main=true) ->
task.streak = 0 unless user.stats.buffs.streaks
else
changeTaskValue()
gainMP(_.max([1, (.01 * user._statsComputed.maxMP)]) * if direction is 'down' then -1 else 1)
if direction is 'down'
delta = calculateDelta() # recalculate delta for unchecking so the gp and exp come out correctly
addPoints() # obviously for delta>0, but also a trick to undo accidental checkboxes
@@ -1096,12 +1098,7 @@ api.wrap = (user, main=true) ->
addPoints() # obviously for delta>0, but also a trick to undo accidental checkboxes
# MP++ per checklist item in ToDo, bonus per CLI
multiplier = _.max([(_.reduce(task.checklist,((m,i)->m+(if i.completed then 1 else 0)),1)),1])
mpDelta = _.max([(multiplier), (.01 * user._statsComputed.maxMP * multiplier)])
mpDelta *= user._tmp.crit or 1
mpDelta *= -1 if direction is 'down' # unticking a todo
user.stats.mp += mpDelta
user.stats.mp = user._statsComputed.maxMP if user.stats.mp >= user._statsComputed.maxMP
user.stats.mp = 0 if user.stats.mp < 0 # BUT DO WE WANT THIS? SEE COMMIT DESCRIPTION
gainMP(_.max([(multiplier), (.01 * user._statsComputed.maxMP * multiplier)]) * if direction is 'down' then -1 else 1)
when 'reward'
# Don't adjust values for rewards
@@ -1186,6 +1183,12 @@ api.wrap = (user, main=true) ->
# Scoring
# ----------------------------------------------------------------------
gainMP: (delta) ->
delta *= user._tmp.crit or 1
user.stats.mp += delta
user.stats.mp = user._statsComputed.maxMP if user.stats.mp >= user._statsComputed.maxMP
user.stats.mp = 0 if user.stats.mp < 0
randomDrop: (modifiers, req) ->
{task} = modifiers