habitica/common/script/count.js

77 lines
1.3 KiB
JavaScript
Raw Normal View History

import {
each,
filter,
keys,
size,
} from 'lodash';
2015-11-15 14:16:55 +00:00
import content from './content/index';
const DROP_ANIMALS = keys(content.pets);
2015-11-15 14:16:55 +00:00
function beastMasterProgress (pets) {
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;
}
2015-11-15 14:16:55 +00:00
function dropPetsCurrentlyOwned (pets) {
let count = 0;
each(DROP_ANIMALS, (animal) => {
2015-11-15 14:16:55 +00:00
if (pets[animal] > 0)
count++;
});
return count;
}
2015-11-15 14:16:55 +00:00
function mountMasterProgress (mounts) {
let count = 0;
each(DROP_ANIMALS, (animal) => {
if (mounts[animal])
2015-11-15 14:16:55 +00:00
count++;
});
return count;
}
2015-11-15 14:16:55 +00:00
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;
}
2015-11-15 14:16:55 +00:00
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,
};