mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 04:29:40 +00:00
classes: move item-store sorting from web to shard (so we can share with
mobile)
This commit is contained in:
parent
ba6e416e4d
commit
665166507e
2 changed files with 43 additions and 19 deletions
36
dist/habitrpg-shared.js
vendored
36
dist/habitrpg-shared.js
vendored
|
|
@ -11259,25 +11259,41 @@ try {
|
|||
|
||||
module.exports.updateStore = function(user) {
|
||||
var changes;
|
||||
changes = {};
|
||||
changes = [];
|
||||
_.each(['weapon', 'armor', 'shield', 'head'], function(type) {
|
||||
var i;
|
||||
i = module.exports.getItem(user, type).index;
|
||||
return changes[type] = items.gear.flat["" + type + "_" + user.stats["class"] + "_" + (+i + 1)] || {
|
||||
return changes.push(items.gear.flat["" + type + "_" + user.stats["class"] + "_" + (+i + 1)] || {
|
||||
hide: true
|
||||
};
|
||||
});
|
||||
});
|
||||
_.defaults(changes, _.reduce(_.where(items.gear.flat, {
|
||||
_.defaults(changes, _.transform(_.where(items.gear.flat, {
|
||||
klass: 'special'
|
||||
}), function(m, v) {
|
||||
if ((typeof v.canOwn === "function" ? v.canOwn(user) : void 0) && !user.items.gear.owned[v.key]) {
|
||||
m[v.key] = v;
|
||||
return m.push(v);
|
||||
}
|
||||
return m;
|
||||
}, {}));
|
||||
changes.potion = items.potion;
|
||||
changes.reroll = items.reroll;
|
||||
return changes;
|
||||
}));
|
||||
changes.push(items.potion);
|
||||
changes.push(items.reroll);
|
||||
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;
|
||||
case 'reroll':
|
||||
return 6;
|
||||
default:
|
||||
return 7;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -452,20 +452,28 @@ module.exports.buyItem = (user, item) ->
|
|||
update store
|
||||
###
|
||||
module.exports.updateStore = (user) ->
|
||||
changes = {}
|
||||
changes = []
|
||||
_.each ['weapon', 'armor', 'shield', 'head'], (type) ->
|
||||
i = module.exports.getItem(user, type).index
|
||||
changes[type] = items.gear.flat["#{type}_#{user.stats.class}_#{+i + 1}"] or {hide:true}
|
||||
changes.push items.gear.flat["#{type}_#{user.stats.class}_#{+i + 1}"] or {hide:true}
|
||||
|
||||
# Add special items (contrib gear, backer gear, etc)
|
||||
_.defaults changes, _.reduce(_.where(items.gear.flat, {klass:'special'}), (m,v) ->
|
||||
m[v.key] = v if v.canOwn?(user) && !user.items.gear.owned[v.key]
|
||||
m
|
||||
, {})
|
||||
_.defaults changes, _.transform _.where(items.gear.flat, {klass:'special'}), (m,v) ->
|
||||
m.push v if v.canOwn?(user) && !user.items.gear.owned[v.key]
|
||||
|
||||
changes.potion = items.potion
|
||||
changes.reroll = items.reroll
|
||||
changes
|
||||
changes.push items.potion
|
||||
changes.push items.reroll
|
||||
|
||||
# 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
|
||||
when 'reroll' then 6
|
||||
else 7
|
||||
|
||||
###
|
||||
Gets an item, and caps max to the last item in its array
|
||||
|
|
|
|||
Loading…
Reference in a new issue