mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
item pinning (#8918)
* toggle pinned state of items server + client * pin quests / add pin src * add officially pinned items and api to get in app rewards * update schema and get items deatils * update pin actions to the new logic * show countBadge only with a number * extract getPinKey - pin seasonal items * togglePinned in buy-dialogs * add pinKey to shop items * wip * wip * fix path * togglePinnedItem as common.op / use in client * fix linting * pinning: getItemInfo and save in db path and type * make api more consistent, fix bugs * updates * fix bugs * update actions to current api * marketGear * change to pinType * add mystery_set to getItemInfo * fix isPinned * ignore animals * list shopItems (initial) * shopItem now has default popoverconent, itemclass and price / currency - list pinned items as rewards - attributes to gear * show buyModal for the rewards * show mystery_set icon * add info whether item is suggested * write migration, fix style issues * pin potion and armoire * make potion, armoire not unpinnable * show notes for armoire and potion, add default items for new users * show unpin notification * add/remove pinned gear on class-change * remove pinned & add new gear on purchase - refactoring pinning methods - fixes * always allow to purchase armoire * highlight item if suggested
This commit is contained in:
247
website/common/script/libs/getItemInfo.js
Normal file
247
website/common/script/libs/getItemInfo.js
Normal file
@@ -0,0 +1,247 @@
|
||||
import i18n from '../i18n';
|
||||
import content from '../content/index';
|
||||
import { BadRequest } from './errors';
|
||||
import count from '../count';
|
||||
|
||||
function lockQuest (quest, user) {
|
||||
if (quest.lvl && user.stats.lvl < quest.lvl) return true;
|
||||
if (quest.unlockCondition && (quest.key === 'moon1' || quest.key === 'moon2' || quest.key === 'moon3')) {
|
||||
return user.loginIncentives < quest.unlockCondition.incentiveThreshold;
|
||||
}
|
||||
if (user.achievements.quests) return quest.previous && !user.achievements.quests[quest.previous];
|
||||
return quest.previous;
|
||||
}
|
||||
|
||||
const officialPinnedItems = content.officialPinnedItems;
|
||||
|
||||
function isItemSuggested (itemInfo) {
|
||||
return officialPinnedItems.findIndex(officialItem => {
|
||||
return officialItem.type === itemInfo.pinType && officialItem.path === itemInfo.path;
|
||||
}) > -1;
|
||||
}
|
||||
|
||||
function getDefaultGearProps (item, language) {
|
||||
return {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
type: item.type,
|
||||
specialClass: item.specialClass,
|
||||
locked: false,
|
||||
purchaseType: 'gear',
|
||||
class: `shop_${item.key}`,
|
||||
path: `gear.flat.${item.key}`,
|
||||
str: item.str,
|
||||
int: item.int,
|
||||
per: item.per,
|
||||
con: item.con,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = function getItemInfo (user, type, item, language = 'en') {
|
||||
let itemInfo;
|
||||
|
||||
switch (type) {
|
||||
case 'egg':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: i18n.t('egg', {eggType: item.text(language)}, language),
|
||||
notes: item.notes(language),
|
||||
value: item.value,
|
||||
class: `Pet_Egg_${item.key}`,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'eggs',
|
||||
path: `eggs.${item.key}`,
|
||||
pinType: 'egg',
|
||||
};
|
||||
break;
|
||||
case 'hatchingPotion':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: i18n.t('potion', {potionType: item.text(language)}),
|
||||
notes: item.notes(language),
|
||||
class: `Pet_HatchingPotion_${item.key}`,
|
||||
value: item.value,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'hatchingPotions',
|
||||
path: `hatchingPotions.${item.key}`,
|
||||
pinType: 'hatchingPotion',
|
||||
};
|
||||
break;
|
||||
case 'premiumHatchingPotion':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: i18n.t('potion', {potionType: item.text(language)}),
|
||||
notes: `${item.notes(language)} ${item._addlNotes(language)}`,
|
||||
class: `Pet_HatchingPotion_${item.key}`,
|
||||
value: item.value,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'hatchingPotions',
|
||||
path: `premiumHatchingPotions.${item.key}`,
|
||||
pinType: 'premiumHatchingPotion',
|
||||
};
|
||||
break;
|
||||
case 'food':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
class: `Pet_Food_${item.key}`,
|
||||
value: item.value,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'food',
|
||||
path: `food.${item.key}`,
|
||||
pinType: 'food',
|
||||
};
|
||||
break;
|
||||
case 'questBundle':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
value: item.value,
|
||||
currency: 'gems',
|
||||
class: `quest_bundle_${item.key}`,
|
||||
purchaseType: 'bundles',
|
||||
path: `bundles.${item.key}`,
|
||||
pinType: 'questBundle',
|
||||
};
|
||||
break;
|
||||
case 'quest': // eslint-disable-line no-case-declarations
|
||||
const locked = lockQuest(item, user);
|
||||
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
group: item.group,
|
||||
value: item.goldValue ? item.goldValue : item.value,
|
||||
currency: item.goldValue ? 'gold' : 'gems',
|
||||
locked,
|
||||
unlockCondition: item.unlockCondition,
|
||||
drop: item.drop,
|
||||
boss: item.boss,
|
||||
collect: item.collect,
|
||||
lvl: item.lvl,
|
||||
class: locked ? `inventory_quest_scroll_locked inventory_quest_scroll_${item.key}_locked` : `inventory_quest_scroll inventory_quest_scroll_${item.key}`,
|
||||
purchaseType: 'quests',
|
||||
path: `quests.${item.key}`,
|
||||
pinType: 'quest',
|
||||
};
|
||||
break;
|
||||
case 'timeTravelers':
|
||||
// TODO
|
||||
itemInfo = {};
|
||||
break;
|
||||
case 'seasonalSpell':
|
||||
itemInfo = {
|
||||
key: item.keyspellKey,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
value: item.value,
|
||||
type: 'special',
|
||||
currency: 'gold',
|
||||
locked: false,
|
||||
purchaseType: 'spells',
|
||||
class: `inventory_special_${item.key}`,
|
||||
path: `spells.special.${item.key}`,
|
||||
pinType: 'seasonalSpell',
|
||||
};
|
||||
break;
|
||||
case 'seasonalQuest':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
value: item.value,
|
||||
type: 'quests',
|
||||
currency: 'gems',
|
||||
locked: false,
|
||||
drop: item.drop,
|
||||
boss: item.boss,
|
||||
collect: item.collect,
|
||||
class: `inventory_quest_scroll_${item.key}`,
|
||||
purchaseType: 'quests',
|
||||
path: `quests.${item.key}`,
|
||||
pinType: 'seasonalQuest',
|
||||
};
|
||||
break;
|
||||
case 'gear':
|
||||
// spread operator not available
|
||||
itemInfo = Object.assign(getDefaultGearProps(item, language), {
|
||||
value: item.twoHanded ? 2 : 1,
|
||||
currency: 'gems',
|
||||
pinType: 'gear',
|
||||
});
|
||||
break;
|
||||
case 'marketGear':
|
||||
itemInfo = Object.assign(getDefaultGearProps(item, language), {
|
||||
value: item.value,
|
||||
currency: 'gold',
|
||||
pinType: 'marketGear',
|
||||
});
|
||||
break;
|
||||
case 'background':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
class: `icon_background_${item.key}`,
|
||||
value: item.price,
|
||||
currency: item.currency || 'gems',
|
||||
purchaseType: 'backgrounds',
|
||||
path: `backgrounds.${item.set}.${item.key}`,
|
||||
pinType: 'background',
|
||||
};
|
||||
break;
|
||||
case 'mystery_set':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
value: 1,
|
||||
currency: 'hourglasses',
|
||||
purchaseType: 'mystery_set',
|
||||
class: `shop_set_mystery_${item.key}`,
|
||||
path: `mystery.${item.key}`,
|
||||
pinType: 'mystery_set',
|
||||
};
|
||||
break;
|
||||
case 'potion':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(language),
|
||||
value: item.value,
|
||||
currency: 'gold',
|
||||
purchaseType: 'potions',
|
||||
class: `shop_${item.key}`,
|
||||
path: 'potion',
|
||||
pinType: 'potion',
|
||||
};
|
||||
break;
|
||||
case 'armoire':
|
||||
itemInfo = {
|
||||
key: item.key,
|
||||
text: item.text(language),
|
||||
notes: item.notes(user, count.remainingGearInSet(user.items.gear.owned, 'armoire')), // TODO count
|
||||
value: item.value,
|
||||
currency: 'gold',
|
||||
purchaseType: 'armoire',
|
||||
class: `shop_${item.key}`,
|
||||
path: 'armoire',
|
||||
pinType: 'armoire',
|
||||
};
|
||||
}
|
||||
|
||||
if (itemInfo) {
|
||||
itemInfo.isSuggested = isItemSuggested(itemInfo);
|
||||
} else {
|
||||
throw new BadRequest(i18n.t('wrongItemType', {type}, language));
|
||||
}
|
||||
|
||||
return itemInfo;
|
||||
};
|
||||
Reference in New Issue
Block a user