- Rewrite exports of debuffPotion functions
- Force clear debuffPotions in setDebuffPotionItems to make the same behavior as in develop branch
- Change class of debuffPotion items to shop_{key}
- Resolve lint warnings
This commit is contained in:
Xaz16
2019-10-29 00:27:41 +03:00
parent 60a12e8090
commit aedabd2266
8 changed files with 30 additions and 29 deletions

View File

@@ -16,7 +16,7 @@ describe('setDebuffPotionItems', () => {
user.stats.buffs.spookySparkles = true; user.stats.buffs.spookySparkles = true;
const previousPinnedItemsLength = user.pinnedItems.length; const previousPinnedItemsLength = user.pinnedItems.length;
let result = setDebuffPotionItems(user); const result = setDebuffPotionItems(user);
expect(result.pinnedItems.length).to.be.greaterThan(previousPinnedItemsLength); expect(result.pinnedItems.length).to.be.greaterThan(previousPinnedItemsLength);
}); });

View File

@@ -335,7 +335,6 @@ import BuyQuestModal from '@/components/shops/quests/buyQuestModal.vue';
import notifications from '@/mixins/notifications'; import notifications from '@/mixins/notifications';
import { shouldDo } from '@/../../common/script/cron'; import { shouldDo } from '@/../../common/script/cron';
import inAppRewards from '@/../../common/script/libs/inAppRewards'; import inAppRewards from '@/../../common/script/libs/inAppRewards';
import spells from '@/../../common/script/content/spells';
import taskDefaults from '@/../../common/script/libs/taskDefaults'; import taskDefaults from '@/../../common/script/libs/taskDefaults';
import { import {

View File

@@ -2,6 +2,7 @@ import each from 'lodash/each';
import t from './translation'; import t from './translation';
import { NotAuthorized } from '../libs/errors'; import { NotAuthorized } from '../libs/errors';
import statsComputed from '../libs/statsComputed'; // eslint-disable-line import/no-cycle 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 crit from '../fns/crit'; // eslint-disable-line import/no-cycle
import updateStats from '../fns/updateStats'; import updateStats from '../fns/updateStats';
@@ -287,6 +288,7 @@ spells.special = {
if (!target.achievements.snowball) target.achievements.snowball = 0; if (!target.achievements.snowball) target.achievements.snowball = 0;
target.achievements.snowball += 1; target.achievements.snowball += 1;
user.items.special.snowball -= 1; user.items.special.snowball -= 1;
setDebuffPotionItems(user);
}, },
}, },
salt: { salt: {
@@ -300,8 +302,7 @@ spells.special = {
cast (user) { cast (user) {
user.stats.buffs.snowball = false; user.stats.buffs.snowball = false;
user.stats.gp -= 5; user.stats.gp -= 5;
// Remove antidote from pinned items setDebuffPotionItems(user);
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.salt'));
}, },
}, },
spookySparkles: { spookySparkles: {
@@ -320,6 +321,7 @@ spells.special = {
if (!target.achievements.spookySparkles) target.achievements.spookySparkles = 0; if (!target.achievements.spookySparkles) target.achievements.spookySparkles = 0;
target.achievements.spookySparkles += 1; target.achievements.spookySparkles += 1;
user.items.special.spookySparkles -= 1; user.items.special.spookySparkles -= 1;
setDebuffPotionItems(user);
}, },
}, },
opaquePotion: { opaquePotion: {
@@ -333,8 +335,7 @@ spells.special = {
cast (user) { cast (user) {
user.stats.buffs.spookySparkles = false; user.stats.buffs.spookySparkles = false;
user.stats.gp -= 5; user.stats.gp -= 5;
// Remove antidote from pinned items setDebuffPotionItems(user);
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.opaquePotion'));
}, },
}, },
shinySeed: { shinySeed: {
@@ -353,6 +354,7 @@ spells.special = {
if (!target.achievements.shinySeed) target.achievements.shinySeed = 0; if (!target.achievements.shinySeed) target.achievements.shinySeed = 0;
target.achievements.shinySeed += 1; target.achievements.shinySeed += 1;
user.items.special.shinySeed -= 1; user.items.special.shinySeed -= 1;
setDebuffPotionItems(user);
}, },
}, },
petalFreePotion: { petalFreePotion: {
@@ -366,8 +368,7 @@ spells.special = {
cast (user) { cast (user) {
user.stats.buffs.shinySeed = false; user.stats.buffs.shinySeed = false;
user.stats.gp -= 5; user.stats.gp -= 5;
// Remove antidote from pinned items setDebuffPotionItems(user);
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.petalFreePotion'));
}, },
}, },
seafoam: { seafoam: {
@@ -386,6 +387,7 @@ spells.special = {
if (!target.achievements.seafoam) target.achievements.seafoam = 0; if (!target.achievements.seafoam) target.achievements.seafoam = 0;
target.achievements.seafoam += 1; target.achievements.seafoam += 1;
user.items.special.seafoam -= 1; user.items.special.seafoam -= 1;
setDebuffPotionItems(user);
}, },
}, },
sand: { sand: {
@@ -399,7 +401,7 @@ spells.special = {
cast (user) { cast (user) {
user.stats.buffs.seafoam = false; user.stats.buffs.seafoam = false;
user.stats.gp -= 5; user.stats.gp -= 5;
user.pinnedItems = user.pinnedItems.filter(item => !item.path.includes('spells.special.sand')); setDebuffPotionItems(user);
}, },
}, },
nye: { nye: {

View File

@@ -46,10 +46,8 @@ import updateStore from './libs/updateStore';
import inAppRewards from './libs/inAppRewards'; import inAppRewards from './libs/inAppRewards';
import setDebuffPotionItems from './libs/setDebuffPotionItems'; import setDebuffPotionItems from './libs/setDebuffPotionItems';
api.setDebuffPotionItems = setDebuffPotionItems;
import getDebuffPotionItems from './libs/getDebuffPotionItems'; import getDebuffPotionItems from './libs/getDebuffPotionItems';
api.getDebuffPotionItems = getDebuffPotionItems;
import uuid from './libs/uuid'; import uuid from './libs/uuid';
@@ -164,6 +162,9 @@ api.shops = shops;
api.achievements = achievements; api.achievements = achievements;
api.randomVal = randomVal; api.randomVal = randomVal;
api.hasClass = hasClass; api.hasClass = hasClass;
api.setDebuffPotionItems = setDebuffPotionItems;
api.getDebuffPotionItems = getDebuffPotionItems;
api.fns = { api.fns = {
autoAllocate, autoAllocate,

View File

@@ -1,13 +1,13 @@
import { TRANSFORMATION_DEBUFFS_LIST } from '../constants'; import { TRANSFORMATION_DEBUFFS_LIST } from '../constants';
module.exports = function getDebuffPotionItems (user) { export default function getDebuffPotionItems (user) {
const items = []; const items = [];
const userBuffs = user.stats.buffs; const userBuffs = user.stats.buffs;
if (user) { if (user) {
for (let key in TRANSFORMATION_DEBUFFS_LIST) { for (const key in TRANSFORMATION_DEBUFFS_LIST) {
if (userBuffs[key]) { if (userBuffs[key]) {
let debuff = TRANSFORMATION_DEBUFFS_LIST[key]; const debuff = TRANSFORMATION_DEBUFFS_LIST[key];
const item = { const item = {
path: `spells.special.${debuff}`, path: `spells.special.${debuff}`,
type: 'debuffPotion', type: 'debuffPotion',
@@ -15,8 +15,7 @@ module.exports = function getDebuffPotionItems (user) {
items.push(item); items.push(item);
} }
} }
}
return items; return items;
} }
};

View File

@@ -191,7 +191,7 @@ export default function getItemInfo (user, type, item, officialPinnedItems, lang
currency: 'gold', currency: 'gold',
locked: false, locked: false,
purchaseType: 'debuffPotion', purchaseType: 'debuffPotion',
class: `inventory_special_${item.key}`, class: `shop_${item.key}`,
path: `spells.special.${item.key}`, path: `spells.special.${item.key}`,
pinType: 'debuffPotion', pinType: 'debuffPotion',
}; };

View File

@@ -1,7 +1,13 @@
import getDebuffPotionItems from './getDebuffPotionItems'; 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); const debuffPotionItems = getDebuffPotionItems(user);
if (debuffPotionItems.length) { if (debuffPotionItems.length) {
@@ -18,13 +24,7 @@ module.exports = function setDebuffPotionItems (user) {
if (!isUserHaveDebuffInPinnedItems) { if (!isUserHaveDebuffInPinnedItems) {
user.pinnedItems.push(...debuffPotionItems); user.pinnedItems.push(...debuffPotionItems);
} }
} else {
user.pinnedItems = user.pinnedItems.filter(item => {
return item.type !== 'debuffPotion';
});
} }
return user; return user;
}; }

View File

@@ -11,7 +11,7 @@ import {
} from '../models/group'; } from '../models/group';
import apiError from './apiError'; 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. // Excluding notifications and flags from the list of public fields to return.
const partyMembersPublicFields = 'profile.name stats achievements items.special'; const partyMembersPublicFields = 'profile.name stats achievements items.special';
@@ -98,7 +98,7 @@ async function castPartySpell (req, party, partyMembers, user, spell, quantity =
return partyMembers; 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)) { if (!party && (!targetId || user._id === targetId)) {
partyMembers = user; // eslint-disable-line no-param-reassign partyMembers = user; // eslint-disable-line no-param-reassign
} else { } else {