mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
Discount Bundled Quests (#8731)
* refactor(content): split quests file * feat(purchases): sell bundled quests * fix(style): address linting errors * test(bundles): shop and purchase tests * fix(test): remove only * test(bundles): check balance deduction * docs(content): comment bundle structure * fix(test): account for cumulative balance
This commit is contained in:
@@ -114,6 +114,79 @@ shops.getMarketCategories = function getMarket (user, language) {
|
||||
shops.getQuestShopCategories = function getQuestShopCategories (user, language) {
|
||||
let categories = [];
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------
|
||||
* Quest Bundles
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* These appear in the Content index.js as follows:
|
||||
* {
|
||||
* bundleName: {
|
||||
* key: 'bundleName',
|
||||
* text: t('bundleNameText'),
|
||||
* notes: t('bundleNameNotes'),
|
||||
* bundleKeys: [
|
||||
* 'quest1',
|
||||
* 'quest2',
|
||||
* 'quest3',
|
||||
* ],
|
||||
* canBuy () {
|
||||
* return true when bundle is available for purchase;
|
||||
* },
|
||||
* type: 'quests',
|
||||
* value: 7,
|
||||
* },
|
||||
* secondBundleName: {
|
||||
* ...
|
||||
* },
|
||||
* }
|
||||
*
|
||||
* After filtering and mapping, the Shop will produce:
|
||||
*
|
||||
* [
|
||||
* {
|
||||
* identifier: 'bundle',
|
||||
* text: 'i18ned string for bundles category',
|
||||
* items: [
|
||||
* {
|
||||
* key: 'bundleName',
|
||||
* text: 'i18ned string for bundle title',
|
||||
* notes: 'i18ned string for bundle description',
|
||||
* value: 7,
|
||||
* currency: 'gems',
|
||||
* class: 'quest_bundle_bundleName',
|
||||
* purchaseType: 'bundles',
|
||||
* },
|
||||
* { second bundle },
|
||||
* ],
|
||||
* },
|
||||
* { main quest category 1 },
|
||||
* ...
|
||||
* ]
|
||||
*
|
||||
*/
|
||||
|
||||
let bundleCategory = {
|
||||
identifier: 'bundle',
|
||||
text: i18n.t('questBundles', 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',
|
||||
};
|
||||
}));
|
||||
|
||||
categories.push(bundleCategory);
|
||||
|
||||
each(content.userCanOwnQuestCategories, type => {
|
||||
let category = {
|
||||
identifier: type,
|
||||
|
||||
Reference in New Issue
Block a user