From 36f6860e7993da6f8e34cf83003f87bfa44b2b67 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Tue, 10 Sep 2019 11:22:14 -0400 Subject: [PATCH] Pet Hatching Item Overbuy Warning (#11313) * fix(shops): warn if user is purchasing too many pet-hatching items * fix(shops): handle undefined potion count --- website/client/components/shops/buyModal.vue | 24 ++++++++++++++++++++ website/common/locales/en/character.json | 1 + 2 files changed, 25 insertions(+) diff --git a/website/client/components/shops/buyModal.vue b/website/client/components/shops/buyModal.vue index 99de909e01..a54b33deab 100644 --- a/website/client/components/shops/buyModal.vue +++ b/website/client/components/shops/buyModal.vue @@ -300,9 +300,14 @@ import Avatar from 'client/components/avatar'; import seasonalShopConfig from 'common/script/libs/shops-seasonal.config'; + import { drops as dropEggs } from 'common/script/content/eggs'; + import keys from 'lodash/keys'; + import reduce from 'lodash/reduce'; import moment from 'moment'; + const dropEggKeys = keys(dropEggs); + const hideAmountSelectionForPurchaseTypes = [ 'gear', 'backgrounds', 'mystery_set', 'card', 'rebirth_orb', 'fortify', 'armoire', 'keys', @@ -402,6 +407,25 @@ return; } + if (this.item.pinType === 'premiumHatchingPotion' || this.item.pinType === 'eggs' && dropEggKeys.indexOf(this.item.key) === -1) { + let petsRemaining = 20 - this.selectedAmountToBuy; + petsRemaining -= reduce(this.user.items.pets, (sum, petValue, petKey) => { + if (petKey.indexOf(this.item.key) !== -1 && petValue > 0) return sum + 1; + return sum; + }, 0); + petsRemaining -= reduce(this.user.items.mounts, (sum, mountValue, mountKey) => { + if (mountKey.indexOf(this.item.key) !== -1 && mountValue === true) return sum + 1; + return sum; + }, 0); + if (this.item.pinType === 'premiumHatchingPotion') { + petsRemaining -= this.user.items.hatchingPotions[this.item.key] + 2 || 2; + } else { + petsRemaining -= this.user.items.eggs[this.item.key] || 0; + } + + if (petsRemaining < 0 && !confirm(this.$t('purchasePetItemConfirm', {itemText: this.item.text}))) return; + } + const shouldConfirmPurchase = this.item.currency === 'gems' || this.item.currency === 'hourglasses'; if (shouldConfirmPurchase && !this.confirmPurchase(this.item.currency, this.item.value * this.selectedAmountToBuy)) { return; diff --git a/website/common/locales/en/character.json b/website/common/locales/en/character.json index 8a1d6160c6..92a6cddb98 100644 --- a/website/common/locales/en/character.json +++ b/website/common/locales/en/character.json @@ -171,6 +171,7 @@ "purchaseFor": "Purchase for <%= cost %> Gems?", "purchaseForGold": "Purchase for <%= cost %> Gold?", "purchaseForHourglasses": "Purchase for <%= cost %> Hourglasses?", + "purchasePetItemConfirm": "This purchase would exceed the number of items you need to hatch all possible <%= itemText %> pets. Are you sure?", "notEnoughMana": "Not enough mana.", "invalidTarget": "You can't cast a skill on that.", "youCast": "You cast <%= spell %>.",