コード例 #1
0
    def __parseInstalled(self, installed, shellsLayout, vehDescr, capacity):
        installedDict = {
            cd: count
            for cd, count, _ in LayoutIterator(installed)
        }
        layoutDict = {
            cd: count
            for cd, count, _ in LayoutIterator(shellsLayout)
        }
        missed = []
        shellsLayout = shellsLayout[:]
        shellsCDs = shellsLayout[::2]
        for shot in vehDescr.gun.shots:
            cd = shot.shell.compactDescr
            if cd in layoutDict:
                count = 0
                if cd in installedDict:
                    count = min(installedDict.get(cd, 0),
                                layoutDict.get(cd, 0))
                idx = shellsCDs.index(cd) * 2 + 1
                shellsLayout[idx] = count
            missed.append(cd)

        for cd in missed:
            shellsLayout.extend([cd, 0])

        result = []
        for intCD, count, isBoughtForCredits in LayoutIterator(shellsLayout):
            result.append((intCD, count, isBoughtForCredits))

        return self.__fixSize(result, capacity)
コード例 #2
0
    def __parseInstalled(self, installed, vehDescr, capacity):
        shellsDict = {cd: count for cd, count, _ in LayoutIterator(installed)}
        installed = installed[:]
        for shot in vehDescr.gun.shots:
            cd = shot.shell.compactDescr
            if cd not in shellsDict and len(installed) < capacity * 2:
                installed.extend([cd, 0])

        result = []
        for intCD, count, isBoughtForCredits in LayoutIterator(installed):
            result.append((intCD, count, isBoughtForCredits))

        return self.__fixSize(result, capacity)
コード例 #3
0
    def _parseShells(self, layoutList, defaultLayoutList, proxy):
        shellsDict = dict(((cd, count) for cd, count, _ in LayoutIterator(layoutList)))
        defaultsDict = dict(((cd, (count, isBoughtForCredits)) for cd, count, isBoughtForCredits in LayoutIterator(defaultLayoutList)))
        layoutList = list(layoutList)
        for shot in self.descriptor.gun['shots']:
            cd = shot['shell']['compactDescr']
            if cd not in shellsDict:
                layoutList.extend([cd, 0])

        result = list()
        for idx, (intCD, count, _) in enumerate(LayoutIterator(layoutList)):
            defaultCount, isBoughtForCredits = defaultsDict.get(intCD, (0, False))
            result.append(Shell(intCD, count, defaultCount, proxy, isBoughtForCredits))

        return result
コード例 #4
0
ファイル: vehicle.py プロジェクト: kusaku/wot_scripts
    def getShellsLayoutPrice(self):
        """
        @return: price that should be paid to fill layout
        """
        if self.shellsLayoutHelper is None:
            return MONEY_UNDEFINED
        else:
            price = MONEY_UNDEFINED
            if g_bootcamp.isRunning():
                return price
            for shellCompDescr, count, isBuyingForAltPrice in LayoutIterator(
                    self.shellsLayoutHelper.getRawLayout()):
                if not shellCompDescr or not count:
                    continue
                shell = self.itemsCache.items.getItemByCD(int(shellCompDescr))
                vehShell = findFirst(
                    lambda s, intCD=shellCompDescr: s.intCD == intCD,
                    self.vehicle.shells)
                vehCount = vehShell.count if vehShell is not None else 0
                buyCount = count - shell.inventoryCount - vehCount
                if buyCount:
                    itemPrice = shell.buyPrices.itemAltPrice if isBuyingForAltPrice else shell.buyPrices.itemPrice
                    buyPrice = buyCount * itemPrice.price
                    price += buyPrice

            return price
コード例 #5
0
    def getEqsLayoutPrice(self):
        """
        @return: price that should be paid to fill layout
        """
        if self.eqsLayout is None:
            return ZERO_MONEY
        else:
            price = ZERO_MONEY
            for idx, (eqCompDescr, count, isBoughtForCredits) in enumerate(
                    LayoutIterator(self.eqsLayout)):
                if not eqCompDescr or not count:
                    continue
                equipment = g_itemsCache.items.getItemByCD(int(eqCompDescr))
                vehEquipment = self.vehicle.eqs[idx]
                vehCount = 1 if vehEquipment is not None else 0
                buyCount = count - equipment.inventoryCount - vehCount
                if buyCount:
                    buyPrice = buyCount * equipment.buyPrice
                    if isBoughtForCredits:
                        buyPrice = buyPrice.exchange(
                            Currency.GOLD, Currency.CREDITS, g_itemsCache.
                            items.shop.exchangeRateForShellsAndEqs)
                    price += buyPrice

            return price
