2013-09-08 16:28:06 +00:00
"use strict" ;
2013-10-22 19:19:43 +00:00
habitrpg . controller ( "UserCtrl" , [ '$rootScope' , '$scope' , '$location' , 'User' , '$http' ,
function ( $rootScope , $scope , $location , User , $http ) {
$scope . profile = User . user ;
$scope . hideUserAvatar = function ( ) {
$ ( ".userAvatar" ) . hide ( ) ;
} ;
2013-10-13 18:47:59 +00:00
2013-10-22 19:19:43 +00:00
$scope . $watch ( '_editing.profile' , function ( value ) {
if ( value === true ) $scope . editingProfile = angular . copy ( User . user . profile ) ;
2013-10-13 18:47:59 +00:00
} ) ;
2013-11-16 10:22:12 +00:00
$scope . allocate = function ( stat ) {
var setObj = { }
setObj [ 'stats.' + stat ] = User . user . stats [ stat ] + 1 ;
setObj [ 'stats.points' ] = User . user . stats . points - 1 ;
User . setMultiple ( setObj ) ;
}
$scope . rerollClass = function ( ) {
if ( ! confirm ( "Are you sure you want to re-roll? This will reset your character's class and allocated points (you'll get them all back to re-allocate)" ) )
return ;
User . setMultiple ( {
2013-12-05 06:53:55 +00:00
'flags.classSelected' : false ,
2013-11-16 10:22:12 +00:00
//'stats.points': this is handled on the server
'stats.str' : 0 ,
'stats.def' : 0 ,
'stats.per' : 0 ,
'stats.int' : 0
} )
}
2013-12-06 17:51:15 +00:00
$scope . rerollSubmit = function ( ) {
2013-12-06 22:41:58 +00:00
var klass = $scope . selectedClass ;
2013-12-06 17:51:15 +00:00
var setVars = {
2013-12-06 22:41:58 +00:00
"stats.class" : klass ,
2013-12-06 17:51:15 +00:00
"flags.classSelected" : true
} ;
2013-12-06 22:41:58 +00:00
// 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 ) {
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 ;
2013-12-06 17:51:15 +00:00
} ) ;
User . setMultiple ( setVars ) ;
$scope . selectedClass = undefined ;
2013-12-06 22:41:58 +00:00
//FIXME run updateStore (we need to access a different scope)
2013-12-06 17:51:15 +00:00
}
2013-11-16 10:22:12 +00:00
2013-10-22 19:19:43 +00:00
$scope . save = function ( ) {
var values = { } ;
_ . each ( $scope . editingProfile , function ( value , key ) {
// Using toString because we need to compare two arrays (websites)
2013-10-23 17:24:24 +00:00
var curVal = $scope . profile . profile [ key ] ;
if ( ! curVal || $scope . editingProfile [ key ] . toString ( ) !== curVal . toString ( ) )
values [ 'profile.' + key ] = value ;
2013-10-22 19:19:43 +00:00
} ) ;
User . setMultiple ( values ) ;
$scope . _editing . profile = false ;
}
2013-10-22 20:59:30 +00:00
$scope . unlock = User . unlock ;
2013-09-08 16:28:06 +00:00
}
2013-10-22 19:19:43 +00:00
] ) ;