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
This commit is contained in:
CJ
2017-07-20 13:28:53 -04:00
committed by Sabe Jones
parent ca90d88289
commit 605391e4e7
7 changed files with 29 additions and 47 deletions

View File

@@ -1,3 +1,5 @@
/* eslint-disable camelcase */
import changeClass from '../../../website/common/script/ops/changeClass';
import {
NotAuthorized,
@@ -58,7 +60,8 @@ describe('shared.ops.changeClass', () => {
it('changes class', () => {
user.stats.class = 'healer';
user.items.gear.owned.armor_rogue_1 = true; // eslint-disable-line camelcase
user.items.gear.owned.weapon_healer_3 = true;
user.items.gear.equipped.weapon = 'weapon_healer_3';
let [data] = changeClass(user, {query: {class: 'rogue'}});
expect(data).to.eql({
@@ -70,13 +73,10 @@ describe('shared.ops.changeClass', () => {
expect(user.stats.class).to.equal('rogue');
expect(user.flags.classSelected).to.be.true;
expect(user.items.gear.equipped.weapon).to.equal('weapon_rogue_0');
expect(user.items.gear.owned.weapon_rogue_0).to.be.true;
expect(user.items.gear.equipped.armor).to.equal('armor_rogue_1');
expect(user.items.gear.owned.armor_rogue_1).to.be.true;
expect(user.items.gear.equipped.shield).to.equal('shield_rogue_0');
expect(user.items.gear.owned.shield_rogue_0).to.be.true;
expect(user.items.gear.equipped.head).to.equal('head_base_0');
expect(user.items.gear.owned.weapon_healer_3).to.be.true;
expect(user.items.gear.equipped.weapon).to.equal('weapon_healer_3');
});
});

View File

@@ -23,16 +23,18 @@ habitrpg.controller('UserCtrl', ['$rootScope', '$scope', '$location', 'User', '$
}
$scope.changeClass = function(klass){
if (!klass) {
if (!confirm(window.env.t('sureReset')))
return;
return User.changeClass({});
}
User.changeClass({query:{class:klass}});
$scope.selectedClass = undefined;
Shared.updateStore(User.user);
Guide.goto('classes', 0,true);
Guide.goto('classes', 0, true);
}
$scope.enableClasses = function(){
return User.changeClass({});
}
$scope.payForNewClass = function(){
if (confirm(window.env.t('sureReset'))) return User.changeClass({});
}
$scope.save = function(){

View File

@@ -64,11 +64,15 @@ function($rootScope, User, $timeout, $state, Analytics, Notification, Shared, So
classes: [
[
{
orphan: true,
content: window.env.t('classGearText'),
final: true,
state: 'options.inventory.equipment',
element: '.equipment-tab',
title: window.env.t('classGear'),
content: window.env.t('classGearText')
}, {
hideNavigation: true
}
/*, {
state: 'options.profile.stats',
element: ".allocate-stats",
title: window.env.t('stats'),
@@ -88,7 +92,7 @@ function($rootScope, User, $timeout, $state, Analytics, Notification, Shared, So
title: window.env.t('readMore'),
content: window.env.t('moreClass'),
final: true
}
}*/
]
],
stats: [[
@@ -265,6 +269,7 @@ function($rootScope, User, $timeout, $state, Analytics, Notification, Shared, So
var goto = function(chapter, page, force) {
if (chapter == 'intro' && User.user.flags.welcomed != true) User.set({'flags.welcomed': true});
if (chapter == 'classes' && User.user.flags.tour.classes === -2) return;
if (page === -1) page = 0;
var curr = User.user.flags.tour[chapter];
if (page != curr+1 && !force) return;

View File

@@ -214,7 +214,7 @@ angular.module('habitrpg')
},
changeClass: function (data) {
callOpsFunctionAndRequest('changeClass', 'change-class', "POST",'', data);
callOpsFunctionAndRequest('changeClass', 'change-class', "POST", '', data);
},
disableClasses: function () {

View File

@@ -61,7 +61,7 @@
"paymentMethods": "Purchase using",
"classGear": "Class Gear",
"classGearText": "First: don't panic! Your old gear is in your inventory, and you're now wearing the apprentice equipment of your new class. Wearing your class's gear grants you a 50% bonus to stats. However, feel free to switch back to your old gear.",
"classGearText": "Congratulations on choosing a class! I've added your new basic weapon to your inventory. Take a look below to equip it!",
"classStats": "These are your class's stats; they affect the game-play. Each time you level up, you get one point to allocate to a particular stat. Hover over each stat for more information.",
"autoAllocate": "Auto Allocate",
"autoAllocateText": "If 'automatic allocation' is checked, your avatar gains stats automatically based on your tasks' attributes, which you can find in <strong>TASK > Edit > Advanced > Attributes</strong>. Eg, if you hit the gym often, and your 'Gym' Daily is set to 'Strength', you'll gain Strength automatically.",

View File

@@ -1,7 +1,5 @@
import i18n from '../i18n';
import get from 'lodash/get';
import each from 'lodash/each';
import findLast from 'lodash/findLast';
import pick from 'lodash/pick';
import splitWhitespace from '../libs/splitWhitespace';
import { capByLevel } from '../statHelpers';
@@ -43,31 +41,8 @@ module.exports = function changeClass (user, req = {}, analytics) {
user.stats.class = klass;
user.flags.classSelected = true;
each(['weapon', 'armor', 'shield', 'head'], (type) => {
let foundKey = false;
findLast(user.items.gear.owned, (val, key) => {
if (key.indexOf(`${type}_${klass}`) !== -1 && val === true) {
foundKey = key;
return true;
}
});
if (!foundKey) {
if (type === 'weapon') {
foundKey = `weapon_${klass}_0`;
} else if (type === 'shield' && klass === 'rogue') {
foundKey = 'shield_rogue_0';
} else {
foundKey = `${type}_base_0`;
}
}
user.items.gear.equipped[type] = foundKey;
if (type === 'weapon' || (type === 'shield' && klass === 'rogue')) { // eslint-disable-line no-extra-parens
user.items.gear.owned[`${type}_${klass}_0`] = 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', {

View File

@@ -69,5 +69,5 @@ script(type='text/ng-template', id='modals/chooseClass.html')
.modal-footer
span(popover-placement='left', popover-trigger='mouseenter', popover=env.t('optOutOfClassesText'))
button.btn.btn-danger(ng-click='User.disableClasses({}); $close()')=env.t('optOutOfClasses')
button.btn.btn-primary(ng-disabled='!selectedClass' ng-click='changeClass(selectedClass); $close()')=env.t('select')
button.btn.btn-primary(ng-disabled='!selectedClass' ng-click='changeClass(selectedClass); selectedClass = undefined; $close()')=env.t('select')
.pull-left!=env.t('chooseClassLearn')