habitica/common/script/ops/reroll.js

30 lines
703 B
JavaScript
Raw Normal View History

2016-03-07 22:02:42 +00:00
import i18n from '../i18n';
import _ from 'lodash';
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;
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;
}
user.balance--;
2016-03-08 16:45:14 +00:00
_.each(user.tasks, function(task) {
2016-03-07 22:02:42 +00:00
if (task.type !== 'reward') {
return task.value = 0;
}
});
user.stats.hp = 50;
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('Fortify Potion', 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
};