Pet Hatching Item Overbuy Warning (#11313)

* fix(shops): warn if user is purchasing too many pet-hatching items

* fix(shops): handle undefined potion count
This commit is contained in:
Sabe Jones
2019-09-10 11:22:14 -04:00
committed by GitHub
parent 74c654d9fc
commit 36f6860e79
2 changed files with 25 additions and 0 deletions
@@ -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;
+1
View File
@@ -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 %>.",