def _successHandler(self, code, ctx=None): additionalMessages = [] if ctx.get('shells', []): totalPrice = MONEY_UNDEFINED for shellCompDescr, price, count in ctx.get('shells', []): price = Money.makeFromMoneyTuple(price) shell = self.itemsCache.items.getItemByCD(shellCompDescr) additionalMessages.append( makeI18nSuccess('shell_buy/success', name=shell.userName, count=count, money=formatPrice(price), type=self._getSysMsgType(price))) totalPrice += price additionalMessages.append( makeI18nSuccess('layout_apply/success_money_spent', money=formatPrice(totalPrice), type=self._getSysMsgType(totalPrice))) if ctx.get('eqs', []): for eqCompDescr, price, count in ctx.get('eqs', []): price = Money.makeFromMoneyTuple(price) equipment = self.itemsCache.items.getItemByCD(eqCompDescr) additionalMessages.append( makeI18nSuccess('artefact_buy/success', kind=equipment.userType, name=equipment.userName, count=count, money=formatPrice(price), type=self._getSysMsgType(price))) return makeSuccess(auxData=additionalMessages)
def __init__(self, intCompactDescr, proxy=None, isBoughtForAltPrice=False): """ Ctr. :param intCompactDescr: item's int compact descriptor :param proxy: instance of ItemsRequester :param isBoughtForAltPrice: indicates whether the item has been bought for credits(alt price) """ GUIItem.__init__(self, proxy) HasIntCD.__init__(self, intCompactDescr) self._isBoughtForAltPrice = isBoughtForAltPrice self._rentInfo = RentalInfoProvider() self._restoreInfo = None self._personalDiscountPrice = None if proxy is not None and proxy.inventory.isSynced( ) and proxy.stats.isSynced() and proxy.shop.isSynced(): self._mayConsumeWalletResources = proxy.stats.mayConsumeWalletResources defaultPrice = proxy.shop.defaults.getItemPrice(self.intCD) if defaultPrice is None: defaultPrice = MONEY_UNDEFINED buyPrice, self._isHidden = proxy.shop.getItem(self.intCD) if buyPrice is None: buyPrice = MONEY_UNDEFINED altPrice = self._getAltPrice(buyPrice, proxy.shop) defaultAltPrice = self._getAltPrice(defaultPrice, proxy.shop.defaults) self._buyPrices = ItemPrices( itemPrice=ItemPrice(price=buyPrice, defPrice=defaultPrice), itemAltPrice=ItemPrice(price=altPrice, defPrice=defaultAltPrice)) defaultSellPrice = Money.makeFromMoneyTuple( BigWorld.player().shop.getSellPrice( defaultPrice, proxy.shop.defaults.sellPriceModifiers(intCompactDescr), self.itemTypeID)) sellPrice = Money.makeFromMoneyTuple( BigWorld.player().shop.getSellPrice( buyPrice, proxy.shop.sellPriceModifiers(intCompactDescr), self.itemTypeID)) self._sellPrices = ItemPrices(itemPrice=ItemPrice( price=sellPrice, defPrice=defaultSellPrice), itemAltPrice=ITEM_PRICE_EMPTY) self._inventoryCount = proxy.inventory.getItems( self.itemTypeID, self.intCD) if self._inventoryCount is None: self._inventoryCount = 0 self._isUnlocked = self.intCD in proxy.stats.unlocks self._isInitiallyUnlocked = self.intCD in proxy.stats.initialUnlocks self._fullyConfigured = True else: self._buyPrices = ITEM_PRICES_EMPTY self._sellPrices = ITEM_PRICES_EMPTY self._isHidden = False self._inventoryCount = 0 self._isUnlocked = False self._mayConsumeWalletResources = False self._isInitiallyUnlocked = False self._fullyConfigured = False return
def __init__(self, intCompactDescr, proxy=None, isBoughtForAltPrice=False, strCD=None): super(FittingItem, self).__init__(intCD=HasIntCD(intCompactDescr), strCD=strCD) self._isBoughtForAltPrice = isBoughtForAltPrice self._rentInfo = RentalInfoProvider(None, None, None, None, None, None) self._restoreInfo = None self._personalDiscountPrice = None self._descriptor = self._getDescriptor() if proxy is not None and proxy.inventory.isSynced( ) and proxy.stats.isSynced() and proxy.shop.isSynced(): self._mayConsumeWalletResources = proxy.stats.mayConsumeWalletResources defaultPrice = proxy.shop.defaults.getItemPrice(self.intCD) if defaultPrice is None: defaultPrice = MONEY_UNDEFINED buyPrice, self._isHidden = proxy.shop.getItem(self.intCD) if buyPrice is None: buyPrice = MONEY_UNDEFINED altPrice = self._getAltPrice(buyPrice, proxy.shop) defaultAltPrice = self._getAltPrice(defaultPrice, proxy.shop.defaults) self._buyPrices = ItemPrices( itemPrice=ItemPrice(price=buyPrice, defPrice=defaultPrice), itemAltPrice=ItemPrice(price=altPrice, defPrice=defaultAltPrice)) defaultSellPrice = Money.makeFromMoneyTuple( BigWorld.player().shop.getSellPrice( defaultPrice, proxy.shop.defaults.sellPriceModifiers(intCompactDescr), self.itemTypeID)) sellPrice = Money.makeFromMoneyTuple( BigWorld.player().shop.getSellPrice( buyPrice, proxy.shop.sellPriceModifiers(intCompactDescr), self.itemTypeID)) self._sellPrices = ItemPrices(itemPrice=ItemPrice( price=sellPrice, defPrice=defaultSellPrice), itemAltPrice=ITEM_PRICE_EMPTY) self._inventoryCount = proxy.inventory.getItems( self.itemTypeID, self.intCD) if self._inventoryCount is None: self._inventoryCount = 0 self._isUnlocked = self.intCD in proxy.stats.unlocks self._isInitiallyUnlocked = self.intCD in proxy.stats.initialUnlocks self._fullyConfigured = True else: self._buyPrices = ITEM_PRICES_EMPTY self._sellPrices = ITEM_PRICES_EMPTY self._isHidden = False self._inventoryCount = 0 self._isUnlocked = False self._mayConsumeWalletResources = False self._isInitiallyUnlocked = False self._fullyConfigured = False return
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 calcRentPackages(vehicle, proxy): result = [] if proxy is not None and vehicle.isRentable: rentCost = proxy.shop.getVehicleRentPrices().get(vehicle.intCD, {}) defaultRentCost = proxy.shop.defaults.getVehicleRentPrices().get(vehicle.intCD, {}) if len(rentCost) and len(defaultRentCost) is not None: for key in sorted(rentCost.keys()): rentPrice = Money.makeFromMoneyTuple(rentCost[key].get('cost', ())) defaultRentPrice = Money.makeFromMoneyTuple(defaultRentCost.get(key, {}).get('cost', rentPrice)) result.append({'days': key, 'rentPrice': rentPrice, 'defaultRentPrice': defaultRentPrice}) return result
def calcVehicleRestorePrice(defaultPrice, proxy): exchangeRate = proxy.exchangeRate sellPriceFactor = proxy.sellPriceModif restorePriceModif = proxy.vehiclesRestoreConfig.restorePriceModif return Money.makeFromMoneyTuple( getVehicleRestorePrice(defaultPrice, exchangeRate, sellPriceFactor, restorePriceModif))
def __new__(cls, additionalData=None, time=0, battles=0, wins=0, isRented=False, *args, **kwargs): additionalData = additionalData or {} if 'compensation' in additionalData: compensations = Money.makeFromMoneyTuple(additionalData['compensation']) else: compensations = MONEY_UNDEFINED result = _RentalInfoProvider.__new__(cls, time, compensations, battles, wins, isRented) return result
def getItemsIterator(self, nationID=None, itemTypeID=None): hiddenInShop = self.data.get('notInShopItems', []) sellForGold = self.data.get('vehiclesToSellForGold', []) prices = self.getPrices() for intCD in self.__getListOfCompDescrs(nationID, itemTypeID): if intCD in prices: yield (intCD, Money.makeFromMoneyTuple(prices[intCD]), intCD in hiddenInShop, intCD in sellForGold)
def calcVehicleRestorePrice(defaultPrice, proxy): """ # calculate vehicle restore price :param defaultPrice: <Money> default buy price :return: <Money> restore price """ exchangeRate = proxy.exchangeRate sellPriceFactor = proxy.sellPriceModif restorePriceModif = proxy.vehiclesRestoreConfig.restorePriceModif return Money.makeFromMoneyTuple(getVehicleRestorePrice(defaultPrice, exchangeRate, sellPriceFactor, restorePriceModif))
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 _successHandler(self, code, ctx=None): additionalMessages = [] if ctx: additionalMessages = [ ItemBuyProcessorMessage( self.itemsCache.items.getItemByCD(cd), count, Money.makeFromMoneyTuple(price)).makeSuccessMsg() for cd, price, count in ctx.get('eqs', []) ] return makeSuccess(auxData=additionalMessages)
def _successHandler(self, code, ctx=None): additionalMessages = [] totalPrice = ZERO_MONEY if ctx: for cd, price, count in ctx.get('shells', []): money = Money.makeFromMoneyTuple(price) additionalMessages.append(ItemBuyProcessorMessage(self.itemsCache.items.getItemByCD(cd), count, money).makeSuccessMsg()) totalPrice += money if totalPrice: additionalMessages.append(ShellsApplyProcessorMessage(self.__vehicle, totalPrice).makeSuccessMsg()) return makeSuccess(auxData=additionalMessages)
def _getCompensationMoney(bonuses): money = ZERO_MONEY for bonusName, bonusValue in bonuses.iteritems(): if bonusName == 'vehicles': vehicles = itertools.chain.from_iterable( [vehBonus.itervalues() for vehBonus in bonusValue]) for vehData in vehicles: if 'customCompensation' in vehData: money += Money.makeFromMoneyTuple( vehData['customCompensation']) return money
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 getRentPriceOfPackage(self, vehicle, rentType, packageID, package): rentPrice = package.get('cost', (0, 0)) if rentType == RentType.SEASON_RENT: seasonType = package.get('seasonType', None) cycleRentPrice = package.get('defaultCycleCost', (0, 0)) season = self.seasonsController.getCurrentSeason(seasonType) if season is not None and season.getSeasonID() == packageID: numCycles = len(season.getAllCycles()) cycleOrdinalNumber = season.getCycleOrdinalNumber() if vehicle.isRented: activeSeasonRent = vehicle.currentSeasonRent if activeSeasonRent and activeSeasonRent.duration == SeasonRentDuration.SEASON_CYCLE and activeSeasonRent.seasonID == season.getCycleID() and cycleOrdinalNumber + 1 <= numCycles: cycleOrdinalNumber += 1 rentPrice = calculateSeasonRentPrice(cycleRentPrice, rentPrice, cycleOrdinalNumber - 1, numCycles) return Money.makeFromMoneyTuple(rentPrice)
def __new__(cls, additionalData=None, time=0, battles=0, wins=0, seasonRent=None, isRented=False, *args, **kwargs): additionalData = additionalData or {} if 'compensation' in additionalData: compensations = Money.makeFromMoneyTuple( additionalData['compensation']) else: compensations = MONEY_UNDEFINED isWotPlus = WOTPLUS_RENT_KEY in additionalData isTelecomRent = TELECOM_RENTALS_RENT_KEY in additionalData result = _RentalInfoProvider.__new__(cls, time, compensations, battles, wins, seasonRent or {}, isRented, isWotPlus, isTelecomRent) return result
def __getInitialVO(self): vehicle = self.itemsCache.items.getItemByCD(self.__vehicleIntCD) rentalTermSlots = [] statsMoney = self.itemsCache.items.stats.money isRestoreAvailable = vehicle.isRestoreAvailable() if isRestoreAvailable: isEnough = vehicle.restorePrice <= statsMoney or isIngameShopEnabled( ) isEnoughStatuses = Money.makeFromMoneyTuple( (isEnough, isEnough, isEnough)) enabled = isRestoreAvailable or not (constants.IS_CHINA and vehicle.rentalIsActive) rentalTermSlots.append({ 'itemId': -1, 'label': i18n.makeString(STORE.BUYVEHICLEWINDOW_RESTORE), 'price': getItemPricesVO( ItemPrice(vehicle.restorePrice, vehicle.restorePrice)), 'enabled': enabled, 'selected': self.__selectedRentTerm <= _NOT_RENT_IDX, 'isEnough': isEnough, 'isEnoughStatuses': getMoneyVO(isEnoughStatuses) }) rentPackages = vehicle.rentPackages for rentPackageId in xrange(len(rentPackages)): rentPackage = rentPackages[rentPackageId] days = rentPackage['days'] standartRentDays = STORE.getRentTermDays(days) price = ItemPrice(rentPackage['rentPrice'], rentPackage['defaultRentPrice']) isEnough = statsMoney >= price.price or isIngameShopEnabled() isEnoughStatuses = Money.makeFromMoneyTuple( (isEnough, isEnough, isEnough)) enabled = vehicle.maxRentDuration - vehicle.rentLeftTime >= days * time_utils.ONE_DAY rentalTermSlots.append({ 'itemId': rentPackageId, 'label': standartRentDays if standartRentDays is not None else i18n.makeString(STORE.RENTALTERMSELECTIONPOPOVER_TERMSLOTANY, days=days), 'price': getItemPricesVO(price), 'enabled': enabled, 'selected': self.__selectedRentTerm == days, 'isEnough': isEnough, 'isEnoughStatuses': getMoneyVO(isEnoughStatuses) }) if not isRestoreAvailable: isEnough = vehicle.buyPrices.itemPrice.price <= statsMoney or isIngameShopEnabled( ) isEnoughStatuses = Money.makeFromMoneyTuple( (isEnough, isEnough, isEnough)) enabled = not vehicle.isDisabledForBuy and not vehicle.isHidden rentalTermSlots.append({ 'itemId': _NOT_RENT_IDX, 'label': i18n.makeString( STORE.RENTALTERMSELECTIONPOPOVER_TERMSLOTUNLIM), 'price': getItemPricesVO(vehicle.buyPrices.itemPrice), 'enabled': enabled, 'selected': self.__selectedRentTerm <= _NOT_RENT_IDX, 'isEnough': isEnough, 'isEnoughStatuses': getMoneyVO(isEnoughStatuses) }) return { 'titleLabel': text_styles.highTitle(STORE.RENTALTERMSELECTIONPOPOVER_TITLELABEL), 'rentalTermSlots': rentalTermSlots }
def getPrice(self, intCD): return Money.makeFromMoneyTuple(self._getRawPrice(intCD))
def __getInitialVO(self): vehicle = self.itemsCache.items.getItemByCD(self.__vehicleIntCD) isEnoughStatuses = getMoneyVO( Money.makeFromMoneyTuple((True, True, True))) rentalTermSlots = [] isRestoreAvailable = vehicle.isRestoreAvailable() if isRestoreAvailable: enabled = isRestoreAvailable or not (constants.IS_CHINA and vehicle.rentalIsActive) rentalTermSlots.append({ 'itemId': -1, 'label': i18n.makeString(STORE.BUYVEHICLEWINDOW_RESTORE), 'price': getItemPricesVO( ItemPrice(vehicle.restorePrice, vehicle.restorePrice)), 'enabled': enabled, 'selected': self.__selectedRentID <= _NOT_RENT_IDX, 'isEnoughStatuses': isEnoughStatuses }) rentPackages = vehicle.rentPackages currentSeasonRent = vehicle.currentSeasonRent isSeasonRented = currentSeasonRent is not None for rentPackageIdx, rentPackage in enumerate(rentPackages): rentID = rentPackage['rentID'] rentType, packageID = parseRentID(rentID) if rentType == constants.RentType.TIME_RENT: days = packageID standardRentDays = STORE.getRentTermDays(days) if standardRentDays is not None: label = standardRentDays else: label = i18n.makeString( STORE.RENTALTERMSELECTIONPOPOVER_TERMSLOTANY, days=days) inMaxRentTime = isWithinMaxRentTime(vehicle.maxRentDuration, vehicle.rentLeftTime, days) enabled = not isSeasonRented and inMaxRentTime elif rentType in (constants.RentType.SEASON_RENT, constants.RentType.SEASON_CYCLE_RENT): seasonType = rentPackage['seasonType'] label = i18n.makeString( _SEASON_RENT_TERMS[seasonType][rentType]) if rentType == constants.RentType.SEASON_RENT: enabled = not isSeasonRented or isSeasonRented and currentSeasonRent.duration == SeasonRentDuration.SEASON_CYCLE else: enabled = not isSeasonRented else: raise SoftException( 'Unsupported rental type [{}]!'.format(rentType)) price = ItemPrice(rentPackage['rentPrice'], rentPackage['defaultRentPrice']) rentalTermSlots.append({ 'itemId': rentPackageIdx, 'label': label, 'price': getItemPricesVO(price), 'enabled': enabled, 'selected': self.__selectedRentID == rentID, 'isEnoughStatuses': isEnoughStatuses }) if not isRestoreAvailable: enabled = not vehicle.isDisabledForBuy and not vehicle.isHidden rentalTermSlots.append({ 'itemId': _NOT_RENT_IDX, 'label': i18n.makeString( STORE.RENTALTERMSELECTIONPOPOVER_TERMSLOTUNLIM), 'price': getItemPricesVO(vehicle.buyPrices.itemPrice), 'enabled': enabled, 'selected': self.__selectedRentID <= _NOT_RENT_IDX, 'isEnoughStatuses': isEnoughStatuses }) return { 'titleLabel': text_styles.highTitle(STORE.RENTALTERMSELECTIONPOPOVER_TITLELABEL), 'rentalTermSlots': rentalTermSlots }