Files
habitica/website/common/script/ops/changeClass.js
CJ 605391e4e7 Fixes #7958 - do not remove Battle Gear equipment when changing class (#8064)
* Changed files to fix Bug 7958:
 - website/client-old/.../userCtrl.js#38: removed to keep inventory constant
 - website/common/.../changeClass.js#33:  removed to stop 'classes' introduction

* Adjustments following Bug Review
 - Removed remaining 'foundKey' logic
 - Adjusted test logic to reflect feature change

* Reverting userCtrl.js to development version
 - Reintroduces "classes" Guide tour

* New version of Fixes #7958
 - Changed logic to only notify user the first time they choose a class
 - Changed message to represent this change in logic
 - #LINT: Cleaned interface for changing class
    - New method: enableClasses() -- because, really, should we be calling User.changeClass({}) from the UX?
    - New method: payForNewClass() -- handles prompting the user to confirm that they want to change class

* Remove new User Flag, use flags.tour.classes

* Whoopsie. Fix PR conflict.

* Changed files to fix Bug 7958:
 - website/client-old/.../userCtrl.js#38: removed to keep inventory constant
 - website/common/.../changeClass.js#33:  removed to stop 'classes' introduction

* Adjustments following Bug Review
 - Removed remaining 'foundKey' logic
 - Adjusted test logic to reflect feature change

* Reverting userCtrl.js to development version
 - Reintroduces "classes" Guide tour

* New version of Fixes #7958
 - Changed logic to only notify user the first time they choose a class
 - Changed message to represent this change in logic
 - #LINT: Cleaned interface for changing class
    - New method: enableClasses() -- because, really, should we be calling User.changeClass({}) from the UX?
    - New method: payForNewClass() -- handles prompting the user to confirm that they want to change class

* Remove new User Flag, use flags.tour.classes

* Whoopsie. Fix PR conflict.

* Removed Extraneous Flag

* Removed Extraneous Flag

* Changed files to fix Bug 7958:
 - website/client-old/.../userCtrl.js#38: removed to keep inventory constant
 - website/common/.../changeClass.js#33:  removed to stop 'classes' introduction

* New version of Fixes #7958
 - Changed logic to only notify user the first time they choose a class
 - Changed message to represent this change in logic
 - #LINT: Cleaned interface for changing class
    - New method: enableClasses() -- because, really, should we be calling User.changeClass({}) from the UX?
    - New method: payForNewClass() -- handles prompting the user to confirm that they want to change class

Remove new User Flag, use flags.tour.classes

Whoopsie. Fix PR conflict.

Removed Extraneous Flag

* Fixes handling architecture change

* Updates following Review 20170418-0602

* Remove cause of mocha/no-exclusive-tests lint failure
2017-07-20 10:28:53 -07:00

65 lines
2.0 KiB
JavaScript

import i18n from '../i18n';
import get from 'lodash/get';
import pick from 'lodash/pick';
import splitWhitespace from '../libs/splitWhitespace';
import { capByLevel } from '../statHelpers';
import {
NotAuthorized,
BadRequest,
} from '../libs/errors';
function resetClass (user, req = {}) {
if (user.preferences.disableClasses) {
user.preferences.disableClasses = false;
user.preferences.autoAllocate = false;
} else {
if (user.balance < 0.75) throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
user.balance -= 0.75;
}
user.stats.str = 0;
user.stats.con = 0;
user.stats.per = 0;
user.stats.int = 0;
user.stats.points = capByLevel(user.stats.lvl);
user.flags.classSelected = false;
}
module.exports = function changeClass (user, req = {}, analytics) {
let klass = get(req, 'query.class');
// user.flags.classSelected is set to false after the user paid the 3 gems
if (user.stats.lvl < 10) {
throw new NotAuthorized(i18n.t('lvl10ChangeClass', req.language));
} else if (!klass) {
// if no class is specified, reset points and set user.flags.classSelected to false. User will have paid 3 gems and will be prompted to select class.
resetClass(user, req);
} else if (klass === 'warrior' || klass === 'rogue' || klass === 'wizard' || klass === 'healer') {
if (user.flags.classSelected) {
resetClass(user, req);
}
user.stats.class = klass;
user.flags.classSelected = true;
user.items.gear.owned[`weapon_${klass}_0`] = true;
if (klass === 'rogue') user.items.gear.owned[`shield_${klass}_0`] = true;
if (analytics) {
analytics.track('change class', {
uuid: user._id,
class: klass,
acquireMethod: 'Gems',
gemCost: 3,
category: 'behavior',
headers: req.headers,
});
}
} else {
// if invalid class is specified, throw an error.
throw new BadRequest(i18n.t('invalidClass', req.language));
}
return [
pick(user, splitWhitespace('stats flags items preferences')),
];
};