mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
31 lines
748 B
JavaScript
31 lines
748 B
JavaScript
import getDebuffPotionItems from './getDebuffPotionItems';
|
|
|
|
|
|
module.exports = function setDebuffPotionItems (user) {
|
|
const debuffPotionItems = getDebuffPotionItems(user);
|
|
|
|
if (debuffPotionItems.length) {
|
|
let isPresent = false;
|
|
const isUserHaveDebuffInPinnedItems = user.pinnedItems.find(pinnedItem => {
|
|
debuffPotionItems.forEach(debuffPotion => {
|
|
if (!isPresent) {
|
|
isPresent = debuffPotion.path === pinnedItem.path;
|
|
}
|
|
});
|
|
return isPresent;
|
|
});
|
|
|
|
if (!isUserHaveDebuffInPinnedItems) {
|
|
user.pinnedItems.push(...debuffPotionItems);
|
|
}
|
|
} else {
|
|
user.pinnedItems = user.pinnedItems.filter(item => {
|
|
return item.type !== 'debuffPotion';
|
|
});
|
|
}
|
|
|
|
return user;
|
|
};
|
|
|
|
|