mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +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:
@@ -8,18 +8,10 @@ import pickBy from 'lodash/pickBy';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import getItemInfo from './getItemInfo';
|
||||
|
||||
let shops = {};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
shops.getMarketCategories = function getMarket (user, language) {
|
||||
let categories = [];
|
||||
let eggsCategory = {
|
||||
@@ -32,16 +24,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
.filter(egg => egg.canBuy(user))
|
||||
.concat(values(content.dropEggs))
|
||||
.map(egg => {
|
||||
return {
|
||||
key: egg.key,
|
||||
text: i18n.t('egg', {eggType: egg.text()}, language),
|
||||
notes: egg.notes(language),
|
||||
value: egg.value,
|
||||
class: `Pet_Egg_${egg.key}`,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'eggs',
|
||||
};
|
||||
return getItemInfo(user, 'egg', egg, language);
|
||||
}), 'key');
|
||||
categories.push(eggsCategory);
|
||||
|
||||
@@ -53,16 +36,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
hatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
|
||||
.filter(hp => !hp.limited)
|
||||
.map(hatchingPotion => {
|
||||
return {
|
||||
key: hatchingPotion.key,
|
||||
text: i18n.t('potion', {potionType: hatchingPotion.text(language)}),
|
||||
notes: hatchingPotion.notes(language),
|
||||
class: `Pet_HatchingPotion_${hatchingPotion.key}`,
|
||||
value: hatchingPotion.value,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'hatchingPotions',
|
||||
};
|
||||
return getItemInfo(user, 'hatchingPotion', hatchingPotion, language);
|
||||
}), 'key');
|
||||
categories.push(hatchingPotionsCategory);
|
||||
|
||||
@@ -74,16 +48,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
premiumHatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
|
||||
.filter(hp => hp.limited && hp.canBuy())
|
||||
.map(premiumHatchingPotion => {
|
||||
return {
|
||||
key: premiumHatchingPotion.key,
|
||||
text: i18n.t('potion', {potionType: premiumHatchingPotion.text(language)}),
|
||||
notes: `${premiumHatchingPotion.notes(language)} ${premiumHatchingPotion._addlNotes(language)}`,
|
||||
class: `Pet_HatchingPotion_${premiumHatchingPotion.key}`,
|
||||
value: premiumHatchingPotion.value,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'hatchingPotions',
|
||||
};
|
||||
return getItemInfo(user, 'premiumHatchingPotion', premiumHatchingPotion, language);
|
||||
}), 'key');
|
||||
if (premiumHatchingPotionsCategory.items.length > 0) {
|
||||
categories.push(premiumHatchingPotionsCategory);
|
||||
@@ -97,16 +62,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
foodCategory.items = sortBy(values(content.food)
|
||||
.filter(food => food.canDrop || food.key === 'Saddle')
|
||||
.map(foodItem => {
|
||||
return {
|
||||
key: foodItem.key,
|
||||
text: foodItem.text(language),
|
||||
notes: foodItem.notes(language),
|
||||
class: `Pet_Food_${foodItem.key}`,
|
||||
value: foodItem.value,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'food',
|
||||
};
|
||||
return getItemInfo(user, 'food', foodItem, language);
|
||||
}), 'key');
|
||||
categories.push(foodCategory);
|
||||
|
||||
@@ -178,15 +134,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
|
||||
bundleCategory.items = sortBy(values(content.bundles)
|
||||
.filter(bundle => bundle.type === 'quests' && bundle.canBuy())
|
||||
.map(bundle => {
|
||||
return {
|
||||
key: bundle.key,
|
||||
text: bundle.text(language),
|
||||
notes: bundle.notes(language),
|
||||
value: bundle.value,
|
||||
currency: 'gems',
|
||||
class: `quest_bundle_${bundle.key}`,
|
||||
purchaseType: 'bundles',
|
||||
};
|
||||
return getItemInfo(user, 'questBundle', bundle, language);
|
||||
}));
|
||||
|
||||
if (bundleCategory.items.length > 0) {
|
||||
@@ -202,23 +150,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
|
||||
category.items = content.questsByLevel
|
||||
.filter(quest => quest.canBuy(user) && quest.category === type)
|
||||
.map(quest => {
|
||||
let locked = lockQuest(quest, user);
|
||||
return {
|
||||
key: quest.key,
|
||||
text: quest.text(language),
|
||||
notes: quest.notes(language),
|
||||
group: quest.group,
|
||||
value: quest.goldValue ? quest.goldValue : quest.value,
|
||||
currency: quest.goldValue ? 'gold' : 'gems',
|
||||
locked,
|
||||
unlockCondition: quest.unlockCondition,
|
||||
drop: quest.drop,
|
||||
boss: quest.boss,
|
||||
collect: quest.collect,
|
||||
lvl: quest.lvl,
|
||||
class: locked ? `inventory_quest_scroll_locked inventory_quest_scroll_${quest.key}_locked` : `inventory_quest_scroll inventory_quest_scroll_${quest.key}`,
|
||||
purchaseType: 'quests',
|
||||
};
|
||||
return getItemInfo(user, 'quest', quest, language);
|
||||
});
|
||||
|
||||
categories.push(category);
|
||||
@@ -251,6 +183,7 @@ shops.getTimeTravelersCategories = function getTimeTravelersCategories (user, la
|
||||
notes: '',
|
||||
locked: false,
|
||||
currency: 'hourglasses',
|
||||
pinType: 'IGNORE',
|
||||
};
|
||||
category.items.push(item);
|
||||
}
|
||||
@@ -269,6 +202,8 @@ shops.getTimeTravelersCategories = function getTimeTravelersCategories (user, la
|
||||
let category = {
|
||||
identifier: set.key,
|
||||
text: set.text(language),
|
||||
path: `mystery.${set.key}`,
|
||||
pinType: 'mystery_set',
|
||||
purchaseAll: true,
|
||||
};
|
||||
|
||||
@@ -283,6 +218,7 @@ shops.getTimeTravelersCategories = function getTimeTravelersCategories (user, la
|
||||
locked: false,
|
||||
currency: 'hourglasses',
|
||||
class: `shop_${item.key}`,
|
||||
pinKey: `timeTravelers!gear.flat.${item.key}`,
|
||||
};
|
||||
});
|
||||
if (category.items.length > 0) {
|
||||
@@ -322,18 +258,8 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
text: i18n.t('seasonalItems', language),
|
||||
};
|
||||
|
||||
category.items = map(spells, (spell, key) => {
|
||||
return {
|
||||
key,
|
||||
text: spell.text(language),
|
||||
notes: spell.notes(language),
|
||||
value: spell.value,
|
||||
type: 'special',
|
||||
currency: 'gold',
|
||||
locked: false,
|
||||
purchaseType: 'spells',
|
||||
class: `inventory_special_${key}`,
|
||||
};
|
||||
category.items = map(spells, (spell) => {
|
||||
return getItemInfo(user, 'seasonalSpell', spell, language);
|
||||
});
|
||||
|
||||
categories.push(category);
|
||||
@@ -349,21 +275,8 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
text: i18n.t('quests', language),
|
||||
};
|
||||
|
||||
category.items = map(quests, (quest, key) => {
|
||||
return {
|
||||
key,
|
||||
text: quest.text(language),
|
||||
notes: quest.notes(language),
|
||||
value: quest.value,
|
||||
type: 'quests',
|
||||
currency: 'gems',
|
||||
locked: false,
|
||||
drop: quest.drop,
|
||||
boss: quest.boss,
|
||||
collect: quest.collect,
|
||||
class: `inventory_quest_scroll_${key}`,
|
||||
purchaseType: 'quests',
|
||||
};
|
||||
category.items = map(quests, (quest) => {
|
||||
return getItemInfo(user, 'seasonalQuest', quest, language);
|
||||
});
|
||||
|
||||
categories.push(category);
|
||||
@@ -379,18 +292,7 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
||||
category.items = flatGearArray.filter((gear) => {
|
||||
return user.items.gear.owned[gear.key] === undefined && gear.index === key;
|
||||
}).map(gear => {
|
||||
return {
|
||||
key: gear.key,
|
||||
text: gear.text(language),
|
||||
notes: gear.notes(language),
|
||||
value: gear.twoHanded ? 2 : 1,
|
||||
type: gear.type,
|
||||
specialClass: gear.specialClass,
|
||||
locked: false,
|
||||
currency: 'gems',
|
||||
purchaseType: 'gear',
|
||||
class: `shop_${gear.key}`,
|
||||
};
|
||||
return getItemInfo(null, 'gear', gear, language);
|
||||
});
|
||||
|
||||
if (category.items.length > 0) {
|
||||
@@ -412,15 +314,8 @@ shops.getBackgroundShopSets = function getBackgroundShopSets (language) {
|
||||
text: i18n.t(key, language),
|
||||
};
|
||||
|
||||
set.items = map(group, (background, bgKey) => {
|
||||
return {
|
||||
key: bgKey,
|
||||
text: background.text(language),
|
||||
notes: background.notes(language),
|
||||
value: background.price,
|
||||
currency: background.currency || 'gems',
|
||||
purchaseType: 'backgrounds',
|
||||
};
|
||||
set.items = map(group, (background) => {
|
||||
return getItemInfo(null, 'background', background, language);
|
||||
});
|
||||
|
||||
sets.push(set);
|
||||
|
||||
Reference in New Issue
Block a user