mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
* Re-organize common folder * fix: Correct paths in tests * fix: move new content to proper folder * chore: Move audio folder to assets * Move sprites to sprites assets directory * Move css sprites to assets directory * Split out readmes for common code and sprites * Move images to assets directory * Move destinatin of shared browserified file * remove unused file * move compiled js to client-old * Fix karma tests * fix: Correct paths for sprites
36 lines
972 B
JavaScript
36 lines
972 B
JavaScript
import i18n from '../i18n';
|
|
import content from '../content/index';
|
|
import _ from 'lodash';
|
|
import splitWhitespace from '../libs/splitWhitespace';
|
|
import {
|
|
BadRequest,
|
|
NotAuthorized,
|
|
NotFound,
|
|
} from '../libs/errors';
|
|
|
|
module.exports = function buySpecialSpell (user, req = {}) {
|
|
let key = _.get(req, 'params.key');
|
|
if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language));
|
|
|
|
let item = content.special[key];
|
|
if (!item) throw new NotFound(i18n.t('spellNotFound', {spellId: key}, req.language));
|
|
|
|
if (user.stats.gp < item.value) {
|
|
throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
|
}
|
|
user.stats.gp -= item.value;
|
|
|
|
user.items.special[key]++;
|
|
|
|
if (req.v2 === true) {
|
|
return _.pick(user, splitWhitespace('items stats'));
|
|
} else {
|
|
return [
|
|
_.pick(user, splitWhitespace('items stats')),
|
|
i18n.t('messageBought', {
|
|
itemText: item.text(req.language),
|
|
}, req.language),
|
|
];
|
|
}
|
|
};
|