mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 02:02:19 +00:00
[#1431] add temporary server-based pet-purchasing mechanism. Lotsa cleanup /
refactoring to be had here
This commit is contained in:
parent
812ba3a339
commit
ef69309b0c
5 changed files with 44 additions and 26 deletions
|
|
@ -1,5 +1,5 @@
|
|||
habitrpg.controller("MarketCtrl", ['$rootScope', '$scope', 'User',
|
||||
function($rootScope, $scope, User) {
|
||||
habitrpg.controller("MarketCtrl", ['$rootScope', '$scope', 'User', 'API_URL', '$http',
|
||||
function($rootScope, $scope, User, API_URL, $http) {
|
||||
|
||||
$scope.eggs = window.habitrpgShared.items.items.pets;
|
||||
$scope.hatchingPotions = window.habitrpgShared.items.items.hatchingPotions;
|
||||
|
|
@ -8,7 +8,7 @@ habitrpg.controller("MarketCtrl", ['$rootScope', '$scope', 'User',
|
|||
|
||||
$scope.buy = function(type, item){
|
||||
var gems = User.user.balance * 4,
|
||||
store = type === 'egg' ? $scope.userEggs : $scope.userHatchingPotions;
|
||||
store = type === 'egg' ? $scope.userEggs : $scope.userHatchingPotions,
|
||||
storePath = type === 'egg' ? 'items.eggs' : 'items.hatchingPotions'
|
||||
|
||||
if(gems < item.value){
|
||||
|
|
@ -19,20 +19,15 @@ habitrpg.controller("MarketCtrl", ['$rootScope', '$scope', 'User',
|
|||
|
||||
if(confirm(message)){
|
||||
var toPush = type === 'egg' ? item : item.name;
|
||||
store.push(toPush);
|
||||
|
||||
var dataStore = {
|
||||
op: 'set',
|
||||
data: {}
|
||||
};
|
||||
|
||||
dataStore.data[storePath] = store;
|
||||
User.user.balance = (gems - item.value) / 4;
|
||||
|
||||
User.log([
|
||||
dataStore,
|
||||
{ op: 'set', data: {'balance': User.user.balance} }
|
||||
]);
|
||||
$http.post(API_URL + '/api/v1/market/buy?type=' + type, toPush)
|
||||
.success(function(data){
|
||||
User.user.balance = data.balance;
|
||||
store.push(toPush);
|
||||
//$sc¡ope.items = data.items.eggs; // FIXME this isn't updating the UI
|
||||
}).error(function(data){
|
||||
alert(data);
|
||||
console.error(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,30 @@ var User = require('./../models/user').model;
|
|||
var Group = require('./../models/group').model;
|
||||
var api = module.exports;
|
||||
|
||||
// FIXME put this in a proper location
|
||||
api.marketBuy = function(req, res, next){
|
||||
var user = res.locals.user,
|
||||
type = req.query.type,
|
||||
item = req.body;
|
||||
|
||||
if (!_.contains(['hatchingPotion', 'egg'], req.query.type))
|
||||
return res.json(400, {err: "Type must be in 'hatchingPotion' or 'egg'"});
|
||||
var item;
|
||||
if (type == 'egg'){
|
||||
if (!user.items && !user.items.eggs) user.items.eggs = [];
|
||||
user.items.eggs.push(item);
|
||||
} else {
|
||||
if (!user.items && !user.items.hatchingPotions) user.items.hatchingPotions = [];
|
||||
user.items.hatchingPotions.push(item.name);
|
||||
}
|
||||
user.markModified('items'); // I still don't get when this is necessary and when not..
|
||||
user.balance -= (item.value/4);
|
||||
user.save(function(err, saved){
|
||||
if (err) return res.json(500, {err:err});
|
||||
res.json(saved);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ router.post('/groups/:gid/chat', auth.auth, groups.attachGroup, groups.postChat)
|
|||
//PUT /groups/:gid/chat/:messageId
|
||||
//DELETE /groups/:gid/chat/:messageId
|
||||
|
||||
|
||||
// Market
|
||||
router.post('/market/buy', auth.auth, user.marketBuy);
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -6,11 +6,10 @@
|
|||
td
|
||||
.popover.static-popover.fade.right.in
|
||||
.arrow
|
||||
h3.popover-title Alexander Augustin
|
||||
h3.popover-title
|
||||
a(target='_blank', href='http://www.kickstarter.com/profile/523661924') Alexander Augustin
|
||||
.popover-content
|
||||
| Welcome to the Market! I'm the merchant,
|
||||
a(target='_blank', href='http://www.kickstarter.com/profile/523661924') Alexander
|
||||
| . Dying to get that particular pet you're after, but don't want to wait for it to drop? Buy it here!
|
||||
| Welcome to the Market! I'm the merchant, Alexander. Dying to get that particular pet you're after, but don't want to wait for it to drop? Buy it here!
|
||||
|
||||
menu.inventory-list(type='list')
|
||||
li.customize-menu
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@
|
|||
.NPC-Matt
|
||||
.popover.static-popover.fade.right.in(style='max-width: 550px; margin-left: 10px;')
|
||||
.arrow
|
||||
h3.popover-title Matt Boch
|
||||
h3.popover-title
|
||||
a(target='_blank', href='http://www.kickstarter.com/profile/mattboch') Matt Boch
|
||||
.popover-content
|
||||
p
|
||||
| Welcome to the Stable! I'm
|
||||
a(target='_blank', href='http://www.kickstarter.com/profile/mattboch') Matt
|
||||
| , the beast master. Choose a pet here to adventure at your side - they aren't much help yet, but I forsee a time when they're able to
|
||||
| Welcome to the Stable! I'm Matt, the beast master. Choose a pet here to adventure at your side - they aren't much help yet, but I forsee a time when they're able to
|
||||
a(href='https://trello.com/card/mounts/50e5d3684fe3a7266b0036d6/221') grow into powerful steeds
|
||||
| ! Until that day,
|
||||
a(target='_blank', href='https://f.cloud.github.com/assets/2374703/164631/3ed5fa6c-78cd-11e2-8743-f65ac477b55e.png') have a look-see
|
||||
|
|
|
|||
Loading…
Reference in a new issue