less harsh death. Now you lose 1 random item & all GP, but no levels.

see #223
This commit is contained in:
Tyler Renelle
2013-05-10 11:13:34 +01:00
parent 016bb08572
commit 164f8532e9
3 changed files with 37 additions and 26 deletions
+6 -5
View File
@@ -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 "<i class='icon-death'></i> 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 '<i class="icon-death"></i> You died! Game over.', 'death'
else
statsNotification '<i class="icon-chevron-up"></i> Level Up!', 'lvl'
statsNotification '<i class="icon-chevron-up"></i> Level Up!', 'lvl'
module.exports.resetDom = (model) ->
DERBY.app.dom.clear()
+29 -18
View File
@@ -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)
+2 -3
View File
@@ -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