コード例 #6
0
    def getShellsLayoutPrice(self):
        """
        @return: price that should be paid to fill layout
        """
        if self.shellsLayout is None:
            return ZERO_MONEY
        else:
            price = ZERO_MONEY
            for shellCompDescr, count, isBoughtForCredits in LayoutIterator(
                    self.shellsLayout):
                if not shellCompDescr or not count:
                    continue
                shell = g_itemsCache.items.getItemByCD(int(shellCompDescr))
                vehShell = findFirst(lambda s: s.intCD == shellCompDescr,
                                     self.vehicle.shells)
                vehCount = vehShell.count if vehShell is not None else 0
                buyCount = count - shell.inventoryCount - vehCount
                if buyCount:
                    buyPrice = buyCount * shell.buyPrice
                    if isBoughtForCredits:
                        buyPrice = buyPrice.exchange(
                            Currency.GOLD, Currency.CREDITS, g_itemsCache.
                            items.shop.exchangeRateForShellsAndEqs)
                    price += buyPrice

            return price
コード例 #7
0
def getInstalledShells(shellsCDs, shellsLayout):
    aggregate = {}
    for shellCD, count, _ in LayoutIterator(tuple(chain(*shellsLayout))):
        aggregate[shellCD] = max(count, aggregate.get(shellCD, 0))

    installed = []
    for shellCD in shellsCDs:
        installed.extend((shellCD, aggregate.get(shellCD, 0)))

    return installed
コード例 #8
0
    def __parseLayout(self, shellsInvLayout, vehDescr, capacity, layoutIdx):
        shellsLayoutKey = (vehDescr.turret.compactDescr, vehDescr.gun.compactDescr)
        if shellsLayoutKey in shellsInvLayout:
            shellsLayouts = shellsInvLayout[shellsLayoutKey]
            shellsLayoutsSize = len(shellsLayouts)
            if shellsLayoutsSize <= layoutIdx < self.setupLayouts.capacity or not shellsLayouts[layoutIdx]:
                shellsLayout = self.__getDefaultShellsLayout(vehDescr, defaultCount=0)
            else:
                shellsLayout = shellsLayouts[layoutIdx]
        else:
            shellsLayout = self.__getDefaultShellsLayout(vehDescr)
        result = []
        for intCD, count, isBoughtForCredits in LayoutIterator(shellsLayout):
            result.append((intCD, count, isBoughtForCredits))

        return (self.__fixSize(result, capacity), shellsLayout)
コード例 #9
0
    def __parseLayout(self, shellsInvLayout, vehDescr, capacity):
        shellsLayoutKey = (vehDescr.turret.compactDescr,
                           vehDescr.gun.compactDescr)
        if shellsLayoutKey in shellsInvLayout:
            shellsLayout = shellsInvLayout[shellsLayoutKey]
        else:
            shellsLayout = []
            gun = self.__itemsFactory.createVehicleGun(
                vehDescr.gun.compactDescr, descriptor=vehDescr.gun)
            if gun is not None:
                for shell in gun.defaultAmmo:
                    shellsLayout += (shell.intCD, shell.count)

        result = []
        for intCD, count, isBoughtForCredits in LayoutIterator(shellsLayout):
            result.append((intCD, count, isBoughtForCredits))

        return self.__fixSize(result, capacity)
コード例 #10
0
    def getEqsLayoutPrice(self):
        if self.eqsLayoutHelper is None:
            return MONEY_UNDEFINED
        else:
            price = MONEY_UNDEFINED
            regularEqsLayout = self.eqsLayoutHelper.getRegularRawLayout()
            for idx, (eqCompDescr, count, isBuyingForAltPrice) in enumerate(
                    LayoutIterator(regularEqsLayout)):
                if not eqCompDescr or not count:
                    continue
                equipment = self.itemsCache.items.getItemByCD(int(eqCompDescr))
                vehEquipment = self.vehicle.equipment.regularConsumables[idx]
                vehCount = 1 if vehEquipment is not None else 0
                buyCount = count - equipment.inventoryCount - vehCount
                if buyCount:
                    itemPrice = equipment.buyPrices.itemAltPrice if isBuyingForAltPrice else equipment.buyPrices.itemPrice
                    buyPrice = buyCount * itemPrice.price
                    price += buyPrice

            return price
