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:
@@ -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;
|
||||
|
||||
@@ -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 %>.",
|
||||
|
||||
Reference in New Issue
Block a user