Check previous gear owned before purchasing next level gear (fixes #9071) (#9466)

* add another check if previous gear is owned

* respect gear purchase order

* catch error with miscalculation of equipment number floor

* add integration test for proper equipment purchasing order

* fix syntax

* add 'previousGearNotOwned' string

* rewrite logic for different starting levels for wep vs others

* separate and add tests for armor and weapon

* rename variable for clarification

* skip check if itemIndex is NaN

* change obscure NaN check for readability

* change conditional from checking NaN to Int
This commit is contained in:
Julius Jung
2017-12-05 14:58:12 -05:00
committed by Sabe Jones
parent bfaa7c0fea
commit d4bc7c77a9
3 changed files with 35 additions and 2 deletions
+12
View File
@@ -35,6 +35,18 @@ module.exports = function buyGear (user, req = {}, analytics) {
throw new NotAuthorized(i18n.t('equipmentAlreadyOwned', req.language));
}
let itemIndex = Number(item.index);
if (Number.isInteger(itemIndex)) {
let previousLevelGear = key.replace(/[0-9]/, itemIndex - 1);
let hasPreviousLevelGear = user.items.gear.owned[previousLevelGear];
let checkIndexToType = itemIndex > (item.type === 'weapon' ? 0 : 1);
if (checkIndexToType && !hasPreviousLevelGear) {
throw new NotAuthorized(i18n.t('previousGearNotOwned', req.language));
}
}
if (user.preferences.autoEquip) {
user.items.gear.equipped[item.type] = item.key;
message = handleTwoHanded(user, item, undefined, req);