Restrict users from getting back from death (#8808)

* Add test to prevent death users recovering health

* Add check for buying potions with zero health

* Validate hp <= 0 to take boss damage into account
This commit is contained in:
Oscar Rendón
2017-07-18 15:26:10 -05:00
committed by Sabe Jones
parent d918bc9f56
commit ab777f7006
6 changed files with 38 additions and 3 deletions

View File

@@ -76,5 +76,35 @@ describe('shared.ops.buyHealthPotion', () => {
done();
}
});
it('does not allow potion purchases when hp is zero', (done) => {
user.stats.hp = 0;
user.stats.gp = 40;
try {
buyHealthPotion(user);
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageHealthAlreadyMin'));
expect(user.stats.hp).to.eql(0);
expect(user.stats.gp).to.eql(40);
done();
}
});
it('does not allow potion purchases when hp is negative', (done) => {
user.stats.hp = -8;
user.stats.gp = 40;
try {
buyHealthPotion(user);
} catch (err) {
expect(err).to.be.an.instanceof(NotAuthorized);
expect(err.message).to.equal(i18n.t('messageHealthAlreadyMin'));
expect(user.stats.hp).to.eql(-8);
expect(user.stats.gp).to.eql(40);
done();
}
});
});
});

View File

@@ -31,6 +31,7 @@
"messageAlreadyPurchasedGear": "You purchased this gear in the past, but do not currently own it. You can buy it again in the rewards column on the tasks page.",
"messageAlreadyOwnGear": "You already own this item. Equip it by going to the equipment page.",
"messageHealthAlreadyMax": "You already have maximum health.",
"messageHealthAlreadyMin": "Oh no! You have already run out of health so it's too late to buy a health potion, but don't worry - you can revive!",
"armoireEquipment": "<%= image %> You found a piece of rare Equipment in the Armoire: <%= dropText %>! Awesome!",
"armoireFood": "<%= image %> You rummage in the Armoire and find <%= dropArticle %><%= dropText %>. What's that doing in here?",

View File

@@ -56,4 +56,4 @@
"messageUserOperationNotFound": "<%= operation %> operation not be here",
"messageNotificationNotFound": "Notification not found.",
"notificationsRequired": "Notification ids are required."
}
}

View File

@@ -56,4 +56,4 @@
"messageUserOperationNotFound": "<%= operation %> no encontrado",
"messageNotificationNotFound": "Notificación no encontrada.",
"notificationsRequired": "Se requieren ids de notificación."
}
}

View File

@@ -56,4 +56,4 @@
"messageUserOperationNotFound": "<%= operation %> operación no encontrada",
"messageNotificationNotFound": "Notificación no encontrada.",
"notificationsRequired": "Se requiere el ID de notificación."
}
}

View File

@@ -19,6 +19,10 @@ module.exports = function buyHealthPotion (user, req = {}, analytics) {
throw new NotAuthorized(i18n.t('messageHealthAlreadyMax', req.language));
}
if (user.stats.hp <= 0) {
throw new NotAuthorized(i18n.t('messageHealthAlreadyMin', req.language));
}
user.stats.hp += 15;
if (user.stats.hp > 50) {
user.stats.hp = 50;