mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Allow user to buy numbered special gear (#9823)
* fix(buy): allow user to buy numbered special gear * fix(buy): correct content constant
This commit is contained in:
@@ -138,5 +138,27 @@ describe('shared.ops.buyGear', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not buyGear equipment if user does not own prior item in sequence', (done) => {
|
||||||
|
user.stats.gp = 200;
|
||||||
|
|
||||||
|
try {
|
||||||
|
buyGear(user, {params: {key: 'armor_warrior_2'}});
|
||||||
|
} catch (err) {
|
||||||
|
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||||
|
expect(err.message).to.equal(i18n.t('previousGearNotOwned'));
|
||||||
|
expect(user.items.gear.owned).to.not.have.property('armor_warrior_2');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does buyGear equipment if item is a numbered special item user qualifies for', () => {
|
||||||
|
user.stats.gp = 200;
|
||||||
|
user.items.gear.owned.head_special_2 = false;
|
||||||
|
|
||||||
|
buyGear(user, {params: {key: 'head_special_2'}});
|
||||||
|
|
||||||
|
expect(user.items.gear.owned).to.have.property('head_special_2', true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ module.exports = function buyGear (user, req = {}, analytics) {
|
|||||||
|
|
||||||
let itemIndex = Number(item.index);
|
let itemIndex = Number(item.index);
|
||||||
|
|
||||||
if (Number.isInteger(itemIndex)) {
|
if (Number.isInteger(itemIndex) && content.classes.includes(item.klass)) {
|
||||||
let previousLevelGear = key.replace(/[0-9]/, itemIndex - 1);
|
let previousLevelGear = key.replace(/[0-9]/, itemIndex - 1);
|
||||||
let hasPreviousLevelGear = user.items.gear.owned[previousLevelGear];
|
let hasPreviousLevelGear = user.items.gear.owned[previousLevelGear];
|
||||||
let checkIndexToType = itemIndex > (item.type === 'weapon' ? 0 : 1);
|
let checkIndexToType = itemIndex > (item.type === 'weapon' || item.type === 'shield' && item.klass === 'rogue' ? 0 : 1);
|
||||||
|
|
||||||
if (checkIndexToType && !hasPreviousLevelGear) {
|
if (checkIndexToType && !hasPreviousLevelGear) {
|
||||||
throw new NotAuthorized(i18n.t('previousGearNotOwned', req.language));
|
throw new NotAuthorized(i18n.t('previousGearNotOwned', req.language));
|
||||||
@@ -52,7 +52,6 @@ module.exports = function buyGear (user, req = {}, analytics) {
|
|||||||
message = handleTwoHanded(user, item, undefined, req);
|
message = handleTwoHanded(user, item, undefined, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
removePinnedGearAddPossibleNewOnes(user, `gear.flat.${item.key}`, item.key);
|
removePinnedGearAddPossibleNewOnes(user, `gear.flat.${item.key}`, item.key);
|
||||||
|
|
||||||
if (item.last) ultimateGear(user);
|
if (item.last) ultimateGear(user);
|
||||||
|
|||||||
Reference in New Issue
Block a user