mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
[#1977] port pet-feeding to user.ops, so that it's now available in the API. Also add handling of 200 errors to simply notify and continue on up to server (friendly messages)
This commit is contained in:
@@ -2,7 +2,7 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL',
|
|||||||
function($rootScope, $scope, User, API_URL, $http, Notification) {
|
function($rootScope, $scope, User, API_URL, $http, Notification) {
|
||||||
|
|
||||||
var user = User.user;
|
var user = User.user;
|
||||||
var Content = $rootScope.Shared.content;
|
var Content = $rootScope.Content;
|
||||||
|
|
||||||
// convenience vars since these are accessed frequently
|
// convenience vars since these are accessed frequently
|
||||||
|
|
||||||
@@ -20,10 +20,10 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL',
|
|||||||
|
|
||||||
$scope.$watch('user.items.gear', function(gear){
|
$scope.$watch('user.items.gear', function(gear){
|
||||||
$scope.gear = {
|
$scope.gear = {
|
||||||
base: _.where(shared.content.gear.flat, {klass: 'base'})
|
base: _.where(Content.gear.flat, {klass: 'base'})
|
||||||
};
|
};
|
||||||
_.each(gear.owned, function(bool,key){
|
_.each(gear.owned, function(bool,key){
|
||||||
var item = shared.content.gear.flat[key];
|
var item = Content.gear.flat[key];
|
||||||
if (!$scope.gear[item.klass]) $scope.gear[item.klass] = [];
|
if (!$scope.gear[item.klass]) $scope.gear[item.klass] = [];
|
||||||
$scope.gear[item.klass].push(item);
|
$scope.gear[item.klass].push(item);
|
||||||
})
|
})
|
||||||
@@ -33,7 +33,7 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL',
|
|||||||
if ($scope.selectedEgg && $scope.selectedEgg.name == egg) {
|
if ($scope.selectedEgg && $scope.selectedEgg.name == egg) {
|
||||||
return $scope.selectedEgg = null; // clicked same egg, unselect
|
return $scope.selectedEgg = null; // clicked same egg, unselect
|
||||||
}
|
}
|
||||||
var eggData = _.findWhere(shared.content.eggs, {name:egg});
|
var eggData = _.findWhere(Content.eggs, {name:egg});
|
||||||
if (!$scope.selectedPotion) {
|
if (!$scope.selectedPotion) {
|
||||||
$scope.selectedEgg = eggData;
|
$scope.selectedEgg = eggData;
|
||||||
} else {
|
} else {
|
||||||
@@ -46,7 +46,7 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL',
|
|||||||
return $scope.selectedPotion = null; // clicked same egg, unselect
|
return $scope.selectedPotion = null; // clicked same egg, unselect
|
||||||
}
|
}
|
||||||
// we really didn't think through the way these things are stored and getting passed around...
|
// we really didn't think through the way these things are stored and getting passed around...
|
||||||
var potionData = _.findWhere(shared.content.hatchingPotions, {name:potion});
|
var potionData = _.findWhere(Content.hatchingPotions, {name:potion});
|
||||||
if (!$scope.selectedEgg) {
|
if (!$scope.selectedEgg) {
|
||||||
$scope.selectedPotion = potionData;
|
$scope.selectedPotion = potionData;
|
||||||
} else {
|
} else {
|
||||||
@@ -104,53 +104,20 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL',
|
|||||||
|
|
||||||
// Feeding Pet
|
// Feeding Pet
|
||||||
if ($scope.selectedFood) {
|
if ($scope.selectedFood) {
|
||||||
if (window.habitrpgShared.shared.content.specialPets[pet]) return Notification.text("Can't feed this pet.");
|
var food = $scope.selectedFood
|
||||||
var setObj = {};
|
if (food.name == 'Saddle' && !confirm('Saddle ' + pet + '?')) return;
|
||||||
var userPets = user.items.pets;
|
if (!confirm('Feed ' + pet + ' a ' + food.name + '?')) return;
|
||||||
if (user.items.mounts[pet] && (userPets[pet] >= 50 || $scope.selectedFood.name == 'Saddle'))
|
User.user.ops.feed({query:{pet: pet, food: food.name}});
|
||||||
return Notification.text("You already have that mount");
|
|
||||||
|
|
||||||
var evolve = function(){
|
|
||||||
userPets[pet] = 0;
|
|
||||||
setObj['items.mounts.' + pet] = true;
|
|
||||||
if (pet == user.items.currentPet) setObj['items.currentPet'] = '';
|
|
||||||
Notification.text('You have tamed '+egg+", let's go for a ride!");
|
|
||||||
}
|
|
||||||
// Saddling a pet
|
|
||||||
if ($scope.selectedFood.name == 'Saddle') {
|
|
||||||
if (!confirm('Saddle ' + pet + '?')) return;
|
|
||||||
evolve();
|
|
||||||
} else {
|
|
||||||
if (!confirm('Feed ' + pet + ' a ' + $scope.selectedFood.name + '?')) return;
|
|
||||||
if ($scope.selectedFood.target == potion) {
|
|
||||||
userPets[pet] += 5;
|
|
||||||
Notification.text(egg+' really likes the '+$scope.selectedFood.name+'!');
|
|
||||||
} else {
|
|
||||||
userPets[pet] += 2;
|
|
||||||
Notification.text(egg+' eats the '+$scope.selectedFood.name+" but doesn't seem to enjoy it.");
|
|
||||||
}
|
|
||||||
if (userPets[pet] >= 50 && !user.items.mounts[pet]) evolve();
|
|
||||||
}
|
|
||||||
setObj['items.pets.' + pet] = userPets[pet];
|
|
||||||
setObj['items.food.' + $scope.selectedFood.name] = user.items.food[$scope.selectedFood.name] - 1;
|
|
||||||
User.set(setObj);
|
|
||||||
$scope.selectedFood = null;
|
$scope.selectedFood = null;
|
||||||
|
|
||||||
// Selecting Pet
|
// Selecting Pet
|
||||||
} else {
|
} else {
|
||||||
var userCurrentPet = User.user.items.currentPet;
|
User.user.ops.equip({query:{type: 'pet', key: pet}});
|
||||||
if(userCurrentPet && userCurrentPet == pet){
|
|
||||||
User.user.items.currentPet = '';
|
|
||||||
}else{
|
|
||||||
User.user.items.currentPet = pet;
|
|
||||||
}
|
|
||||||
User.set('items.currentPet', User.user.items.currentPet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.chooseMount = function(egg, potion) {
|
$scope.chooseMount = function(egg, potion) {
|
||||||
var mount = egg + '-' + potion;
|
User.user.ops.equip({query:{type: 'mount', key: egg + '-' + potion}});
|
||||||
User.set('items.currentMount', (user.items.currentMount == mount) ? '' : mount);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
@@ -75,7 +75,11 @@ angular.module('userServices', []).
|
|||||||
_.each(user.ops, function(op,k){
|
_.each(user.ops, function(op,k){
|
||||||
user.ops[k] = _.partialRight(op, function(err, req){
|
user.ops[k] = _.partialRight(op, function(err, req){
|
||||||
//if (err) return Notification.text(err); // FIXME Circular dependency found: Notification <- User
|
//if (err) return Notification.text(err); // FIXME Circular dependency found: Notification <- User
|
||||||
if (err) return alert(err);
|
if (err) {
|
||||||
|
alert(err.code ? err.message : err);
|
||||||
|
// In the case of 200s, they're friendly alert messages like "You're pet has hatched!" - still send the op
|
||||||
|
if ((err.code && err.code >= 400) || !err.code) return;
|
||||||
|
}
|
||||||
userServices.log({op:k, params: req.params, query:req.query, body:req.body});
|
userServices.log({op:k, params: req.params, query:req.query, body:req.body});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -505,6 +505,9 @@ _.each(shared.wrap({}).ops, function(op,k){
|
|||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
api.batchUpdate = function(req, res, next) {
|
api.batchUpdate = function(req, res, next) {
|
||||||
|
if (req.body[0] && req.body[0].data)
|
||||||
|
return res.json(400, {err: "API has been updated, please refresh your browser or upgrade your mobile app."})
|
||||||
|
|
||||||
var user = res.locals.user;
|
var user = res.locals.user;
|
||||||
var oldSend = res.send;
|
var oldSend = res.send;
|
||||||
var oldJson = res.json;
|
var oldJson = res.json;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ var UserSchema = new Schema({
|
|||||||
contributions: String // a markdown textarea to list their contributions + links
|
contributions: String // a markdown textarea to list their contributions + links
|
||||||
},
|
},
|
||||||
|
|
||||||
balance: Number,
|
balance: {type: Number, 'default':0},
|
||||||
filters: {type: Schema.Types.Mixed, 'default': {}},
|
filters: {type: Schema.Types.Mixed, 'default': {}},
|
||||||
|
|
||||||
purchased: {
|
purchased: {
|
||||||
|
|||||||
Reference in New Issue
Block a user