def __init__(self, intCompactDescr, proxy = None, isBoughtForCredits = False): GUIItem.__init__(self, proxy) HasIntCD.__init__(self, intCompactDescr) self.defaultPrice = (0, 0) self._buyPrice = (0, 0) self.sellPrice = (0, 0) self.defaultSellPrice = (0, 0) self.altPrice = None self.defaultAltPrice = None self.sellActionPrc = 0 self.isHidden = False self.inventoryCount = 0 self.sellForGold = False self.isUnlocked = False self.isBoughtForCredits = isBoughtForCredits self.rentInfo = RentalInfoProvider() if proxy is not None and proxy.isSynced(): self.defaultPrice = proxy.shop.defaults.getItemPrice(self.intCompactDescr) if self.defaultPrice is None: self.defaultPrice = (0, 0) self._buyPrice, self.isHidden, self.sellForGold = proxy.shop.getItem(self.intCompactDescr) if self._buyPrice is None: self._buyPrice = (0, 0) self.defaultSellPrice = BigWorld.player().shop.getSellPrice(self.defaultPrice, proxy.shop.defaults.sellPriceModifiers(intCompactDescr), self.itemTypeID) self.sellPrice = BigWorld.player().shop.getSellPrice(self.buyPrice, proxy.shop.sellPriceModifiers(intCompactDescr), self.itemTypeID) self.inventoryCount = proxy.inventory.getItems(self.itemTypeID, self.intCompactDescr) if self.inventoryCount is None: self.inventoryCount = 0 self.isUnlocked = self.intCD in proxy.stats.unlocks self.altPrice = self._getAltPrice(self.buyPrice, proxy.shop) self.defaultAltPrice = self._getAltPrice(self.defaultPrice, proxy.shop.defaults) self.sellActionPrc = -1 * getActionPrc(self.sellPrice, self.defaultSellPrice) return
def __getEffectValue(self, vehicle): resoruce = self._goodieDescription.resource if resoruce.isPercentage: return resoruce.value defaultCreditPrice = vehicle.buyPrices.itemPrice.defPrice.getSignValue(Currency.CREDITS) discountCreditPrice = defaultCreditPrice - resoruce.value return getActionPrc(discountCreditPrice, defaultCreditPrice)
def getActionPrc(self): """ Returns discount/penalty percent as int. 0 - if no action. :return: int """ if self.isActionPrice(): return getActionPrc(self.__price, self.__defPrice) return 0
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 __getBoosterPrice(self, booster): block = [] money = g_itemsCache.items.stats.money if booster.buyPrice: price = booster.buyPrice defPrice = booster.defaultPrice need = price - money need = need.toNonNegative() leftPadding = 92 if price.credits > 0: creditsActionPercent = getActionPrc(price.credits, defPrice.credits) block.append(makePriceBlock(price.credits, CURRENCY_SETTINGS.BUY_CREDITS_PRICE, need.credits if need.credits > 0 else None, defPrice.credits if defPrice.credits > 0 else None, creditsActionPercent, leftPadding=leftPadding)) if price.gold > 0: goldActionPercent = getActionPrc(price.gold, defPrice.gold) if price.credits > 0: block.append(formatters.packTextBlockData(text=text_styles.standard(TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding(left=(101 if goldActionPercent > 0 else 81) + self.leftPadding))) block.append(makePriceBlock(price.gold, CURRENCY_SETTINGS.BUY_GOLD_PRICE, need.gold if need.gold > 0 else None, defPrice.gold if defPrice.gold > 0 else None, goldActionPercent, leftPadding=leftPadding)) return block
def _setItemPrice(self, model): if not self._price: return model.setCurrencyType(self._currency) model.setItemPrice(self._price.price.get(self._currency)) discount = getActionPrc(self._price.price, self._price.defPrice) model.setDiscount(discount) model.setIsAcceptDisabled(not self.isPriceInGold() and bool(self._shortage))
def __getEffectValue(self, vehicle): """ Calculates percent discount value for targeted vehicle """ resoruce = self._goodieDescription.resource if resoruce.isPercentage: return resoruce.value else: defaultCreditPrice = vehicle.defaultPrice.credits discountCreditPrice = defaultCreditPrice - resoruce.value return getActionPrc(discountCreditPrice, defaultCreditPrice)
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 __getBoosterPrice(self, booster): block = [] money = g_itemsCache.items.stats.money if booster.buyPrice: price = booster.buyPrice defPrice = booster.defaultPrice need = price - money need = need.toNonNegative() leftPadding = 92 if price.credits > 0: creditsActionPercent = getActionPrc(price.credits, defPrice.credits) block.append( makePriceBlock( price.credits, CURRENCY_SETTINGS.BUY_CREDITS_PRICE, need.credits if need.credits > 0 else None, defPrice.credits if defPrice.credits > 0 else None, creditsActionPercent, leftPadding=leftPadding)) if price.gold > 0: goldActionPercent = getActionPrc(price.gold, defPrice.gold) if price.credits > 0: block.append( formatters.packTextBlockData( text=text_styles.standard( TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding( left=(101 if goldActionPercent > 0 else 81) + self.leftPadding))) block.append( makePriceBlock( price.gold, CURRENCY_SETTINGS.BUY_GOLD_PRICE, need.gold if need.gold > 0 else None, defPrice.gold if defPrice.gold > 0 else None, goldActionPercent, leftPadding=leftPadding)) return block
def __init__(self, intCompactDescr, proxy=None, isBoughtForCredits=False): GUIItem.__init__(self, proxy) HasIntCD.__init__(self, intCompactDescr) self.defaultPrice = ZERO_MONEY self._buyPrice = ZERO_MONEY self.sellPrice = ZERO_MONEY self.defaultSellPrice = ZERO_MONEY self.altPrice = None self.defaultAltPrice = None self.sellActionPrc = 0 self.isHidden = False self.inventoryCount = 0 self.sellForGold = False self.isUnlocked = False self.isBoughtForCredits = isBoughtForCredits self.rentInfo = RentalInfoProvider() self.restoreInfo = None if proxy is not None and proxy.isSynced(): self.defaultPrice = proxy.shop.defaults.getItemPrice( self.intCompactDescr) if self.defaultPrice is None: self.defaultPrice = ZERO_MONEY self._buyPrice, self.isHidden, self.sellForGold = proxy.shop.getItem( self.intCompactDescr) if self._buyPrice is None: self._buyPrice = ZERO_MONEY self.defaultSellPrice = Money(*BigWorld.player().shop.getSellPrice( self.defaultPrice, proxy.shop.defaults.sellPriceModifiers(intCompactDescr), self.itemTypeID)) self.sellPrice = Money(*BigWorld.player().shop.getSellPrice( self._buyPrice, proxy.shop.sellPriceModifiers(intCompactDescr), self.itemTypeID)) self.inventoryCount = proxy.inventory.getItems( self.itemTypeID, self.intCompactDescr) 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.altPrice = self._getAltPrice(self._buyPrice, proxy.shop) self.defaultAltPrice = self._getAltPrice(self.defaultPrice, proxy.shop.defaults) self.sellActionPrc = -1 * getActionPrc(self.sellPrice, self.defaultSellPrice) return
def _getPercentDiscountByMultiplier(mult, default): price = int(round(float(mult) * default)) return getActionPrc(price, default)
def _getPercentDiscountByValue(value, default): return getActionPrc(value, default)
def getRentPackageActionPrc(self, days=None): package = self.getRentPackage(days) if package: return getActionPrc(package['rentPrice'], package['defaultRentPrice']) return 0
def _getPercentDiscountByMultiplier(mult, default): price = int(round(float(mult) * default)) return getActionPrc(price, default)
def _getPercentDiscountByValue(value, default): return getActionPrc(value, default)
def actionPrc(self): return getActionPrc(self.altPrice or self.buyPrice, self.defaultAltPrice or self.defaultPrice)
def construct(self): block = [] module = self.module slotIdx = self.configuration.slotIdx vehicle = self.configuration.vehicle sellPrice = self.configuration.sellPrice buyPrice = self.configuration.buyPrice unlockPrice = self.configuration.unlockPrice inventoryCount = self.configuration.inventoryCount vehiclesCount = self.configuration.vehiclesCount researchNode = self.configuration.node if buyPrice and sellPrice: LOG_ERROR('You are not allowed to use buyPrice and sellPrice at the same time') return else: def checkState(state): if researchNode is not None: return bool(int(researchNode.state) & state) else: return False isEqOrDev = module.itemTypeID in GUI_ITEM_TYPE.ARTEFACTS isNextToUnlock = checkState(NODE_STATE.NEXT_2_UNLOCK) isInstalled = checkState(NODE_STATE.INSTALLED) isInInventory = checkState(NODE_STATE.IN_INVENTORY) isUnlocked = checkState(NODE_STATE.UNLOCKED) isAutoUnlock = checkState(NODE_STATE.AUTO_UNLOCKED) items = g_itemsCache.items credits, gold = items.stats.money itemPrice = (0, 0) if module is not None: itemPrice = module.buyPrice isMoneyEnough = credits >= itemPrice[0] and gold >= itemPrice[1] if unlockPrice and not isEqOrDev: parentCD = vehicle.intCD if vehicle is not None else None isAvailable, cost, need = getUnlockPrice(module.intCD, parentCD) neededValue = None if not isUnlocked and isNextToUnlock and need > 0: neededValue = need if cost > 0: block.append(self._makePriceBlock(cost, 'unlockPrice', neededValue)) creditsActionPercent, goldActionPercent = (0, 0) needCredits, needGold = (0, 0) if buyPrice and not isAutoUnlock: creditsPrice, goldPrice = module.altPrice or module.buyPrice defCreditsPrice, defGoldPrice = module.defaultAltPrice or module.defaultPrice rootInInv = vehicle is not None and vehicle.isInInventory if researchNode: showNeeded = rootInInv and not isMoneyEnough and (isNextToUnlock or isUnlocked) and not (isInstalled or isInInventory) else: isModuleUnlocked = module.isUnlocked isModuleInInventory = module.isInInventory showNeeded = not isModuleInInventory and isModuleUnlocked if isEqOrDev or showNeeded: creditsNeeded = creditsPrice - credits if creditsPrice else 0 goldNeeded = goldPrice - gold if goldPrice else 0 needCredits, needGold = max(0, creditsNeeded), max(0, goldNeeded) if creditsPrice > 0: creditsActionPercent = getActionPrc(creditsPrice, defCreditsPrice) block.append(self._makePriceBlock(creditsPrice, 'buyCreditsPrice', needCredits if needCredits > 0 else None, defCreditsPrice if defCreditsPrice > 0 else None, creditsActionPercent)) if goldPrice > 0: goldActionPercent = getActionPrc(goldPrice, defGoldPrice) block.append(formatters.packTextBlockData(text=text_styles.standard(TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding(left=(101 if goldActionPercent > 0 else 81) + self.leftPadding))) block.append(self._makePriceBlock(goldPrice, 'buyGoldPrice', needGold if needGold > 0 else None, defGoldPrice if defGoldPrice > 0 else None, goldActionPercent)) if sellPrice: block.append(self._makePriceBlock(module.sellPrice[0], 'sellPrice', oldPrice=module.defaultSellPrice[0], percent=module.sellActionPrc)) if inventoryCount: count = module.inventoryCount if count > 0: block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_INVENTORYCOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) if vehiclesCount: inventoryVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) count = len(module.getInstalledVehicles(inventoryVehicles.itervalues())) if count > 0: block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_VEHICLECOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) isInstalled = False if vehicle is not None: isFit, reason = module.mayInstall(vehicle, slotIdx) if not isFit: reason = reason.replace(' ', '_') isInstalled = reason == 'already_installed' if count > self.MAX_INSTALLED_LIST_LEN and (isInstalled or isMoneyEnough): hiddenVehicleCount = count - self.MAX_INSTALLED_LIST_LEN block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.SUITABLEVEHICLE_HIDDENVEHICLECOUNT), value=text_styles.stats(hiddenVehicleCount), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) notEnoughMoney = needCredits > 0 or needGold > 0 hasAction = creditsActionPercent > 0 or goldActionPercent > 0 or module.sellActionPrc > 0 return (block, notEnoughMoney or hasAction)
def getRentPackageActionPrc(self, days = None): package = self.getRentPackage(days) if package: return getActionPrc(package['rentPrice'], package['defaultRentPrice']) return 0
def actionPrc(self): return getActionPrc(self.altPrice or self.buyPrice, self.defaultAltPrice or self.defaultPrice)
def construct(self): block = [] module = self.module slotIdx = self.configuration.slotIdx vehicle = self.configuration.vehicle sellPrice = self.configuration.sellPrice buyPrice = self.configuration.buyPrice unlockPrice = self.configuration.unlockPrice inventoryCount = self.configuration.inventoryCount vehiclesCount = self.configuration.vehiclesCount researchNode = self.configuration.node if buyPrice and sellPrice: LOG_ERROR('You are not allowed to use buyPrice and sellPrice at the same time') return else: def checkState(state): if researchNode is not None: return bool(int(researchNode.state) & state) else: return False isEqOrDev = module.itemTypeID in GUI_ITEM_TYPE.ARTEFACTS isNextToUnlock = checkState(NODE_STATE_FLAGS.NEXT_2_UNLOCK) isInstalled = checkState(NODE_STATE_FLAGS.INSTALLED) isInInventory = checkState(NODE_STATE_FLAGS.IN_INVENTORY) isUnlocked = checkState(NODE_STATE_FLAGS.UNLOCKED) isAutoUnlock = checkState(NODE_STATE_FLAGS.AUTO_UNLOCKED) items = g_itemsCache.items money = items.stats.money itemPrice = ZERO_MONEY if module is not None: itemPrice = module.buyPrice isMoneyEnough = money >= itemPrice leftPadding = 92 if unlockPrice and not isEqOrDev: parentCD = vehicle.intCD if vehicle is not None else None isAvailable, cost, need = getUnlockPrice(module.intCD, parentCD) neededValue = None if not isUnlocked and isNextToUnlock and need > 0: neededValue = need if cost > 0: block.append(makePriceBlock(cost, CURRENCY_SETTINGS.UNLOCK_PRICE, neededValue, leftPadding=leftPadding, valueWidth=self._valueWidth)) creditsActionPercent, goldActionPercent = (0, 0) need = ZERO_MONEY if buyPrice and not isAutoUnlock: price = module.altPrice or module.buyPrice defPrice = module.defaultAltPrice or module.defaultPrice rootInInv = vehicle is not None and vehicle.isInInventory if researchNode: showNeeded = rootInInv and not isMoneyEnough and (isNextToUnlock or isUnlocked) and not (isInstalled or isInInventory) else: isModuleUnlocked = module.isUnlocked isModuleInInventory = module.isInInventory showNeeded = not isModuleInInventory and isModuleUnlocked if isEqOrDev or showNeeded: need = price - money need = need.toNonNegative() if price.credits > 0: creditsActionPercent = getActionPrc(price.credits, defPrice.credits) block.append(makePriceBlock(price.credits, CURRENCY_SETTINGS.BUY_CREDITS_PRICE, need.credits if need.credits > 0 else None, defPrice.credits if defPrice.credits > 0 else None, creditsActionPercent, self._valueWidth, leftPadding)) if price.gold > 0: goldActionPercent = getActionPrc(price.gold, defPrice.gold) block.append(formatters.packTextBlockData(text=text_styles.standard(TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding(left=(101 if goldActionPercent > 0 else 81) + self.leftPadding))) block.append(makePriceBlock(price.gold, CURRENCY_SETTINGS.BUY_GOLD_PRICE, need.gold if need.gold > 0 else None, defPrice.gold if defPrice.gold > 0 else None, goldActionPercent, self._valueWidth, leftPadding)) if sellPrice: block.append(makePriceBlock(module.sellPrice.credits, CURRENCY_SETTINGS.SELL_PRICE, oldPrice=module.defaultSellPrice.credits, percent=module.sellActionPrc, valueWidth=self._valueWidth, leftPadding=leftPadding)) if inventoryCount: count = module.inventoryCount if count > 0: block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_INVENTORYCOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) if vehiclesCount: inventoryVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) count = len(module.getInstalledVehicles(inventoryVehicles.itervalues())) if count > 0: block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_VEHICLECOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) notEnoughMoney = need > ZERO_MONEY hasAction = creditsActionPercent > 0 or goldActionPercent > 0 or module.sellActionPrc > 0 return (block, notEnoughMoney or hasAction)
def getActionPrc(self): return getActionPrc(self.__price, self.__defPrice) if self.isActionPrice() else 0
def construct(self): block = [] module = self.module slotIdx = self.configuration.slotIdx vehicle = self.configuration.vehicle sellPrice = self.configuration.sellPrice buyPrice = self.configuration.buyPrice unlockPrice = self.configuration.unlockPrice inventoryCount = self.configuration.inventoryCount vehiclesCount = self.configuration.vehiclesCount researchNode = self.configuration.node if buyPrice and sellPrice: LOG_ERROR( 'You are not allowed to use buyPrice and sellPrice at the same time' ) return else: def checkState(state): if researchNode is not None: return bool(int(researchNode.state) & state) else: return False isEqOrDev = module.itemTypeID in GUI_ITEM_TYPE.ARTEFACTS isNextToUnlock = checkState(NODE_STATE_FLAGS.NEXT_2_UNLOCK) isInstalled = checkState(NODE_STATE_FLAGS.INSTALLED) isInInventory = checkState(NODE_STATE_FLAGS.IN_INVENTORY) isUnlocked = checkState(NODE_STATE_FLAGS.UNLOCKED) isAutoUnlock = checkState(NODE_STATE_FLAGS.AUTO_UNLOCKED) items = g_itemsCache.items money = items.stats.money itemPrice = ZERO_MONEY if module is not None: itemPrice = module.buyPrice isMoneyEnough = money >= itemPrice leftPadding = 92 if unlockPrice and not isEqOrDev: parentCD = vehicle.intCD if vehicle is not None else None isAvailable, cost, need = getUnlockPrice( module.intCD, parentCD) neededValue = None if not isUnlocked and isNextToUnlock and need > 0: neededValue = need if cost > 0: block.append( makePriceBlock(cost, CURRENCY_SETTINGS.UNLOCK_PRICE, neededValue, leftPadding=leftPadding, valueWidth=self._valueWidth)) creditsActionPercent, goldActionPercent = (0, 0) need = ZERO_MONEY if buyPrice and not isAutoUnlock: price = module.altPrice or module.buyPrice defPrice = module.defaultAltPrice or module.defaultPrice rootInInv = vehicle is not None and vehicle.isInInventory if researchNode: showNeeded = rootInInv and not isMoneyEnough and ( isNextToUnlock or isUnlocked) and not (isInstalled or isInInventory) else: isModuleUnlocked = module.isUnlocked isModuleInInventory = module.isInInventory showNeeded = not isModuleInInventory and isModuleUnlocked if isEqOrDev or showNeeded: need = price - money need = need.toNonNegative() if price.credits > 0: creditsActionPercent = getActionPrc( price.credits, defPrice.credits) block.append( makePriceBlock( price.credits, CURRENCY_SETTINGS.BUY_CREDITS_PRICE, need.credits if need.credits > 0 else None, defPrice.credits if defPrice.credits > 0 else None, creditsActionPercent, self._valueWidth, leftPadding)) if price.gold > 0: goldActionPercent = getActionPrc(price.gold, defPrice.gold) block.append( formatters.packTextBlockData( text=text_styles.standard( TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding( left=(101 if goldActionPercent > 0 else 81) + self.leftPadding))) block.append( makePriceBlock( price.gold, CURRENCY_SETTINGS.BUY_GOLD_PRICE, need.gold if need.gold > 0 else None, defPrice.gold if defPrice.gold > 0 else None, goldActionPercent, self._valueWidth, leftPadding)) if sellPrice: block.append( makePriceBlock(module.sellPrice.credits, CURRENCY_SETTINGS.SELL_PRICE, oldPrice=module.defaultSellPrice.credits, percent=module.sellActionPrc, valueWidth=self._valueWidth, leftPadding=leftPadding)) if inventoryCount: count = module.inventoryCount if count > 0: block.append( formatters.packTextParameterBlockData( name=text_styles.main( TOOLTIPS.VEHICLE_INVENTORYCOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) if vehiclesCount: inventoryVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) count = len( module.getInstalledVehicles( inventoryVehicles.itervalues())) if count > 0: block.append( formatters.packTextParameterBlockData( name=text_styles.main( TOOLTIPS.VEHICLE_VEHICLECOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5))) notEnoughMoney = need > ZERO_MONEY hasAction = creditsActionPercent > 0 or goldActionPercent > 0 or module.sellActionPrc > 0 return (block, notEnoughMoney or hasAction)