diff --git a/test/common/ops/buyHealthPotion.js b/test/common/ops/buyHealthPotion.js index b7d6191c75..e79a063093 100644 --- a/test/common/ops/buyHealthPotion.js +++ b/test/common/ops/buyHealthPotion.js @@ -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(); + } + }); }); }); diff --git a/website/common/locales/en/messages.json b/website/common/locales/en/messages.json index 1ed065d43f..a470121ac4 100644 --- a/website/common/locales/en/messages.json +++ b/website/common/locales/en/messages.json @@ -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?", diff --git a/website/common/locales/en@pirate/messages.json b/website/common/locales/en@pirate/messages.json index 0b44cfd966..a3231f47cf 100644 --- a/website/common/locales/en@pirate/messages.json +++ b/website/common/locales/en@pirate/messages.json @@ -56,4 +56,4 @@ "messageUserOperationNotFound": "<%= operation %> operation not be here", "messageNotificationNotFound": "Notification not found.", "notificationsRequired": "Notification ids are required." -} \ No newline at end of file +} diff --git a/website/common/locales/es/messages.json b/website/common/locales/es/messages.json index 8f8f1d4e40..17951ef0ef 100644 --- a/website/common/locales/es/messages.json +++ b/website/common/locales/es/messages.json @@ -56,4 +56,4 @@ "messageUserOperationNotFound": "<%= operation %> no encontrado", "messageNotificationNotFound": "Notificación no encontrada.", "notificationsRequired": "Se requieren ids de notificación." -} \ No newline at end of file +} diff --git a/website/common/locales/es_419/messages.json b/website/common/locales/es_419/messages.json index 5b4cfdd974..a81dd8f0ff 100644 --- a/website/common/locales/es_419/messages.json +++ b/website/common/locales/es_419/messages.json @@ -56,4 +56,4 @@ "messageUserOperationNotFound": "<%= operation %> operación no encontrada", "messageNotificationNotFound": "Notificación no encontrada.", "notificationsRequired": "Se requiere el ID de notificación." -} \ No newline at end of file +} diff --git a/website/common/script/ops/buyHealthPotion.js b/website/common/script/ops/buyHealthPotion.js index c2705d91bf..8ca087817a 100644 --- a/website/common/script/ops/buyHealthPotion.js +++ b/website/common/script/ops/buyHealthPotion.js @@ -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;