diff --git a/test/common/libs/setDebuffPotionItems.test.js b/test/common/libs/setDebuffPotionItems.test.js index f3313b85b0..78d3379905 100644 --- a/test/common/libs/setDebuffPotionItems.test.js +++ b/test/common/libs/setDebuffPotionItems.test.js @@ -16,7 +16,7 @@ describe('setDebuffPotionItems', () => { user.stats.buffs.spookySparkles = true; const previousPinnedItemsLength = user.pinnedItems.length; - let result = setDebuffPotionItems(user); + const result = setDebuffPotionItems(user); expect(result.pinnedItems.length).to.be.greaterThan(previousPinnedItemsLength); }); diff --git a/website/client/src/components/tasks/column.vue b/website/client/src/components/tasks/column.vue index ca4e47392e..06f3166f88 100644 --- a/website/client/src/components/tasks/column.vue +++ b/website/client/src/components/tasks/column.vue @@ -335,7 +335,6 @@ import BuyQuestModal from '@/components/shops/quests/buyQuestModal.vue'; import notifications from '@/mixins/notifications'; import { shouldDo } from '@/../../common/script/cron'; import inAppRewards from '@/../../common/script/libs/inAppRewards'; -import spells from '@/../../common/script/content/spells'; import taskDefaults from '@/../../common/script/libs/taskDefaults'; import { diff --git a/website/common/script/content/spells.js b/website/common/script/content/spells.js index 48c82c695e..2f06352300 100644 --- a/website/common/script/content/spells.js +++ b/website/common/script/content/spells.js @@ -2,6 +2,7 @@ import each from 'lodash/each'; import t from './translation'; import { NotAuthorized } from '../libs/errors'; import statsComputed from '../libs/statsComputed'; // eslint-disable-line import/no-cycle +import setDebuffPotionItems from '../libs/setDebuffPotionItems'; // eslint-disable-line import/no-cycle import crit from '../fns/crit'; // eslint-disable-line import/no-cycle import updateStats from '../fns/updateStats'; @@ -287,6 +288,7 @@ spells.special = { if (!target.achievements.snowball) target.achievements.snowball = 0; target.achievements.snowball += 1; user.items.special.snowball -= 1; + setDebuffPotionItems(user); }, }, salt: { @@ -300,8 +302,7 @@ spells.special = { cast (user) { user.stats.buffs.snowball = false; user.stats.gp -= 5; - // Remove antidote from pinned items - user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.salt')); + setDebuffPotionItems(user); }, }, spookySparkles: { @@ -320,6 +321,7 @@ spells.special = { if (!target.achievements.spookySparkles) target.achievements.spookySparkles = 0; target.achievements.spookySparkles += 1; user.items.special.spookySparkles -= 1; + setDebuffPotionItems(user); }, }, opaquePotion: { @@ -333,8 +335,7 @@ spells.special = { cast (user) { user.stats.buffs.spookySparkles = false; user.stats.gp -= 5; - // Remove antidote from pinned items - user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.opaquePotion')); + setDebuffPotionItems(user); }, }, shinySeed: { @@ -353,6 +354,7 @@ spells.special = { if (!target.achievements.shinySeed) target.achievements.shinySeed = 0; target.achievements.shinySeed += 1; user.items.special.shinySeed -= 1; + setDebuffPotionItems(user); }, }, petalFreePotion: { @@ -366,8 +368,7 @@ spells.special = { cast (user) { user.stats.buffs.shinySeed = false; user.stats.gp -= 5; - // Remove antidote from pinned items - user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.petalFreePotion')); + setDebuffPotionItems(user); }, }, seafoam: { @@ -386,6 +387,7 @@ spells.special = { if (!target.achievements.seafoam) target.achievements.seafoam = 0; target.achievements.seafoam += 1; user.items.special.seafoam -= 1; + setDebuffPotionItems(user); }, }, sand: { @@ -399,7 +401,7 @@ spells.special = { cast (user) { user.stats.buffs.seafoam = false; user.stats.gp -= 5; - user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.sand')); + setDebuffPotionItems(user); }, }, nye: { diff --git a/website/common/script/index.js b/website/common/script/index.js index da23f74ee7..d8ae34c2f6 100644 --- a/website/common/script/index.js +++ b/website/common/script/index.js @@ -46,10 +46,8 @@ import updateStore from './libs/updateStore'; import inAppRewards from './libs/inAppRewards'; import setDebuffPotionItems from './libs/setDebuffPotionItems'; -api.setDebuffPotionItems = setDebuffPotionItems; import getDebuffPotionItems from './libs/getDebuffPotionItems'; -api.getDebuffPotionItems = getDebuffPotionItems; import uuid from './libs/uuid'; @@ -164,6 +162,9 @@ api.shops = shops; api.achievements = achievements; api.randomVal = randomVal; api.hasClass = hasClass; +api.setDebuffPotionItems = setDebuffPotionItems; +api.getDebuffPotionItems = getDebuffPotionItems; + api.fns = { autoAllocate, diff --git a/website/common/script/libs/getDebuffPotionItems.js b/website/common/script/libs/getDebuffPotionItems.js index 8417f437e9..07e997d6ca 100644 --- a/website/common/script/libs/getDebuffPotionItems.js +++ b/website/common/script/libs/getDebuffPotionItems.js @@ -1,13 +1,13 @@ import { TRANSFORMATION_DEBUFFS_LIST } from '../constants'; -module.exports = function getDebuffPotionItems (user) { +export default function getDebuffPotionItems (user) { const items = []; const userBuffs = user.stats.buffs; if (user) { - for (let key in TRANSFORMATION_DEBUFFS_LIST) { + for (const key in TRANSFORMATION_DEBUFFS_LIST) { if (userBuffs[key]) { - let debuff = TRANSFORMATION_DEBUFFS_LIST[key]; + const debuff = TRANSFORMATION_DEBUFFS_LIST[key]; const item = { path: `spells.special.${debuff}`, type: 'debuffPotion', @@ -15,8 +15,7 @@ module.exports = function getDebuffPotionItems (user) { items.push(item); } } - - - return items; } -}; + + return items; +} diff --git a/website/common/script/libs/getItemInfo.js b/website/common/script/libs/getItemInfo.js index 16228f5f16..9b588dbffd 100644 --- a/website/common/script/libs/getItemInfo.js +++ b/website/common/script/libs/getItemInfo.js @@ -191,7 +191,7 @@ export default function getItemInfo (user, type, item, officialPinnedItems, lang currency: 'gold', locked: false, purchaseType: 'debuffPotion', - class: `inventory_special_${item.key}`, + class: `shop_${item.key}`, path: `spells.special.${item.key}`, pinType: 'debuffPotion', }; diff --git a/website/common/script/libs/setDebuffPotionItems.js b/website/common/script/libs/setDebuffPotionItems.js index 5386698252..3fe6afb1e2 100644 --- a/website/common/script/libs/setDebuffPotionItems.js +++ b/website/common/script/libs/setDebuffPotionItems.js @@ -1,7 +1,13 @@ import getDebuffPotionItems from './getDebuffPotionItems'; +function clearDebuffPotion (user) { + return user.pinnedItems.filter(item => item.type !== 'debuffPotion'); +} + + +export default function setDebuffPotionItems (user) { + user.pinnedItems = clearDebuffPotion(user); -module.exports = function setDebuffPotionItems (user) { const debuffPotionItems = getDebuffPotionItems(user); if (debuffPotionItems.length) { @@ -18,13 +24,7 @@ module.exports = function setDebuffPotionItems (user) { if (!isUserHaveDebuffInPinnedItems) { user.pinnedItems.push(...debuffPotionItems); } - } else { - user.pinnedItems = user.pinnedItems.filter(item => { - return item.type !== 'debuffPotion'; - }); } return user; -}; - - +} diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index a377dfc7ba..231402a453 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -11,7 +11,7 @@ import { } from '../models/group'; import apiError from './apiError'; -const partyMembersFields = 'profile.name stats achievements items.special notifications flags'; +const partyMembersFields = 'profile.name stats achievements items.special notifications flags pinnedItems'; // Excluding notifications and flags from the list of public fields to return. const partyMembersPublicFields = 'profile.name stats achievements items.special'; @@ -98,7 +98,7 @@ async function castPartySpell (req, party, partyMembers, user, spell, quantity = return partyMembers; } -async function castUserSpell (res, req, party, partyMember, targetId, user, spell, quantity = 1) { +async function castUserSpell (res, req, party, partyMembers, targetId, user, spell, quantity = 1) { if (!party && (!targetId || user._id === targetId)) { partyMembers = user; // eslint-disable-line no-param-reassign } else {