mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +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:
@@ -2,6 +2,7 @@ import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import get from 'lodash/get';
|
||||
import pick from 'lodash/pick';
|
||||
import forEach from 'lodash/forEach';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import planGemLimits from '../libs/planGemLimits';
|
||||
import {
|
||||
@@ -62,7 +63,7 @@ module.exports = function purchase (user, req = {}, analytics) {
|
||||
];
|
||||
}
|
||||
|
||||
let acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'quests', 'gear'];
|
||||
let acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'quests', 'gear', 'bundles'];
|
||||
if (acceptedTypes.indexOf(type) === -1) {
|
||||
throw new NotFound(i18n.t('notAccteptedType', req.language));
|
||||
}
|
||||
@@ -101,6 +102,14 @@ module.exports = function purchase (user, req = {}, analytics) {
|
||||
|
||||
if (type === 'gear') {
|
||||
user.items.gear.owned[key] = true;
|
||||
} else if (type === 'bundles') {
|
||||
let subType = item.type;
|
||||
forEach(item.bundleKeys, function addBundledItems (bundledKey) {
|
||||
if (!user.items[subType][bundledKey] || user.items[subType][key] < 0) {
|
||||
user.items[subType][bundledKey] = 0;
|
||||
}
|
||||
user.items[subType][bundledKey]++;
|
||||
});
|
||||
} else {
|
||||
if (!user.items[type][key] || user.items[type][key] < 0) {
|
||||
user.items[type][key] = 0;
|
||||
|
||||
Reference in New Issue
Block a user