Merge pull request #305 from Alys/deathGear-Sep10

prevent off-class items and free items being lost on death
This commit is contained in:
Alice Harris
2014-12-27 08:31:50 +10:00
3 changed files with 6764 additions and 6710 deletions
+6743 -6701
View File
File diff suppressed because it is too large Load Diff
+13 -5
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,10 +410,18 @@ 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 losing a free one. The only exception is that the weapon_warrior_0 free item can be lost so that a new player who dies before buying any gear does experience equipment loss.
# 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
gearOwned = user.items.gear.owned.toObject?() or user.items.gear.owned
losableItems = {}
_.each gearOwned, (v,k) ->
if v
itm = content.gear.flat[''+k]
if itm
if (itm.value > 0 || k == 'weapon_warrior_0') && ( itm.klass == cl || ( itm.klass == 'special' && (! itm.specialClass || itm.specialClass == cl) ) )
losableItems[''+k]=''+k
lostItem = user.fns.randomVal losableItems
if item = content.gear.flat[lostItem]
user.items.gear.owned[lostItem] = false
user.items.gear.equipped[item.type] = "#{item.type}_base_0" if user.items.gear.equipped[item.type] is lostItem
@@ -1306,7 +1314,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
+8 -4
View File
@@ -196,15 +196,19 @@ describe 'User', ->
it "doesn't break unbreakables", ->
ce = shared.countExists
user = newUser()
# breakables (includes default weapon_warrior_0):
user.items.gear.owned['shield_warrior_1'] = true
# unbreakables because off-class or 0 value:
user.items.gear.owned['shield_rogue_1'] = true
user.items.gear.owned['head_special_nye'] = true
expect(ce user.items.gear.owned).to.be 3
expect(ce user.items.gear.owned).to.be 4
user.ops.revive()
expect(ce(user.items.gear.owned)).to.be 3
user.ops.revive()
expect(ce(user.items.gear.owned)).to.be 2
user.ops.revive()
expect(ce(user.items.gear.owned)).to.be 1
user.ops.revive()
expect(ce(user.items.gear.owned)).to.be 0
expect(ce(user.items.gear.owned)).to.be 2
expect(user.items.gear.owned).to.eql { weapon_warrior_0: false, shield_warrior_1: false, shield_rogue_1: true, head_special_nye: true }
it "handles event items", ->
shared.content.gear.flat.head_special_nye.event.start = '2012-01-01'