habitica/common/script/ops/releaseMounts.js

33 lines
861 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, mount;
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;
2016-03-08 16:45:14 +00:00
user.items.currentMount = "";
2016-03-07 22:02:42 +00:00
for (mount in content.pets) {
user.items.mounts[mount] = null;
}
if (!user.achievements.mountMasterCount) {
user.achievements.mountMasterCount = 0;
}
user.achievements.mountMasterCount++;
}
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 mounts', 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
};