mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
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:
@@ -76,5 +76,35 @@ describe('shared.ops.buyHealthPotion', () => {
|
|||||||
done();
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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.",
|
"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.",
|
"messageAlreadyOwnGear": "You already own this item. Equip it by going to the equipment page.",
|
||||||
"messageHealthAlreadyMax": "You already have maximum health.",
|
"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!",
|
"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?",
|
"armoireFood": "<%= image %> You rummage in the Armoire and find <%= dropArticle %><%= dropText %>. What's that doing in here?",
|
||||||
|
|||||||
@@ -56,4 +56,4 @@
|
|||||||
"messageUserOperationNotFound": "<%= operation %> operation not be here",
|
"messageUserOperationNotFound": "<%= operation %> operation not be here",
|
||||||
"messageNotificationNotFound": "Notification not found.",
|
"messageNotificationNotFound": "Notification not found.",
|
||||||
"notificationsRequired": "Notification ids are required."
|
"notificationsRequired": "Notification ids are required."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,4 @@
|
|||||||
"messageUserOperationNotFound": "<%= operation %> no encontrado",
|
"messageUserOperationNotFound": "<%= operation %> no encontrado",
|
||||||
"messageNotificationNotFound": "Notificación no encontrada.",
|
"messageNotificationNotFound": "Notificación no encontrada.",
|
||||||
"notificationsRequired": "Se requieren ids de notificación."
|
"notificationsRequired": "Se requieren ids de notificación."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,4 +56,4 @@
|
|||||||
"messageUserOperationNotFound": "<%= operation %> operación no encontrada",
|
"messageUserOperationNotFound": "<%= operation %> operación no encontrada",
|
||||||
"messageNotificationNotFound": "Notificación no encontrada.",
|
"messageNotificationNotFound": "Notificación no encontrada.",
|
||||||
"notificationsRequired": "Se requiere el ID de notificación."
|
"notificationsRequired": "Se requiere el ID de notificación."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ module.exports = function buyHealthPotion (user, req = {}, analytics) {
|
|||||||
throw new NotAuthorized(i18n.t('messageHealthAlreadyMax', req.language));
|
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;
|
user.stats.hp += 15;
|
||||||
if (user.stats.hp > 50) {
|
if (user.stats.hp > 50) {
|
||||||
user.stats.hp = 50;
|
user.stats.hp = 50;
|
||||||
|
|||||||
Reference in New Issue
Block a user