From 58a2f2de67e6ac867c00e985c5acc06540688a34 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 15 Dec 2013 22:37:40 -0700 Subject: [PATCH] move updateStore back outside of user.fns. It's causing issues there, need to investigate --- dist/habitrpg-shared.js | 85 +++++++++++++++++++++++------------------ script/index.coffee | 46 ++++++++++++---------- 2 files changed, 72 insertions(+), 59 deletions(-) diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index 125fd6e478..cfaab18a9c 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -10648,6 +10648,53 @@ var process=require("__browserify_process");(function() { return newHistory; }; + /* + Update the in-browser store with new gear. FIXME this was in user.fns, but it was causing strange issues there + */ + + + api.updateStore = function(user) { + var changes; + if (!user) { + return; + } + changes = []; + _.each(['weapon', 'armor', 'shield', 'head'], function(type) { + var found; + found = _.find(content.gear.tree[type][user.stats["class"]], function(item) { + return !user.items.gear.owned[item.key]; + }); + if (found) { + changes.push(found); + } + return true; + }); + _.defaults(changes, _.transform(_.where(content.gear.flat, { + klass: 'special' + }), function(m, v) { + if ((typeof v.canOwn === "function" ? v.canOwn(user) : void 0) && !user.items.gear.owned[v.key]) { + return m.push(v); + } + })); + changes.push(content.potion); + return _.sortBy(changes, function(item) { + switch (item.type) { + case 'weapon': + return 1; + case 'armor': + return 2; + case 'head': + return 3; + case 'shield': + return 4; + case 'potion': + return 5; + default: + return 6; + } + }); + }; + /* ------------------------------------------------------ Content @@ -11546,44 +11593,6 @@ var process=require("__browserify_process");(function() { } return item; }, - updateStore: function() { - var changes; - changes = []; - _.each(['weapon', 'armor', 'shield', 'head'], function(type) { - var found; - found = _.find(content.gear.tree[type][user.stats["class"]], function(item) { - return !user.items.gear.owned[item.key]; - }); - if (found) { - changes.push(found); - } - return true; - }); - _.defaults(changes, _.transform(_.where(content.gear.flat, { - klass: 'special' - }), function(m, v) { - if ((typeof v.canOwn === "function" ? v.canOwn(user) : void 0) && !user.items.gear.owned[v.key]) { - return m.push(v); - } - })); - changes.push(content.potion); - return _.sortBy(changes, function(item) { - switch (item.type) { - case 'weapon': - return 1; - case 'armor': - return 2; - case 'head': - return 3; - case 'shield': - return 4; - case 'potion': - return 5; - default: - return 6; - } - }); - }, handleTwoHanded: function(item, type) { var message, weapon, _ref; if (type == null) { diff --git a/script/index.coffee b/script/index.coffee index 839543a2a7..036dc6dc0a 100644 --- a/script/index.coffee +++ b/script/index.coffee @@ -105,6 +105,31 @@ preenHistory = (history) -> newHistory +### + Update the in-browser store with new gear. FIXME this was in user.fns, but it was causing strange issues there +### +api.updateStore = (user) -> + return unless user + changes = [] + _.each ['weapon', 'armor', 'shield', 'head'], (type) -> + found = _.find content.gear.tree[type][user.stats.class], (item) -> + !user.items.gear.owned[item.key] + changes.push(found) if found + true + # Add special items (contrib gear, backer gear, etc) + _.defaults changes, _.transform _.where(content.gear.flat, {klass:'special'}), (m,v) -> + m.push v if v.canOwn?(user) && !user.items.gear.owned[v.key] + changes.push content.potion + # Return sorted store (array) + _.sortBy changes, (item) -> + switch item.type + when 'weapon' then 1 + when 'armor' then 2 + when 'head' then 3 + when 'shield' then 4 + when 'potion' then 5 + else 6 + ### ------------------------------------------------------ Content @@ -733,27 +758,6 @@ api.wrap = (user) -> return content.gear.flat["#{type}_base_0"] unless item item - updateStore: -> - changes = [] - _.each ['weapon', 'armor', 'shield', 'head'], (type) -> - found = _.find content.gear.tree[type][user.stats.class], (item) -> - !user.items.gear.owned[item.key] - changes.push(found) if found - true - # Add special items (contrib gear, backer gear, etc) - _.defaults changes, _.transform _.where(content.gear.flat, {klass:'special'}), (m,v) -> - m.push v if v.canOwn?(user) && !user.items.gear.owned[v.key] - changes.push content.potion - # Return sorted store (array) - _.sortBy changes, (item) -> - switch item.type - when 'weapon' then 1 - when 'armor' then 2 - when 'head' then 3 - when 'shield' then 4 - when 'potion' then 5 - else 6 - handleTwoHanded: (item, type='equipped') -> # If they're buying a shield and wearing a staff, dequip the staff if item.type is "shield" and (weapon = content.gear.flat[user.items.gear[type].weapon])?.twoHanded