prevent off-class items and free items being lost on death

This commit is contained in:
Alice Harris
2014-09-10 14:06:01 +10:00
parent 971ea8a495
commit 87f51913d0
2 changed files with 184 additions and 1001 deletions
+169 -997
View File
File diff suppressed because it is too large Load Diff
+15 -4
View File
@@ -401,7 +401,7 @@ api.wrap = (user, main=true) ->
revive: (req, cb) ->
return cb?({code:400, message: "Cannot revive if not dead"}) unless user.stats.hp <= 0
# Reset stats
# Reset stats after death
_.merge user.stats, {hp:50, exp:0, gp:0}
user.stats.lvl-- if user.stats.lvl > 1
@@ -410,9 +410,20 @@ api.wrap = (user, main=true) ->
user.stats[lostStat]-- if lostStat
# Lose a gear piece
# Note, they can actually lose item weapon_*_0 - it's 0 to buy back, no big deal
# Free items (value:0) cannot be lost to avoid "pay to win". Subscribers have more free (Mystery) items and so would have a higher chance of loosing a free one.
# Note ""+k string-casting. Without this, when run on the server Mongoose returns funny objects
lostItem = user.fns.randomVal _.reduce(user.items.gear.owned, ((m,v,k)->m[''+k]=''+k if v;m), {})
cl = user.stats.class
lostItem = user.fns.randomVal _.reduce(user.items.gear.owned, ((m,v,k)->
if v && k != 'toObject'
# 'toObject' appears as first key when run on server. No idea why.
itm = content.gear.flat[''+k]
if itm
if itm.value > 0 && ( itm.klass == cl || ( itm.klass == 'special' && (! itm.specialClass || itm.specialClass == cl) ) )
m[''+k]=''+k
# else
# console.log "Can't get item for " + k
# # in case other wierd things like 'toObject' turn up
m), {})
if item = content.gear.flat[lostItem]
user.items.gear.owned[lostItem] = false
@@ -1306,7 +1317,7 @@ api.wrap = (user, main=true) ->
)()]++
updateStats: (stats, req) ->
# Game Over
# Game Over (death)
return user.stats.hp=0 if stats.hp <= 0
user.stats.hp = stats.hp