Files
habitica/website/common/script/ops/releasePets.js
Alyssa Batula d2756278c3 Only unequip Gen 1 pets/mounts when releasing pets/mounts, fixes #5366 (#8119)
* Only unequip Gen 1 pets/mounts when releasing pets/mounts

* Changed mount declaration to match releasePets

* Check if a pet/mount is a drop type instead of checking for its name in the list of pets

* Changed references to pet and mount to petInfo and mountInfo for consistency with releasePets and releaseMounts

* Test that releasePets, releaseMounts, and releaseBoth do not unequip quest pets

* Fixed test names, and tests verify that a pet/mount is/is not a drop pet/mount on release

* Removed unneeded comments
2016-10-20 22:00:15 -05:00

44 lines
913 B
JavaScript

import content from '../content/index';
import i18n from '../i18n';
import {
NotAuthorized,
} from '../libs/errors';
module.exports = function releasePets (user, req = {}, analytics) {
if (user.balance < 1) {
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
}
user.balance -= 1;
let petInfo = content.petInfo[user.items.currentPet];
if (petInfo && petInfo.type === 'drop') {
user.items.currentPet = '';
}
for (let pet in content.pets) {
user.items.pets[pet] = 0;
}
if (!user.achievements.beastMasterCount) {
user.achievements.beastMasterCount = 0;
}
user.achievements.beastMasterCount++;
if (analytics) {
analytics.track('release pets', {
uuid: user._id,
acquireMethod: 'Gems',
gemCost: 4,
category: 'behavior',
headers: req.headers,
});
}
return [
user.items.pets,
i18n.t('petsReleased'),
];
};