classes: proper handling of items on class-switch, un-equipping items,

etc. Paves way for item-loss on death. See habitrpg-shared#acae9c3
This commit is contained in:
Tyler Renelle
2013-12-06 15:41:58 -07:00
parent b852d9a9f2
commit c51cdd0849
7 changed files with 44 additions and 34 deletions

View File

@@ -20,16 +20,10 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL',
$scope.$watch('user.items.gear', function(gear){
$scope.gear = {
base: [
Items.items.gear.flat['head_warrior_0'],
Items.items.gear.flat['armor_warrior_0'],
//Items.items.gear.flat['weapon_warrior_0'],
Items.items.gear.flat['shield_warrior_0']
]
base: _.where(Items.items.gear.flat, {klass: 'base'})
};
_.each(gear.owned, function(bool,key){
var item = Items.items.gear.flat[key];
debugger;
if (!$scope.gear[item.klass]) $scope.gear[item.klass] = [];
$scope.gear[item.klass].push(item);
})

View File

@@ -31,21 +31,37 @@ habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$
})
}
$scope.rerollSubmit = function(){
var klass = $scope.selectedClass;
var setVars = {
"stats.class": $scope.selectedClass,
"stats.class": klass,
"flags.classSelected": true
};
// Clear their gear and equip their new class's gear (can still equip old gear from inventory)
// If they've rolled this class before, restore their progress
_.each(['weapon', 'armor','shield','head'], function(type){
setVars['items.gear.owned.' + type + '_' + $scope.selectedClass + '_0'] = true;
setVars['items.gear.equipped.' + type] = $scope.selectedClass + '_0';
});
if ($scope.selectedClass == 'wizard') {
delete setVars['items.gear.owned.shield_wizard_0'];
setVars['items.gear.equipped.shield'] = 'warrior_shield_0';
var foundKey = false;
_.findLast(User.user.items.gear.owned, function(v,k){
if (~k.indexOf(type + '_' + klass)) {
foundKey = k;
return true;
}
});
setVars['items.gear.equipped.' + type] =
foundKey ? foundKey : // restore progress from when they last rolled this class
(type == 'weapon') ? 'weapon_' + klass + '_0' : // weapon_0 is significant, don't reset to base_0
(type == 'shield' && klass == 'rogue') ? 'shield_rogue_0' : // rogues start with an off-hand weapon
type + '_base_0'; // naked for the rest!
// Grant them their new class's gear
if (type == 'weapon' || (type == 'shield' && klass == 'rogue'))
setVars['items.gear.owned.' + type + '_' + klass + '_0'] = true;
});
User.setMultiple(setVars);
$scope.selectedClass = undefined;
//FIXME run updateStore (we need to access a different scope)
}
$scope.save = function(){

View File

@@ -117,15 +117,15 @@ var UserSchema = new Schema({
equipped: {
weapon: {type: String, 'default': 'weapon_warrior_0'},
armor: {type: String, 'default': 'armor_warrior_0'},
head: {type: String, 'default': 'head_warrior_0'},
shield: {type: String, 'default': 'shield_warrior_0'}
armor: {type: String, 'default': 'armor_base_0'},
head: {type: String, 'default': 'head_base_0'},
shield: {type: String, 'default': 'shield_base_0'}
},
costume: {
weapon: {type: String, 'default': 'weapon_warrior_0'},
armor: {type: String, 'default': 'armor_warrior_0'},
head: {type: String, 'default': 'head_warrior_0'},
shield: {type: String, 'default': 'shield_warrior_0'}
weapon: {type: String, 'default': 'weapon_base_0'},
armor: {type: String, 'default': 'armor_base_0'},
head: {type: String, 'default': 'head_base_0'},
shield: {type: String, 'default': 'shield_base_0'}
},
},

View File

@@ -6,8 +6,8 @@ script(id='partials/options.profile.avatar.html', type='text/ng-template')
li.customize-menu
menu(label='Head')
menu
button.broad_armor_warrior_0.customize-option(type='button', ng-click='set("preferences.size","broad")')
button.slim_armor_warrior_0.customize-option(type='button', ng-click='set("preferences.size","slim")')
button.broad_armor_base_0.customize-option(type='button', ng-click='set("preferences.size","broad")')
button.slim_armor_base_0.customize-option(type='button', ng-click='set("preferences.size","slim")')
.span4
h3 Hair
@@ -24,7 +24,7 @@ script(id='partials/options.profile.avatar.html', type='text/ng-template')
// Bangs
li.customize-menu
menu(label='Bangs')
button(class='head_0 customize-option', type='button', ng-click='set("preferences.hair.bangs",0)')
button(class='head_base_0 customize-option', type='button', ng-click='set("preferences.hair.bangs",0)')
button(class='hair_bangs_1_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.bangs",1)')
button(class='hair_bangs_2_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.bangs",2)')
button(class='hair_bangs_3_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.bangs",3)')
@@ -32,7 +32,7 @@ script(id='partials/options.profile.avatar.html', type='text/ng-template')
// Beard
li.customize-menu
menu(label='Beard')
button(class='head_0 customize-option', type='button', ng-click='set("preferences.hair.beard",0)')
button(class='head_base_0 customize-option', type='button', ng-click='set("preferences.hair.beard",0)')
button(class='hair_beard_1_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.beard",1)')
button(class='hair_beard_2_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.beard",2)')
button(class='hair_beard_3_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.beard",3)')
@@ -40,14 +40,14 @@ script(id='partials/options.profile.avatar.html', type='text/ng-template')
// Mustache
li.customize-menu
menu(label='Mustache')
button(class='head_0 customize-option', type='button', ng-click='set("preferences.hair.mustache",0)')
button(class='head_base_0 customize-option', type='button', ng-click='set("preferences.hair.mustache",0)')
button(class='hair_mustache_1_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.mustache",1)')
button(class='hair_mustache_2_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.mustache",2)')
// Base
li.customize-menu
menu(label='Base')
button(class='head_0 customize-option', type='button', ng-click='set("preferences.hair.base",0)')
button(class='head_base_0 customize-option', type='button', ng-click='set("preferences.hair.base",0)')
button(class='hair_base_1_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.base",1)')
button(class='hair_base_2_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.base",2)')
button(class='hair_base_3_{{user.preferences.hair.color}} customize-option', type='button', ng-click='set("preferences.hair.base",3)')

View File

@@ -14,7 +14,7 @@ figure.herobox(ng-click='spell ? castEnd(profile, "user", $event) : clickMember(
span(class='{{profile.preferences.size}}_{{profile.items.gear.equipped.armor}}', ng-if='!profile.preferences.costume')
span(class='{{profile.preferences.size}}_{{profile.items.gear.costume.armor}}', ng-if='profile.preferences.costume')
span(class='head_0')
span(class='head_base_0')
span(class='hair_base_{{profile.preferences.hair.base}}_{{profile.preferences.hair.color}}')
span(class='hair_bangs_{{profile.preferences.hair.bangs}}_{{profile.preferences.hair.color}}')

View File

@@ -14,7 +14,7 @@
.character-sprites
span(class='skin_{{user.preferences.skin}}')
span(class='{{user.preferences.size}}_armor_warrior_5')
span(class='head_0')
span(class='head_base_0')
span(class='hair_base_{{user.preferences.hair.base}}_{{user.preferences.hair.color}}')
span(class='hair_bangs_{{user.preferences.hair.bangs}}_{{user.preferences.hair.color}}')
span(class='hair_beard_{{user.preferences.hair.beard}}_{{user.preferences.hair.color}}')
@@ -28,7 +28,7 @@
.character-sprites
span(class='skin_{{user.preferences.skin}}')
span(class='{{user.preferences.size}}_armor_wizard_5')
span(class='head_0')
span(class='head_base_0')
span(class='hair_base_{{user.preferences.hair.base}}_{{user.preferences.hair.color}}')
span(class='hair_bangs_{{user.preferences.hair.bangs}}_{{user.preferences.hair.color}}')
span(class='hair_beard_{{user.preferences.hair.beard}}_{{user.preferences.hair.color}}')
@@ -42,7 +42,7 @@
.character-sprites
span(class='skin_{{user.preferences.skin}}')
span(class='{{user.preferences.size}}_armor_rogue_5')
span(class='head_0')
span(class='head_base_0')
span(class='hair_base_{{user.preferences.hair.base}}_{{user.preferences.hair.color}}')
span(class='hair_bangs_{{user.preferences.hair.bangs}}_{{user.preferences.hair.color}}')
span(class='hair_beard_{{user.preferences.hair.beard}}_{{user.preferences.hair.color}}')
@@ -56,7 +56,7 @@
.character-sprites
span(class='skin_{{user.preferences.skin}}')
span(class='{{user.preferences.size}}_armor_healer_5')
span(class='head_0')
span(class='head_base_0')
span(class='hair_base_{{user.preferences.hair.base}}_{{user.preferences.hair.color}}')
span(class='hair_bangs_{{user.preferences.hair.bangs}}_{{user.preferences.hair.color}}')
span(class='hair_beard_{{user.preferences.hair.beard}}_{{user.preferences.hair.color}}')

View File

@@ -46,7 +46,7 @@ script(id='templates/habitrpg-tasks.html', type="text/ng-template")
// Static Rewards
ul.items.rewards(bo-if='main && list.type=="reward" && user.flags.itemsEnabled')
li.task.reward-item(ng-if='!item.hide', ng-repeat='item in itemStore')
li.task.reward-item(ng-repeat='item in itemStore')
// right-hand side control buttons
.task-meta-controls
span.task-notes(popover-trigger='mouseenter', popover-placement='left', popover='{{item.notes}}', popover-title='{{item.text}}')