From be643e5ce40f6db1f7cc4eef06b1d708a3c6721d Mon Sep 17 00:00:00 2001 From: Andrew Steele Date: Fri, 18 Jan 2013 12:12:40 -0500 Subject: [PATCH] Changing updateStats to use mass assignment of changes. --- src/app/scoring.coffee | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index 386b89e8cb..56f8f9ab1d 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -95,23 +95,25 @@ taskDeltaFormula = (currentValue, direction) -> updateStats = (stats) -> # if user is dead, dont do anything return if user.get('stats.lvl') == 0 - + + update = {} + if stats.hp? # game over if stats.hp <= 0 - user.set 'stats.lvl', 0 # this signifies dead - user.set 'stats.hp', 0 + update.lvl = 0 # this signifies dead + update.hp = 0 return else - user.set 'stats.hp', stats.hp + update.hp = stats.hp if stats.exp? # level up & carry-over exp tnl = user.get '_tnl' if stats.exp >= tnl stats.exp -= tnl - user.set 'stats.lvl', user.get('stats.lvl') + 1 - user.set 'stats.hp', 50 + update.lvl = user.get('stats.lvl') + 1 + update.hp = 50 if !user.get('items.itemsEnabled') and stats.exp >=15 user.set 'items.itemsEnabled', true $('ul.items').popover @@ -125,11 +127,13 @@ updateStats = (stats) -> " $('ul.items').popover 'show' - user.set 'stats.exp', stats.exp + update.exp = stats.exp if stats.money? money = 0.0 if (!money? or money<0) - user.set 'stats.money', stats.money + update.money = stats.money + + user.set 'stats', update # {taskId} task you want to score # {direction} 'up' or 'down'