mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-31 23:11:15 +00:00
halloween: purchase full set
This commit is contained in:
parent
619c00fb5c
commit
6f32ac2a24
4 changed files with 47 additions and 24 deletions
|
|
@ -33,20 +33,7 @@ habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$
|
|||
$scope.editingProfile.websites.splice($index,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* For gem-unlockable preferences, (a) if owned, select preference (b) else, purchase
|
||||
* @param path: User.preferences <-> User.purchased maps like User.preferences.skin=abc <-> User.purchased.skin.abc. Pass in this paramater as "skin.abc"
|
||||
*/
|
||||
$scope.unlock = function(path){
|
||||
if (window.habitrpgShared.helpers.dotGet('purchased.' + path, User.user)) {
|
||||
var pref = path.split('.')[0],
|
||||
val = path.split('.')[1];
|
||||
window.habitrpgShared.helpers.dotSet('preferences.' + pref, val, User.user);
|
||||
} else {
|
||||
if (confirm("Purchase for 2 Gems?") !== true) return;
|
||||
if (User.user.balance < 0.5) return $rootScope.modals.buyGems = true;
|
||||
User.unlock(path);
|
||||
}
|
||||
}
|
||||
$scope.unlock = User.unlock;
|
||||
|
||||
}
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -164,8 +164,29 @@ angular.module('userServices', []).
|
|||
userServices.log(log);
|
||||
},
|
||||
|
||||
/**
|
||||
* For gem-unlockable preferences, (a) if owned, select preference (b) else, purchase
|
||||
* @param path: User.preferences <-> User.purchased maps like User.preferences.skin=abc <-> User.purchased.skin.abc.
|
||||
* Pass in this paramater as "skin.abc". Alternatively, pass as an array ["skin.abc", "skin.xyz"] to unlock sets
|
||||
*/
|
||||
unlock: function(path){
|
||||
var self = this;
|
||||
var self = userServices; //this; // why isn't this working?
|
||||
|
||||
if (_.isArray(path)) {
|
||||
if (confirm("Purchase for 5 Gems?") !== true) return;
|
||||
if (user.balance < 1.25) return $rootScope.modals.buyGems = true;
|
||||
path = path.join(',');
|
||||
} else {
|
||||
if (window.habitrpgShared.helpers.dotGet('purchased.' + path, user)) {
|
||||
var pref = path.split('.')[0],
|
||||
val = path.split('.')[1];
|
||||
window.habitrpgShared.helpers.dotSet('preferences.' + pref, val, user);
|
||||
} else {
|
||||
if (confirm("Purchase for 2 Gems?") !== true) return;
|
||||
if (user.balance < 0.5) return $rootScope.modals.buyGems = true;
|
||||
}
|
||||
}
|
||||
|
||||
$http.post(API_URL + '/api/v1/user/unlock?path=' + path)
|
||||
.success(function(data, status, headers, config){
|
||||
self.log({}); // sync new unlocked & preferences
|
||||
|
|
|
|||
|
|
@ -572,14 +572,27 @@ api['delete'] = function(req, res) {
|
|||
|
||||
api.unlock = function(req, res) {
|
||||
var user = res.locals.user;
|
||||
if (user.balance < 0.5)
|
||||
var path = req.query.path;
|
||||
var fullSet = ~path.indexOf(',');
|
||||
|
||||
// 5G per set, 2G per individual
|
||||
cost = fullSet ? 1.25 : 0.5;
|
||||
|
||||
if (user.balance < cost)
|
||||
return res.json(401, {err: 'Not enough gems'});
|
||||
|
||||
var path = req.query.path;
|
||||
if (helpers.dotGet('purchased.' + path, user) === true)
|
||||
return res.json(401, {err: 'User already purchased that'});
|
||||
user.balance -= 2;
|
||||
helpers.dotSet('purchased.' + path, true, user);
|
||||
if (fullSet) {
|
||||
var paths = path.split(',');
|
||||
_.each(paths, function(p){
|
||||
helpers.dotSet('purchased.' + p, true, user);
|
||||
});
|
||||
} else {
|
||||
if (helpers.dotGet('purchased.' + path, user) === true)
|
||||
return res.json(401, {err: 'User already purchased that'});
|
||||
helpers.dotSet('purchased.' + path, true, user);
|
||||
}
|
||||
|
||||
user.balance -= cost;
|
||||
user.__v++;
|
||||
user.markModified('purchased');
|
||||
user.save(function(err, saved){
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-click='set("preferences.skin","orc")')
|
||||
|
||||
// Special Events
|
||||
menu(label='Crazy Skin')
|
||||
menu(label='Crazy Skin (2G / skin)')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.eb052b}', ng-click='unlock("skin.eb052b")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.f69922}', ng-click='unlock("skin.f69922")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.f5d70f}', ng-click='unlock("skin.f5d70f")')
|
||||
|
|
@ -45,15 +45,17 @@
|
|||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.d7a9f7}', ng-click='unlock("skin.d7a9f7")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.800ed0}', ng-click='unlock("skin.800ed0")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.rainbow}', ng-click='unlock("skin.rainbow")')
|
||||
button.btn.btn-small.btn-primary(ng-hide='user.purchased.skin.eb052b && user.purchased.skin.f69922 && user.purchased.skin.f5d70f && user.purchased.skin.0ff591 && user.purchased.skin.2b43f6 && user.purchased.skin.d7a9f7 && user.purchased.skin.800ed0 && user.purchased.skin.rainbow', ng-click='unlock(["skin.eb052b", "skin.f69922", "skin.f5d70f", "skin.0ff591", "skin.2b43f6", "skin.d7a9f7", "skin.800ed0", "skin.rainbow"])') Unlock Set (5G)
|
||||
|
||||
// Special Events
|
||||
menu(label='Monster Skin (Happy Halloween!)')
|
||||
menu(label='Monster Skin (2G / skin)')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.monster}', ng-click='unlock("skin.monster")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.pumpkin}', ng-click='unlock("skin.pumpkin")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.skeleton}', ng-click='unlock("skin.skeleton")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.zombie}', ng-click='unlock("skin.zombie")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.ghost}', ng-click='unlock("skin.ghost")')
|
||||
button.customize-option(type='button', class='{{user.preferences.gender}}_skin_orc', ng-class='{locked: !user.purchased.skin.shadow}', ng-click='unlock("skin.shadow")')
|
||||
button.btn.btn-small.btn-primary(ng-hide='user.purchased.skin.monster && user.purchased.skin.pumpkin && user.purchased.skin.skeleton && user.purchased.skin.zombie && user.purchased.skin.ghost && user.purchased.skin.shadow', ng-click='unlock(["skin.monster", "skin.pumpkin", "skin.skeleton", "skin.zombie", "skin.ghost", "skin.shadow"])') Unlock Set (5G)
|
||||
|
||||
menu(ng-show='user.preferences.gender=="f"', type='list')
|
||||
li.customize-menu
|
||||
|
|
|
|||
Loading…
Reference in a new issue