Files
habitica/website/common/script/count.js
Keith Holliday 9c9b67aa9d Keys kennel fixes (#9848)
* Show keys to pets immediately

* Ensured keys to pets dissapear after use

* Added resdirect to stable after purchase

* Added mount check and updated keys to mounts and to both

* Added api calls

* Added check for beastmaster progress

* Added mount check for release mounts. Added pets and mount check to release both

* Added actions

* Added catch to common tests

* Added beast count and reload

* Removed extra console log
2018-03-02 15:30:11 -06:00

86 lines
1.6 KiB
JavaScript

import each from 'lodash/each';
import filter from 'lodash/filter';
import keys from 'lodash/keys';
import size from 'lodash/size';
import content from './content/index';
const DROP_ANIMALS = keys(content.pets);
function beastMasterProgress (pets = {}) {
let count = 0;
each(DROP_ANIMALS, (animal) => {
if (pets[animal] > 0 || pets[animal] === -1)
count++;
});
return count;
}
function beastCount (pets = {}) {
let count = 0;
each(DROP_ANIMALS, (animal) => {
if (pets[animal] > 0) count++;
});
return count;
}
function dropPetsCurrentlyOwned (pets = {}) {
let count = 0;
each(DROP_ANIMALS, (animal) => {
if (pets[animal] > 0)
count++;
});
return count;
}
function mountMasterProgress (mounts = {}) {
let count = 0;
each(DROP_ANIMALS, (animal) => {
if (mounts[animal])
count++;
});
return count;
}
function remainingGearInSet (userGear = {}, set) {
let gear = filter(content.gear.flat, (item) => {
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) => {
let categoryMatches = quest.category === category;
let hasQuest = userQuests[quest.key];
return categoryMatches && hasQuest;
});
let count = size(quests);
return count;
}
module.exports = {
beastMasterProgress,
beastCount,
dropPetsCurrentlyOwned,
mountMasterProgress,
remainingGearInSet,
questsOfCategory,
};