habitica/website/common/script/count.js

75 lines
1.4 KiB
JavaScript
Raw Normal View History

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