habitica/website/common/script/count.js

74 lines
1.5 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);
2019-10-01 15:53:48 +00:00
export function beastMasterProgress (pets = {}) {
2015-11-15 14:16:55 +00:00
let count = 0;
2019-10-08 14:57:10 +00:00
each(DROP_ANIMALS, animal => {
2019-10-09 14:51:17 +00:00
if (pets[animal] > 0 || pets[animal] === -1) count += 1;
});
return count;
}
2019-10-01 15:53:48 +00:00
export function beastCount (pets = {}) {
let count = 0;
2019-10-08 14:57:10 +00:00
each(DROP_ANIMALS, animal => {
2019-10-09 14:51:17 +00:00
if (pets[animal] > 0) count += 1;
});
return count;
}
2019-10-01 15:53:48 +00:00
export function dropPetsCurrentlyOwned (pets = {}) {
2015-11-15 14:16:55 +00:00
let count = 0;
2019-10-08 14:57:10 +00:00
each(DROP_ANIMALS, animal => {
2019-10-09 14:51:17 +00:00
if (pets[animal] > 0) count += 1;
});
return count;
}
2019-10-01 15:53:48 +00:00
export function mountMasterProgress (mounts = {}) {
2015-11-15 14:16:55 +00:00
let count = 0;
2019-10-08 14:57:10 +00:00
each(DROP_ANIMALS, animal => {
2019-10-09 14:51:17 +00:00
if (mounts[animal]) count += 1;
});
return count;
}
2019-10-01 15:53:48 +00:00
export function remainingGearInSet (userGear = {}, set) {
2019-10-08 14:57:10 +00:00
const gear = filter(content.gear.flat, item => {
const setMatches = item.klass === set;
const hasItem = userGear[item.key];
return setMatches && !hasItem;
});
2019-10-08 14:57:10 +00:00
const count = size(gear);
return count;
}
2019-10-01 15:53:48 +00:00
export function questsOfCategory (userQuests = {}, category) {
2019-10-08 14:57:10 +00:00
const quests = filter(content.quests, quest => {
const categoryMatches = quest.category === category;
const hasQuest = userQuests[quest.key];
2015-08-10 18:42:36 +00:00
return categoryMatches && hasQuest;
});
2019-10-08 14:57:10 +00:00
const count = size(quests);
2015-08-10 18:42:36 +00:00
return count;
2019-10-08 14:57:10 +00:00
}