move updateStore back outside of user.fns. It's causing issues there,

need to investigate
This commit is contained in:
Tyler Renelle 2013-12-15 22:37:40 -07:00
parent 5d390561d2
commit 58a2f2de67
2 changed files with 72 additions and 59 deletions

View file

@ -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) {

View file

@ -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