* 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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user