habitica/common/script/ops/releasePets.js

33 lines
846 B
JavaScript
Raw Normal View History

2016-03-07 22:02:42 +00:00
import content from '../content/index';
import i18n from '../i18n';
2016-03-08 16:45:14 +00:00
module.exports = function(user, req, cb, analytics) {
2016-03-07 22:02:42 +00:00
var analyticsData, pet;
if (user.balance < 1) {
2016-03-08 16:45:14 +00:00
return typeof cb === "function" ? cb({
2016-03-07 22:02:42 +00:00
code: 401,
message: i18n.t('notEnoughGems', req.language)
}) : void 0;
} else {
user.balance -= 1;
for (pet in content.pets) {
user.items.pets[pet] = 0;
}
if (!user.achievements.beastMasterCount) {
user.achievements.beastMasterCount = 0;
}
user.achievements.beastMasterCount++;
2016-03-08 16:45:14 +00:00
user.items.currentPet = "";
2016-03-07 22:02:42 +00:00
}
analyticsData = {
uuid: user._id,
acquireMethod: 'Gems',
gemCost: 4,
category: 'behavior'
};
2016-03-08 16:45:14 +00:00
if (analytics != null) {
2016-03-07 22:02:42 +00:00
analytics.track('release pets', analyticsData);
}
2016-03-08 16:45:14 +00:00
return typeof cb === "function" ? cb(null, user) : void 0;
2016-03-07 22:02:42 +00:00
};