Skip to content

Commit

Permalink
Merge pull request #115 from Andrew565/master
Browse files Browse the repository at this point in the history
Updating updateStats for mass update
  • Loading branch information
lefnire committed Jan 18, 2013
2 parents 83346ed + be643e5 commit 7c5c450
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/app/scoring.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -125,11 +127,13 @@ updateStats = (stats) ->
</div>"
$('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'
Expand Down

0 comments on commit 7c5c450

Please sign in to comment.