コード例 #11
0
ファイル: vehicle.py プロジェクト: v3ss0n/WOTDecompiled
    def getEqsLayoutPrice(self):
        """
        @param layout: eqs layout
        @return: price that should be paid to fill layout
        """
        goldPrice = 0
        creditsPrice = 0
        for idx, (eqCompDescr, count, isBoughtForCredits) in enumerate(LayoutIterator(self.eqsLayout)):
            if not eqCompDescr or not count:
                continue
            equipment = g_itemsCache.items.getItemByCD(int(eqCompDescr))
            vehEquipment = self.vehicle.eqs[idx]
            vehCount = 1 if vehEquipment is not None else 0
            buyCount = count - equipment.inventoryCount - vehCount
            if buyCount:
                if equipment.buyPrice[1] and not isBoughtForCredits:
                    goldPrice += equipment.buyPrice[1] * buyCount
                elif equipment.buyPrice[1] and isBoughtForCredits:
                    creditsPrice += equipment.buyPrice[1] * buyCount * g_itemsCache.items.shop.exchangeRateForShellsAndEqs
                elif equipment.buyPrice[0]:
                    creditsPrice += equipment.buyPrice[0] * buyCount

        return (creditsPrice, goldPrice)
コード例 #12
0
ファイル: vehicle.py プロジェクト: jamesxia4/wot_client
    def getShellsLayoutPrice(self):
        """
        @return: price that should be paid to fill layout
        """
        goldPrice = 0
        creditsPrice = 0
        if self.shellsLayout is None:
            return (creditsPrice, goldPrice)
        for shellCompDescr, count, isBoughtForCredits in LayoutIterator(self.shellsLayout):
            if not shellCompDescr or not count:
                continue
            shell = g_itemsCache.items.getItemByCD(int(shellCompDescr))
            vehShell = findFirst(lambda s: s.intCD == shellCompDescr, self.vehicle.shells)
            vehCount = vehShell.count if vehShell is not None else 0
            buyCount = count - shell.inventoryCount - vehCount
            if buyCount:
                if shell.buyPrice[1] and not isBoughtForCredits:
                    goldPrice += shell.buyPrice[1] * buyCount
                elif shell.buyPrice[1] and isBoughtForCredits:
                    creditsPrice += shell.buyPrice[1] * buyCount * g_itemsCache.items.shop.exchangeRateForShellsAndEqs
                elif shell.buyPrice[0]:
                    creditsPrice += shell.buyPrice[0] * buyCount

        return (creditsPrice, goldPrice)
