mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
Common reorg (#8025)
* 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
This commit is contained in:
committed by
Matteo Pagliazzi
parent
d971e673af
commit
81b7eeeb71
44
website/common/script/ops/hatch.js
Normal file
44
website/common/script/ops/hatch.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
} from '../libs/errors';
|
||||
|
||||
module.exports = function hatch (user, req = {}) {
|
||||
let egg = _.get(req, 'params.egg');
|
||||
let hatchingPotion = _.get(req, 'params.hatchingPotion');
|
||||
|
||||
if (!(egg && hatchingPotion)) {
|
||||
throw new BadRequest(i18n.t('missingEggHatchingPotionHatch', req.language));
|
||||
}
|
||||
|
||||
if (!(user.items.eggs[egg] > 0 && user.items.hatchingPotions[hatchingPotion] > 0)) {
|
||||
throw new NotFound(i18n.t('messageMissingEggPotion', req.language));
|
||||
}
|
||||
|
||||
if (content.hatchingPotions[hatchingPotion].premium && !content.dropEggs[egg]) {
|
||||
throw new BadRequest(i18n.t('messageInvalidEggPotionCombo', req.language));
|
||||
}
|
||||
|
||||
let pet = `${egg}-${hatchingPotion}`;
|
||||
|
||||
if (user.items.pets[pet] && user.items.pets[pet] > 0) {
|
||||
throw new NotAuthorized(i18n.t('messageAlreadyPet', req.language));
|
||||
}
|
||||
|
||||
user.items.pets[pet] = 5;
|
||||
user.items.eggs[egg]--;
|
||||
user.items.hatchingPotions[hatchingPotion]--;
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user.items;
|
||||
} else {
|
||||
return [
|
||||
user.items,
|
||||
i18n.t('messageHatched', req.language),
|
||||
];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user