habitica-self-host/common/script/count.js

72 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-11-15 14:16:55 +00:00
import _ from 'lodash';
import content from './content/index';
2015-11-15 14:16:55 +00:00
const DROP_ANIMALS = _.keys(content.pets);
2015-11-15 14:16:55 +00:00
function beastMasterProgress (pets) {
let count = 0;
2015-11-15 14:16:55 +00:00
_(DROP_ANIMALS).each((animal) => {
if (pets[animal] > 0 || pets[animal] === -1)
count++;
}).value();
return count;
}
2015-11-15 14:16:55 +00:00
function dropPetsCurrentlyOwned (pets) {
let count = 0;
2015-11-15 14:16:55 +00:00
_(DROP_ANIMALS).each((animal) => {
if (pets[animal] > 0)
count++;
}).value();
return count;
}
2015-11-15 14:16:55 +00:00
function mountMasterProgress (mounts) {
let count = 0;
_(DROP_ANIMALS).each((animal) => {
if (mounts[animal])
2015-11-15 14:16:55 +00:00
count++;
}).value();
return count;
}
2015-11-15 14:16:55 +00:00
function remainingGearInSet (userGear, set) {
let gear = _.filter(content.gear.flat, (item) => {
let setMatches = item.klass === set;
let hasItem = userGear[item.key];
return setMatches && !hasItem;
});
2015-11-15 14:16:55 +00:00
let count = _.size(gear);
return count;
}
2015-11-15 14:16:55 +00:00
function questsOfCategory (userQuests, category) {
let quests = _.filter(content.quests, (quest) => {
let categoryMatches = quest.category === category;
let hasQuest = userQuests[quest.key];
2015-08-10 18:42:36 +00:00
return categoryMatches && hasQuest;
});
2015-11-15 14:16:55 +00:00
let count = _.size(quests);
2015-08-10 18:42:36 +00:00
return count;
}
2015-11-15 14:16:55 +00:00
export default {
beastMasterProgress,
dropPetsCurrentlyOwned,
mountMasterProgress,
remainingGearInSet,
questsOfCategory,
};