コード例 #13
0
    def invalidateCache(self, diff=None):
        invalidate = defaultdict(set)
        if diff is None:
            LOG_DEBUG('Gui items cache full invalidation')
            for itemTypeID, cache in self.__itemsCache.iteritems():
                if itemTypeID not in (GUI_ITEM_TYPE.ACCOUNT_DOSSIER,
                                      GUI_ITEM_TYPE.VEHICLE_DOSSIER,
                                      GUI_ITEM_TYPE.BATTLE_ABILITY):
                    cache.clear()

        else:
            for statName, data in diff.get('stats', {}).iteritems():
                if statName in ('unlocks', ('unlocks', '_r')):
                    self._invalidateUnlocks(data, invalidate)
                if statName == 'eliteVehicles':
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(data)
                if statName in ('vehTypeXP', 'vehTypeLocks'):
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(data.keys())
                if statName in (('multipliedXPVehs', '_r'), ):
                    getter = vehicles.getVehicleTypeCompactDescr
                    inventoryVehiclesCDs = [
                        getter(v['compDescr'])
                        for v in self.__inventory.getItems(
                            GUI_ITEM_TYPE.VEHICLE).itervalues()
                    ]
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(
                        inventoryVehiclesCDs)
                if statName in ('oldVehInvIDs', ):
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(data)

        for cacheType, data in diff.get('cache', {}).iteritems():
            if cacheType == 'vehsLock':
                for itemID in data.keys():
                    vehData = self.__inventory.getVehicleData(
                        _getDiffID(itemID))
                    if vehData is not None:
                        invalidate[GUI_ITEM_TYPE.VEHICLE].add(
                            vehData.descriptor.type.compactDescr)

        for cacheType, data in diff.get('groupLocks', {}).iteritems():
            if cacheType in ('isGroupLocked', 'groupBattles'):
                getter = vehicles.getVehicleTypeCompactDescr
                inventoryVehiclesCDs = [
                    getter(v['compDescr']) for v in self.inventory.getItems(
                        GUI_ITEM_TYPE.VEHICLE).itervalues()
                ]
                invalidate[GUI_ITEM_TYPE.VEHICLE].update(inventoryVehiclesCDs)

        for itemTypeID, itemsDiff in diff.get('inventory', {}).iteritems():
            if itemTypeID == GUI_ITEM_TYPE.VEHICLE:
                if 'compDescr' in itemsDiff:
                    for strCD in itemsDiff['compDescr'].itervalues():
                        if strCD is not None:
                            invalidate[itemTypeID].add(
                                vehicles.getVehicleTypeCompactDescr(strCD))

                for data in itemsDiff.itervalues():
                    for itemID in data.iterkeys():
                        vehData = self.__inventory.getVehicleData(
                            _getDiffID(itemID))
                        if vehData is not None:
                            invalidate[itemTypeID].add(
                                vehData.descriptor.type.compactDescr)
                            invalidate[GUI_ITEM_TYPE.TANKMAN].update(
                                self.__getTankmenIDsForVehicle(vehData))

            if itemTypeID == GUI_ITEM_TYPE.TANKMAN:
                for data in itemsDiff.itervalues():
                    invalidate[itemTypeID].update(data.keys())
                    for itemID in data.keys():
                        tmanInvID = _getDiffID(itemID)
                        tmanData = self.__inventory.getTankmanData(tmanInvID)
                        if tmanData is not None and tmanData.vehicle != -1:
                            invalidate[GUI_ITEM_TYPE.VEHICLE].update(
                                self.__getVehicleCDForTankman(tmanData))
                            invalidate[GUI_ITEM_TYPE.TANKMAN].update(
                                self.__getTankmenIDsForTankman(tmanData))

            if itemTypeID == GUI_ITEM_TYPE.SHELL:
                invalidate[itemTypeID].update(itemsDiff.keys())
                vehicleItems = self.__inventory.getItems(GUI_ITEM_TYPE.VEHICLE)
                if vehicleItems:
                    for shellIntCD in itemsDiff.iterkeys():
                        for vehicle in vehicleItems.itervalues():
                            shells = vehicle['shells']
                            for intCD, _, _ in LayoutIterator(shells):
                                if shellIntCD == intCD:
                                    vehicleIntCD = vehicles.getVehicleTypeCompactDescr(
                                        vehicle['compDescr'])
                                    invalidate[GUI_ITEM_TYPE.VEHICLE].add(
                                        vehicleIntCD)
                                    vehicleData = self.__inventory.getItemData(
                                        vehicleIntCD)
                                    if vehicleData is not None:
                                        gunIntCD = vehicleData.descriptor.gun.compactDescr
                                        invalidate[GUI_ITEM_TYPE.GUN].add(
                                            gunIntCD)

            if itemTypeID == GUI_ITEM_TYPE.CUSTOMIZATION:
                for vehicleIntCD, outfitsData in itemsDiff.get(
                        CustomizationInvData.OUTFITS, {}).iteritems():
                    invalidate[GUI_ITEM_TYPE.VEHICLE].add(vehicleIntCD)
                    seasons = (outfitsData or {}).keys() or SeasonType.RANGE
                    for season in seasons:
                        invalidate[GUI_ITEM_TYPE.OUTFIT].add(
                            (vehicleIntCD, season))

                for cType, items in itemsDiff.get(CustomizationInvData.ITEMS,
                                                  {}).iteritems():
                    for idx in items.iterkeys():
                        intCD = vehicles.makeIntCompactDescrByID(
                            'customizationItem', cType, idx)
                        invalidate[GUI_ITEM_TYPE.CUSTOMIZATION].add(intCD)

            invalidate[itemTypeID].update(itemsDiff.keys())

        for itemType, itemsDiff in diff.get('recycleBin', {}).iteritems():
            deletedItems = itemsDiff.get('buffer', {})
            for itemID in deletedItems.iterkeys():
                if itemType == 'tankmen':
                    invalidate[GUI_ITEM_TYPE.TANKMAN].add(itemID * -1)
                invalidate[GUI_ITEM_TYPE.VEHICLE].add(itemID)

        if 'goodies' in diff:
            vehicleDiscounts = self.__shop.getVehicleDiscountDescriptions()
            for goodieID in diff['goodies'].iterkeys():
                if goodieID in vehicleDiscounts:
                    vehicleDiscount = vehicleDiscounts[goodieID]
                    invalidate[GUI_ITEM_TYPE.VEHICLE].add(
                        vehicleDiscount.target.targetValue)

        for itemTypeID, uniqueIDs in invalidate.iteritems():
            self._invalidateItems(itemTypeID, uniqueIDs)

        return invalidate
