Files
habitica/common/script/fns/ultimateGear.js
Matteo Pagliazzi bb6f0f4252 split user.fns
2016-03-08 18:58:39 +01:00

34 lines
1.2 KiB
JavaScript

import content from '../content/index';
import _ from 'lodash';
module.exports = function(user) {
var base, owned;
owned = typeof window !== "undefined" && window !== null ? user.items.gear.owned : user.items.gear.owned.toObject();
if ((base = user.achievements).ultimateGearSets == null) {
base.ultimateGearSets = {
healer: false,
wizard: false,
rogue: false,
warrior: false
};
}
content.classes.forEach(function(klass) {
if (user.achievements.ultimateGearSets[klass] !== true) {
return user.achievements.ultimateGearSets[klass] = _.reduce(['armor', 'shield', 'head', 'weapon'], function(soFarGood, type) {
var found;
found = _.find(content.gear.tree[type][klass], {
last: true
});
return soFarGood && (!found || owned[found.key] === true);
}, true);
}
});
if (typeof user.markModified === "function") {
user.markModified('achievements.ultimateGearSets');
}
if (_.contains(user.achievements.ultimateGearSets, true) && user.flags.armoireEnabled !== true) {
user.flags.armoireEnabled = true;
return typeof user.markModified === "function" ? user.markModified('flags') : void 0;
}
};