diff --git a/src/app/browser.coffee b/src/app/browser.coffee
index c954716d01..16d0536bc2 100644
--- a/src/app/browser.coffee
+++ b/src/app/browser.coffee
@@ -184,13 +184,14 @@ setupGrowlNotifications = (model) ->
statsNotification "+ #{showCoins(bonus)} Streak Bonus!"
model.del('_streakBonus')
+ user.on 'set', 'items.*', (item, after, before) ->
+ if item in ['armor','weapon','shield','head'] and parseInt(after) < parseInt(before)
+ item = 'helm' if item is 'head' # don't want to day "lost a head"
+ statsNotification " You died! Lost GP and #{item}.", "death"
+
user.on 'set', 'stats.lvl', (captures, args) ->
if captures > args
- if captures is 1 and args is 0
- statsNotification ' You died! Game over.', 'death'
- else
- statsNotification ' Level Up!', 'lvl'
-
+ statsNotification ' Level Up!', 'lvl'
module.exports.resetDom = (model) ->
DERBY.app.dom.clear()
diff --git a/src/app/character.coffee b/src/app/character.coffee
index 1384baede0..edecd2d889 100644
--- a/src/app/character.coffee
+++ b/src/app/character.coffee
@@ -10,28 +10,27 @@ derby = require 'derby'
module.exports.app = (appExports, model) ->
user = model.at '_user'
- revive = (batch) ->
+ appExports.revive = ->
# Reset stats
- batch.set 'stats.hp', 50
- batch.set 'stats.lvl', 1
- batch.set 'stats.gp', 0
- batch.set 'stats.exp', 0
+ user.set 'stats.hp', 50
+ user.set 'stats.exp', 0
+ user.set 'stats.gp', 0
- # Reset items
- batch.set 'items.armor', 0
- batch.set 'items.weapon', 0
- batch.set 'items.head', 0
- batch.set 'items.shield', 0
+ ## Lose a random item
+ loseThisItem = false
+ owned = user.get('items')
+ # unless they're already at 0-everything
+ if parseInt(owned.armor)>0 or parseInt(owned.head)>0 or parseInt(owned.shield)>0 or parseInt(owned.weapon)>0
+ console.log 'test'
+ # find a random item to lose
+ until loseThisItem
+ #candidate = {0:'items.armor', 1:'items.head', 2:'items.shield', 3:'items.weapon', 4:'stats.gp'}[Math.random()*5|0]
+ candidate = {0:'armor', 1:'head', 2:'shield', 3:'weapon'}[Math.random()*4|0]
+ loseThisItem = candidate if owned[candidate] > 0
+ user.set "items.#{loseThisItem}", 0
- # Reset item store
items.updateStore(model)
- appExports.revive = (e, el) ->
- batch = new BatchUpdate(model)
- batch.startTransaction()
- revive(batch)
- batch.commit()
-
appExports.reset = (e, el) ->
batch = new BatchUpdate(model)
batch.startTransaction()
@@ -39,7 +38,19 @@ module.exports.app = (appExports, model) ->
batch.set 'tasks', {}
_.each taskTypes, (type) -> batch.set "#{type}Ids", []
batch.set 'balance', 1 if user.get('balance') < 1 #only if they haven't manually bought tokens
- revive(batch)
+
+ # Reset stats
+ batch.set 'stats.hp', 50
+ batch.set 'stats.lvl', 1
+ batch.set 'stats.gp', 0
+ batch.set 'stats.exp', 0
+ # Reset items
+ batch.set 'items.armor', 0
+ batch.set 'items.weapon', 0
+ batch.set 'items.head', 0
+ batch.set 'items.shield', 0
+
+ items.updateStore(model)
batch.commit()
browser.resetDom(model)
diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee
index 4cad725ab0..fd976c1d68 100644
--- a/src/app/scoring.coffee
+++ b/src/app/scoring.coffee
@@ -207,13 +207,12 @@ updateStats = (model, newStats, batch) ->
obj = batch.obj()
# if user is dead, dont do anything
- return if obj.stats.lvl == 0
+ return if obj.stats.hp <= 0
if newStats.hp?
# Game Over
if newStats.hp <= 0
- obj.stats.lvl = 0 # signifies dead
- obj.stats.hp = 0
+ obj.stats.hp = 0 # signifies dead
return
else
obj.stats.hp = newStats.hp