コード例 #14
0
    def invalidateCache(self, diff=None):
        invalidate = defaultdict(set)
        if diff is None:
            LOG_DEBUG('Gui items cache full invalidation')
            for itemTypeID, cache in self.__itemsCache.iteritems():
                if itemTypeID not in (GUI_ITEM_TYPE.ACCOUNT_DOSSIER,
                                      GUI_ITEM_TYPE.VEHICLE_DOSSIER):
                    cache.clear()

        else:
            for statName, data in diff.get('stats', {}).iteritems():
                if statName == 'unlocks':
                    self._invalidateUnlocks(data, invalidate)
                elif statName == 'eliteVehicles':
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(data)
                elif statName in ('vehTypeXP', 'vehTypeLocks'):
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(data.keys())
                elif statName in (('multipliedXPVehs', '_r'), ):
                    inventoryVehiclesCDs = map(
                        lambda v: vehicles.getVehicleTypeCompactDescr(v[
                            'compDescr']),
                        self.inventory.getItems(
                            GUI_ITEM_TYPE.VEHICLE).itervalues())
                    invalidate[GUI_ITEM_TYPE.VEHICLE].update(
                        inventoryVehiclesCDs)

            for cacheType, data in diff.get('cache', {}).iteritems():
                if cacheType == 'vehsLock':
                    for id in data.keys():
                        vehData = self.inventory.getVehicleData(_getDiffID(id))
                        if vehData is not None:
                            invalidate[GUI_ITEM_TYPE.VEHICLE].add(
                                vehData.descriptor.type.compactDescr)

            for itemTypeID, itemsDiff in diff.get('inventory', {}).iteritems():
                if itemTypeID == GUI_ITEM_TYPE.VEHICLE:
                    if 'compDescr' in itemsDiff:
                        for strCD in itemsDiff['compDescr'].itervalues():
                            if strCD is not None:
                                invalidate[itemTypeID].add(
                                    vehicles.getVehicleTypeCompactDescr(strCD))

                    for data in itemsDiff.itervalues():
                        for id in data.iterkeys():
                            vehData = self.inventory.getVehicleData(
                                _getDiffID(id))
                            if vehData is not None:
                                invalidate[itemTypeID].add(
                                    vehData.descriptor.type.compactDescr)
                                invalidate[GUI_ITEM_TYPE.TANKMAN].update(
                                    self.__getTankmenIDsForVehicle(vehData))

                elif itemTypeID == GUI_ITEM_TYPE.TANKMAN:
                    for data in itemsDiff.itervalues():
                        invalidate[itemTypeID].update(data.keys())
                        for id in data.keys():
                            tmanInvID = _getDiffID(id)
                            tmanData = self.inventory.getTankmanData(tmanInvID)
                            if tmanData is not None and tmanData.vehicle != -1:
                                invalidate[GUI_ITEM_TYPE.VEHICLE].update(
                                    self.__getVehicleCDForTankman(tmanData))
                                invalidate[GUI_ITEM_TYPE.TANKMAN].update(
                                    self.__getTankmenIDsForTankman(tmanData))

                elif itemTypeID == GUI_ITEM_TYPE.SHELL:
                    invalidate[itemTypeID].update(itemsDiff.keys())
                    for shellIntCD in itemsDiff.iterkeys():
                        for vehicle in self.inventory.getItems(
                                GUI_ITEM_TYPE.VEHICLE).itervalues():
                            shells = vehicle['shells']
                            for intCD, _, _ in LayoutIterator(shells):
                                if shellIntCD == intCD:
                                    vehicleIntCD = vehicles.getVehicleTypeCompactDescr(
                                        vehicle['compDescr'])
                                    invalidate[GUI_ITEM_TYPE.VEHICLE].add(
                                        vehicleIntCD)
                                    vehicelData = self.inventory.getItemData(
                                        vehicleIntCD)
                                    gunIntCD = vehicelData.descriptor.gun[
                                        'compactDescr']
                                    invalidate[GUI_ITEM_TYPE.GUN].add(gunIntCD)

                else:
                    invalidate[itemTypeID].update(itemsDiff.keys())

            for itemTypeID, uniqueIDs in invalidate.iteritems():
                self._invalidateItems(itemTypeID, uniqueIDs)

        return invalidate