mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
classes: fixes to buying special-gear & regular gear habitrpg-shared#ee4777d
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
db.users.find().forEach(function(user){
|
db.users.find().forEach(function(user){
|
||||||
|
|
||||||
|
user.stats.class = 'warrior';
|
||||||
|
|
||||||
// grant backer/contrib gear, rather than using js logic
|
// grant backer/contrib gear, rather than using js logic
|
||||||
|
|
||||||
// migrate current owned items
|
// migrate current owned items
|
||||||
|
|||||||
@@ -106,17 +106,30 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', '
|
|||||||
|
|
||||||
var updateStore = function(){
|
var updateStore = function(){
|
||||||
var updated = window.habitrpgShared.items.updateStore(User.user);
|
var updated = window.habitrpgShared.items.updateStore(User.user);
|
||||||
// Figure out whether we wanna put this in habitrpg-shared
|
// Do we wanna put this in habitrpg-shared?
|
||||||
var sorted = [updated.weapon, updated.armor, updated.head, updated.shield, updated.potion, updated.reroll];
|
var sorted = _.chain(updated)
|
||||||
|
.toArray()
|
||||||
|
.sortBy(function(item){
|
||||||
|
switch (item.type) {
|
||||||
|
case 'weapon': return 1;
|
||||||
|
case 'armor': return 2;
|
||||||
|
case 'head': return 3;
|
||||||
|
case 'shield': return 4;
|
||||||
|
case 'potion': return 5;
|
||||||
|
case 'reroll': return 6;
|
||||||
|
default: return 7;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.value();
|
||||||
$scope.itemStore = sorted;
|
$scope.itemStore = sorted;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStore();
|
updateStore();
|
||||||
|
|
||||||
$scope.buy = function(type) {
|
$scope.buy = function(item) {
|
||||||
var hasEnough = window.habitrpgShared.items.buyItem(User.user, type);
|
var hasEnough = window.habitrpgShared.items.buyItem(User.user, item);
|
||||||
if (hasEnough) {
|
if (hasEnough) {
|
||||||
User.log({op: "buy", type: type});
|
User.log({op: "buy", key: item.key});
|
||||||
Notification.text("Item purchased.");
|
Notification.text("Item purchased.");
|
||||||
updateStore();
|
updateStore();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -204,11 +204,11 @@ api.clearCompleted = function(req, res, next) {
|
|||||||
*/
|
*/
|
||||||
api.buy = function(req, res, next) {
|
api.buy = function(req, res, next) {
|
||||||
var user = res.locals.user;
|
var user = res.locals.user;
|
||||||
var type = req.params.type;
|
var key = req.params.key;
|
||||||
if (!type.match(/potion|weapon|armor|head|shield/)) { // if (item !== 'potion' && !items.items.gear.flat[item])
|
if (key !== 'potion' && !items.items.gear.flat[key]) {
|
||||||
return res.json(400, {err: ":item must be a supported key, see https://github.com/HabitRPG/habitrpg-shared/blob/master/script/items.coffee"});
|
return res.json(400, {err: ":item must be a supported key, see https://github.com/HabitRPG/habitrpg-shared/blob/master/script/items.coffee"});
|
||||||
}
|
}
|
||||||
var hasEnough = items.buyItem(user, type);
|
var hasEnough = items.buyItem(user, items.items.gear.flat[key]);
|
||||||
if (hasEnough) {
|
if (hasEnough) {
|
||||||
return user.save(function(err, saved) {
|
return user.save(function(err, saved) {
|
||||||
if (err) return res.json(500, {err: err});
|
if (err) return res.json(500, {err: err});
|
||||||
@@ -565,6 +565,7 @@ api.batchUpdate = function(req, res, next) {
|
|||||||
req.params.id = action.data && action.data.id;
|
req.params.id = action.data && action.data.id;
|
||||||
req.params.direction = action.dir;
|
req.params.direction = action.dir;
|
||||||
req.params.type = action.type;
|
req.params.type = action.type;
|
||||||
|
req.params.key = action.key;
|
||||||
req.body = action.data;
|
req.body = action.data;
|
||||||
res.send = res.json = function(code, data) {
|
res.send = res.json = function(code, data) {
|
||||||
if (_.isNumber(code) && code >= 400) {
|
if (_.isNumber(code) && code >= 400) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ if (nconf.get('NODE_ENV') == 'development') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Items*/
|
/* Items*/
|
||||||
router.post('/user/buy/:type', auth.auth, cron, user.buy);
|
router.post('/user/buy/:key', auth.auth, cron, user.buy);
|
||||||
|
|
||||||
/* User*/
|
/* User*/
|
||||||
router.get('/user', auth.auth, cron, user.getUser);
|
router.get('/user', auth.auth, cron, user.getUser);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ script(id='templates/habitrpg-tasks.html', type="text/ng-template")
|
|||||||
.task-controls
|
.task-controls
|
||||||
a.task-action-btn.btn-reroll(bo-if='item.type=="reroll"', ng-click='modals.reroll = true')
|
a.task-action-btn.btn-reroll(bo-if='item.type=="reroll"', ng-click='modals.reroll = true')
|
||||||
i.icon-repeat
|
i.icon-repeat
|
||||||
a.money.btn-buy.item-btn(bo-if='item.type!="reroll"', ng-click='buy(item.type)')
|
a.money.btn-buy.item-btn(bo-if='item.type!="reroll"', ng-click='buy(item)')
|
||||||
span.reward-cost {{item.value}}
|
span.reward-cost {{item.value}}
|
||||||
span.shop_gold
|
span.shop_gold
|
||||||
// main content
|
// main content
|
||||||
|
|||||||
Reference in New Issue
Block a user