def getVehicleSlotsItemPrice(self, currentSlotsCount): defPrice = self.defaults.getVehicleSlotsPrice(currentSlotsCount) price = self.getVehicleSlotsPrice(currentSlotsCount) slotGoodies = self.personalSlotDiscounts if slotGoodies: bestGoody = self.bestGoody(slotGoodies) price = getPriceWithDiscount(price, bestGoody.resource) return ItemPrice(price=Money.makeFrom(Currency.GOLD, price), defPrice=Money.makeFrom(Currency.GOLD, defPrice))
def _getByuContentData(self, vehicle, stats, isTradeIn): shop = self.itemsCache.items.shop shopDefaults = shop.defaults tankMenCount = len(vehicle.crew) vehiclePricesActionData = self._getItemPriceActionData(vehicle) ammoPrice = ITEM_PRICE_EMPTY for shell in vehicle.gun.defaultAmmo: ammoPrice += shell.buyPrices.itemPrice * shell.defaultCount ammoActionPriceData = None if ammoPrice.isActionPrice(): ammoActionPriceData = packActionTooltipData(ACTION_TOOLTIPS_TYPE.AMMO, str(vehicle.intCD), True, ammoPrice.price, ammoPrice.defPrice) slotPrice = shop.getVehicleSlotsPrice(stats.vehicleSlots) slotDefaultPrice = shopDefaults.getVehicleSlotsPrice(stats.vehicleSlots) slotActionPriceData = None if slotPrice != slotDefaultPrice: slotActionPriceData = packActionTooltipData(ACTION_TOOLTIPS_TYPE.ECONOMICS, 'slotsPrices', True, Money(gold=slotPrice), Money(gold=slotDefaultPrice)) tankmenTotalLabel = i18n.makeString(DIALOGS.BUYVEHICLEWINDOW_TANKMENTOTALLABEL, count=str(tankMenCount)) studyData = [] for index, (tCost, defTCost, typeID) in enumerate(zip(shop.tankmanCostWithGoodyDiscount, shopDefaults.tankmanCost, ('free', 'school', 'academy'))): if tCost['isPremium']: currency = Currency.GOLD else: currency = Currency.CREDITS price = tCost[currency] * tankMenCount defPrice = defTCost[currency] * tankMenCount totalPrice = Money.makeFrom(currency, price) totalDefPrice = Money.makeFrom(currency, defPrice) if typeID == 'free': formatedPrice = i18n.makeString(MENU.TANKMANTRAININGWINDOW_FREE_PRICE) else: formatedPrice = moneyWithIcon(totalPrice, currType=currency) studyPriceActionData = None if price != defPrice: studyPriceActionData = packActionTooltipData(ACTION_TOOLTIPS_TYPE.ECONOMICS, '%sTankmanCost' % currency, True, totalPrice, totalDefPrice) studyData.insert(0, {'id': typeID, 'price': price, 'crewType': index, 'actionPrice': studyPriceActionData, 'label': '%d%% - %s' % (tCost['roleLevel'], formatedPrice)}) initData = {'tankmenTotalLabel': tankmenTotalLabel, 'vehiclePrices': self._getVehiclePrice(vehicle).toMoneyTuple(), 'vehiclePricesActionData': vehiclePricesActionData, 'isRentable': vehicle.isRentable, 'rentDataDD': self._getRentData(vehicle, vehiclePricesActionData), 'ammoPrice': ammoPrice.price.getSignValue(Currency.CREDITS), 'ammoActionPriceData': ammoActionPriceData, 'slotPrice': slotPrice, 'slotActionPriceData': slotActionPriceData, 'isStudyDisabled': vehicle.hasCrew, 'isNoAmmo': not vehicle.hasShells, 'studyData': studyData, 'nation': self.nationID} initData.update(self._getContentFields(vehicle)) if isTradeIn: initData.update(self.__getTradeInContentFields(vehicle)) return initData
def formatActionPrices(oldPrice, newPrice, isBuying, checkGold=False): oldPrice = Money.makeFromMoneyTuple(oldPrice) if not oldPrice.isDefined(): oldPrice = Money(credits=0) newPrice = Money.makeFromMoneyTuple(newPrice) if not newPrice.isDefined(): newPrice = Money.makeFrom(oldPrice.getCurrency(), 0) return (_getFormattedPrice(oldPrice, isBuying, checkGold), _getFormattedPrice(newPrice, isBuying, checkGold))
def getActionPrcAsMoney(self): actionPrc = MONEY_UNDEFINED if self.isActionPrice(): for currency in Currency.ALL: prc = getActionPrc(self.__price.get(currency), self.__defPrice.get(currency)) actionPrc += Money.makeFrom(currency, prc if prc else None) return actionPrc
def getBoosterPriceData(self, boosterID): shop = self._items.shop prices = Money.makeFromMoneyTuple( shop.getBoosterPricesTuple(boosterID)) defPrices = Money.makeFromMoneyTuple( shop.defaults.getBoosterPricesTuple(boosterID)) if prices.isCompound(): currency = prices.getCurrency(byWeight=True) buyPrice = Money.makeFrom(currency, prices.get(currency)) defPrice = Money.makeFrom(currency, defPrices.getSignValue(currency)) altPrice = prices.replace(currency, None) defAltPrice = defPrices.replace(currency, None) else: buyPrice = prices defPrice = defPrices altPrice = None defAltPrice = None return (buyPrice, defPrice, altPrice, defAltPrice)
def getActionPrcAsMoney(self): """ Returns discount/penalty percent as Money. MONEY_UNDEFINED - if no action. :return: Money, where each element - percent value for a currency. """ actionPrc = MONEY_UNDEFINED if self.isActionPrice(): for currency in Currency.ALL: prc = getActionPrc(self.__price.get(currency), self.__defPrice.get(currency)) actionPrc += Money.makeFrom(currency, prc if prc else None) return actionPrc
def getBoosterPriceData(self, boosterID): """ Gets tuple of booster price-related data: (buy price, def price, alt price, def alt price, is booster hidden). """ shop = self._items.shop prices = Money.makeFromMoneyTuple(shop.getBoosterPricesTuple(boosterID)) defPrices = Money.makeFromMoneyTuple(shop.defaults.getBoosterPricesTuple(boosterID)) if prices.isCompound(): currency = prices.getCurrency(byWeight=True) buyPrice = Money.makeFrom(currency, prices.get(currency)) defPrice = Money.makeFrom(currency, defPrices.getSignValue(currency)) altPrice = prices.replace(currency, None) defAltPrice = defPrices.replace(currency, None) else: buyPrice = prices defPrice = defPrices altPrice = None defAltPrice = None return (buyPrice, defPrice, altPrice, defAltPrice, boosterID in shop.getHiddenBoosters())
def _tryParseProductInfo(responseBody): try: productInfo = json.loads(responseBody) data = productInfo['data'] priceSection = data['price'] buySection = data['links']['buy'] return _ProductInfo(price=Money.makeFrom(priceSection.get('currency', 'credits'), int(priceSection.get('value', 0))), href=buySection['href'], method=buySection['method']) except (TypeError, KeyError, ValueError, IndexError) as e: _logger.exception(e) return None