diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index 74b136fb04..2eb573b92d 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -14147,7 +14147,7 @@ api.wrap = function(user, main) { return typeof cb === "function" ? cb(null, {}) : void 0; }, revive: function(req, cb) { - var cl, item, lostItem, lostStat; + var cl, gearOwned, item, losableItems, lostItem, lostStat; _.merge(user.stats, { hp: 50, exp: 0, @@ -14166,18 +14166,20 @@ api.wrap = function(user, main) { user.stats[lostStat]--; } cl = user.stats["class"]; - lostItem = user.fns.randomVal(_.reduce(user.items.gear.owned, (function(m, v, k) { + gearOwned = typeof user.items.gear.owned.toObject === "undefined" ? user.items.gear.owned : user.items.gear.owned.toObject(); + losableItems = {}; + _.each(gearOwned, function(v, k) { var itm; - if (v && k !== 'toObject') { + 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)))) { - m['' + k] = '' + k; + return losableItems['' + k] = '' + k; } } } - return m; - }), {})); + }); + lostItem = user.fns.randomVal(losableItems); if (item = content.gear.flat[lostItem]) { user.items.gear.owned[lostItem] = false; if (user.items.gear.equipped[item.type] === lostItem) { @@ -15657,4 +15659,4 @@ api.wrap = function(user, main) { }).call(this,require("/Users/lefnire/Dropbox/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js")) -},{"./content.coffee":5,"./i18n.coffee":6,"/Users/lefnire/Dropbox/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":2,"lodash":3,"moment":4}]},{},[1]) \ No newline at end of file +},{"./content.coffee":5,"./i18n.coffee":6,"/Users/lefnire/Dropbox/Sites/habitrpg/modules/habitrpg-shared/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":2,"lodash":3,"moment":4}]},{},[1]) diff --git a/script/index.coffee b/script/index.coffee index c1f6dd77e6..606da6f649 100644 --- a/script/index.coffee +++ b/script/index.coffee @@ -411,20 +411,16 @@ api.wrap = (user, main=true) -> # Lose a gear piece # 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 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. + gearOwned = if (typeof user.items.gear.owned.toObject is "undefined") then user.items.gear.owned else user.items.gear.owned.toObject() + 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) ) ) - m[''+k]=''+k - # else - # console.log "Can't get item for " + k - # # in case other wierd things like 'toObject' turn up - m), {}) - + 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