mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Fix: Antidotes to Avatar Transformation Items should be added to Rewards by API (#11353)
* Fix: moved debuffPotions from vue component - Move logic of choosing proper debuf potion from vue component to website commons - introduce new function to get debuffSpellItems * Fix: move debuffPotions to server * Refactoring: move setting of debuff potion to func * Fix: sanity * Refactoring & Tests: - Create test case for get and set DebuffPotionItems functions - Fix setDebuffPotionItems function to not create duplicated debuff items - Make debuff potion type of items unpinnable - Move list of debuffs to constant to reuse it in tests and functions * Fix: typo in test describe * Fix: translation of unpin * Fix: setDebuffPotionItems on cron buffs reset * Fix: use full path for debuff potions
This commit is contained in:
committed by
Matteo Pagliazzi
parent
85eab76a71
commit
5b57d91a9b
@@ -23,3 +23,10 @@ export const SUPPORTED_SOCIAL_NETWORKS = [
|
||||
export const GUILDS_PER_PAGE = 30; // number of guilds to return per page when using pagination
|
||||
|
||||
export const PARTY_LIMIT_MEMBERS = 30;
|
||||
|
||||
export const TRANSFORMATION_DEBUFFS_LIST = {
|
||||
snowball: 'salt',
|
||||
spookySparkles: 'opaquePotion',
|
||||
shinySeed: 'petalFreePotion',
|
||||
seafoam: 'sand',
|
||||
};
|
||||
|
||||
@@ -289,6 +289,8 @@ 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'));
|
||||
},
|
||||
},
|
||||
spookySparkles: {
|
||||
@@ -320,6 +322,8 @@ 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'));
|
||||
},
|
||||
},
|
||||
shinySeed: {
|
||||
@@ -351,6 +355,8 @@ 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'));
|
||||
},
|
||||
},
|
||||
seafoam: {
|
||||
@@ -382,6 +388,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'));
|
||||
},
|
||||
},
|
||||
nye: {
|
||||
|
||||
@@ -77,6 +77,12 @@ api.updateStore = updateStore;
|
||||
import inAppRewards from './libs/inAppRewards';
|
||||
api.inAppRewards = inAppRewards;
|
||||
|
||||
import setDebuffPotionItems from './libs/setDebuffPotionItems';
|
||||
api.setDebuffPotionItems = setDebuffPotionItems;
|
||||
|
||||
import getDebuffPotionItems from './libs/getDebuffPotionItems';
|
||||
api.getDebuffPotionItems = getDebuffPotionItems;
|
||||
|
||||
import uuid from './libs/uuid';
|
||||
api.uuid = uuid;
|
||||
|
||||
|
||||
22
website/common/script/libs/getDebuffPotionItems.js
Normal file
22
website/common/script/libs/getDebuffPotionItems.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { TRANSFORMATION_DEBUFFS_LIST } from '../constants';
|
||||
|
||||
module.exports = function getDebuffPotionItems (user) {
|
||||
const items = [];
|
||||
const userBuffs = user.stats.buffs;
|
||||
|
||||
if (user) {
|
||||
for (let key in TRANSFORMATION_DEBUFFS_LIST) {
|
||||
if (userBuffs[key]) {
|
||||
let debuff = TRANSFORMATION_DEBUFFS_LIST[key];
|
||||
const item = {
|
||||
path: `spells.special.${debuff}`,
|
||||
type: 'debuffPotion',
|
||||
};
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return items;
|
||||
}
|
||||
};
|
||||
@@ -177,6 +177,25 @@ module.exports = function getItemInfo (user, type, item, officialPinnedItems, la
|
||||
pinType: 'seasonalSpell',
|
||||
};
|
||||
break;
|
||||
case 'debuffPotion':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
mana: item.mana,
|
||||
cast: item.cast,
|
||||
immediateUse: item.immediateUse,
|
||||
target: item.target,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
value: item.value,
|
||||
type: 'debuffPotion',
|
||||
currency: 'gold',
|
||||
locked: false,
|
||||
purchaseType: 'debuffPotion',
|
||||
class: `inventory_special_${item.key}`,
|
||||
path: `spells.special.${item.key}`,
|
||||
pinType: 'debuffPotion',
|
||||
};
|
||||
break;
|
||||
case 'seasonalQuest':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
|
||||
30
website/common/script/libs/setDebuffPotionItems.js
Normal file
30
website/common/script/libs/setDebuffPotionItems.js
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -146,8 +146,9 @@ function togglePinnedItem (user, {item, type, path}, req = {}) {
|
||||
}
|
||||
|
||||
|
||||
if (path === 'armoire' || path === 'potion') {
|
||||
throw new BadRequest(i18n.t('cannotUnpinArmoirPotion', req.language));
|
||||
if (path === 'armoire' || path === 'potion' || type === 'debuffPotion') {
|
||||
// @TODO: take into considertation debuffPotion type in message
|
||||
throw new BadRequest(i18n.t('cannotUnpinItem', req.language));
|
||||
}
|
||||
|
||||
const isOfficialPinned = pathExistsInArray(officialPinnedItems, path) !== -1;
|
||||
|
||||
Reference in New Issue
Block a user