Files
habitica/common/script/count.js
Blade Barringer b1519eed14 fix: Display beastmaster count even if member route returned no items
Because of this line:
f1286762a8/website/server/controllers/api-v3/members.js (L53)

We minimize any empty objects, which causes the statCalc methods to fail
2016-05-23 21:47:42 -05:00

77 lines
1.3 KiB
JavaScript

import {
each,
filter,
keys,
size,
} from 'lodash';
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 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,
dropPetsCurrentlyOwned,
mountMasterProgress,
remainingGearInSet,
questsOfCategory,
};