Пример #1
0
    def isNext2Unlock(self, vTypeCD, unlocked=set(), xps=None, freeXP=0):
        """ Is given vehicle is next to unlock. "next to unlock" - all required
        items are unlocked. If vehicle is available in a few vehicles, than
        returns compact descriptor for parent vehicle where min XP cost.
        NOTE: if xps is defined than searches vehicles for which enough experience
        and available.
        :param vTypeCD: compact descriptor of vehicle (int).
        :param unlocked: set of unlocked items (int compact descriptor).
        :param xps: dict of vehicles XPs { int compact descriptor : xp, ... }
        :param freeXP: value of free XP.
        :return: (<is available>, <instance of UnlockProps>).
        """
        topLevel = self.getTopLevel(vTypeCD)
        available = False
        topIDs = set()
        compare = []
        result = DEFAULT_UNLOCK_PROPS
        for parentCD in topLevel:
            nextLevel = self.__nextLevels[parentCD]
            idx, xpCost, required = nextLevel[vTypeCD]
            if required.issubset(unlocked) and parentCD in unlocked:
                topIDs.add(parentCD)
                compare.append(UnlockProps(parentCD, idx, xpCost, topIDs))
                available = True
            elif not result.xpCost or result.xpCost > xpCost:
                result = UnlockProps(parentCD, idx, xpCost, set())

        if available:
            result = self._findNext2Unlock(compare, xps=xps, freeXP=freeXP)
        return (available, result)
Пример #2
0
    def __loadItems(self, rootItem, unlockStats):
        itemGetter = self.getItem
        rootCD = rootItem.intCD
        maxPath = 0
        nodes = []
        for unlockIdx, xpCost, nodeCD, required in rootItem.getUnlocksDescrs():
            itemTypeID = getTypeOfCompactDescr(nodeCD)
            required.add(rootCD)
            path = required.copy()
            path = self.__fixPath(itemTypeID, path)
            maxPath = max(len(path), maxPath)
            nodes.append((nodeCD, itemTypeID,
                          UnlockProps(rootCD, unlockIdx, xpCost,
                                      required), path))

        for nodeCD, itemTypeID, unlockProps, path in nodes:
            node = self._getNodeData(nodeCD,
                                     rootItem,
                                     itemGetter(nodeCD),
                                     unlockStats,
                                     unlockProps,
                                     path,
                                     level=self.__fixLevel(
                                         itemTypeID, path, maxPath))
            self._addNode(nodeCD, node)
Пример #3
0
    def getNext2UnlockByItems(self,
                              itemCDs,
                              unlocked=set(),
                              xps=None,
                              freeXP=0):
        filtered = filter(lambda item: item in self.__topItems, itemCDs)
        if not len(filtered) or not len(unlocked):
            return {}
        available = defaultdict(list)
        parentCDs = set(
            filter(lambda item: getTypeOfCompactDescr(item) == _VEHICLE,
                   itemCDs))
        for item in filtered:
            if item in unlocked:
                parentCDs |= self.__topItems[item]

        for parentCD in parentCDs:
            if parentCD not in unlocked:
                continue
            nextLevel = self.__nextLevels[parentCD]
            topIDs = set()
            for childCD, (idx, xpCost, required) in nextLevel.iteritems():
                if childCD not in unlocked and required.issubset(unlocked):
                    topIDs.add(parentCD)
                    available[childCD].append(
                        UnlockProps(parentCD, idx, xpCost, topIDs))

        result = {}
        for childCD, compare in available.iteritems():
            result[childCD] = self._findNext2Unlock(compare,
                                                    xps=xps,
                                                    freeXP=freeXP)

        return result
Пример #4
0
    def _loadItems(self, rootItem, unlockStats):
        itemGetter = self.getItem
        rootCD = rootItem.intCD
        maxPath = 0
        nodes_ = []
        for unlockIdx, oldCost, nodeCD, required in self._getRootUnlocksDescrs(
                rootItem):
            itemTypeID = getTypeOfCD(nodeCD)
            required.add(rootCD)
            path = required.copy()
            path = self.__fixPath(itemTypeID, path)
            maxPath = max(len(path), maxPath)
            xpCost = oldCost
            discount = 0
            if itemTypeID == GUI_ITEM_TYPE.VEHICLE:
                item = self.getItem(nodeCD)
                xpCost, discount = self._getNewCost(nodeCD, item.level,
                                                    oldCost)
            nodes_.append((nodeCD, itemTypeID,
                           UnlockProps(rootCD, unlockIdx, xpCost, required,
                                       discount, oldCost), path))

        for nodeCD, itemTypeID, unlockProps, path in nodes_:
            node = self._getNodeData(nodeCD,
                                     rootItem,
                                     itemGetter(nodeCD),
                                     unlockStats,
                                     unlockProps,
                                     path,
                                     level=self.__fixLevel(
                                         itemTypeID, path, maxPath))
            self._addNode(nodeCD, node)
Пример #5
0
    def _loadItems(self, rootItem, unlockStats):
        """
        Third, loads research items.
        :param rootItem: instance of gui item for root. @see gui.shared.gui_items.
        :param unlockStats: instance of unlockStats.
        """
        itemGetter = self.getItem
        rootCD = rootItem.intCD
        maxPath = 0
        nodes = []
        for unlockIdx, xpCost, nodeCD, required in self._getRootUnlocksDescrs(
                rootItem):
            itemTypeID = getTypeOfCD(nodeCD)
            required.add(rootCD)
            path = required.copy()
            path = self.__fixPath(itemTypeID, path)
            maxPath = max(len(path), maxPath)
            nodes.append((nodeCD, itemTypeID,
                          UnlockProps(rootCD, unlockIdx, xpCost,
                                      required), path))

        for nodeCD, itemTypeID, unlockProps, path in nodes:
            node = self._getNodeData(nodeCD,
                                     rootItem,
                                     itemGetter(nodeCD),
                                     unlockStats,
                                     unlockProps,
                                     path,
                                     level=self.__fixLevel(
                                         itemTypeID, path, maxPath))
            self._addNode(nodeCD, node)
Пример #6
0
def getUnlockPrice(compactDescr,
                   parentCD=None,
                   vehicleLevel=UNKNOWN_VEHICLE_LEVEL,
                   itemsCache=None):
    itemTypeId, _, _ = vehicles.parseIntCompactDescr(compactDescr)
    freeXP = itemsCache.items.stats.actualFreeXP
    unlocks = itemsCache.items.stats.unlocks
    xpVehs = itemsCache.items.stats.vehiclesXPs
    g_techTreeDP.load()
    pricesDict = g_techTreeDP.getUnlockPrices(compactDescr)

    def getUnlockProps(isAvailable, vehCompDescr, unlockProps=None):
        if unlockProps is not None:
            unlockPrice = unlockProps.xpCost
        elif vehCompDescr in pricesDict:
            unlockPrice = pricesDict[vehCompDescr]
        else:
            vehicle = itemsCache.items.getItemByCD(parentCD)
            _, unlockPrice, _ = vehicle.getUnlockDescrByIntCD(compactDescr)
        oldPrice = unlockProps.xpFullCost if unlockProps is not None else unlockPrice
        discount = unlockProps.discount if unlockProps is not None else 0
        pVehXp = xpVehs.get(vehCompDescr, 0)
        need = unlockPrice - pVehXp
        needWithFreeXP = need - freeXP
        return (isAvailable, unlockPrice, min(need, needWithFreeXP), oldPrice,
                discount)

    if itemTypeId == vehicles._VEHICLE:
        isAvailable, unlockProps = g_techTreeDP.isNext2Unlock(
            compactDescr, unlocks, xpVehs, freeXP, vehicleLevel)
        if parentCD is not None and parentCD == unlockProps.parentID:
            return getUnlockProps(isAvailable, parentCD, unlockProps)
        xpCost = pricesDict.get(parentCD, 0)
        discount, newCost = g_techTreeDP.getBlueprintDiscountData(
            compactDescr, vehicleLevel, xpCost)
        unlockProps = UnlockProps(parentCD, -1, newCost, None, discount,
                                  xpCost)
        return getUnlockProps(isAvailable, unlockProps.parentID, unlockProps)
    else:
        isAvailable = compactDescr in unlocks
        if parentCD is not None:
            return getUnlockProps(isAvailable, parentCD)
        vehsCompDescrs = [
            compDescr for compDescr in pricesDict.keys()
            if compDescr in unlocks
        ]
        if not vehsCompDescrs:
            vehsCompDescrs = pricesDict.keys()
        minUnlockPrice = sys.maxint
        minUnlockPriceVehCD = None
        for vcd in vehsCompDescrs:
            if pricesDict[vcd] <= minUnlockPrice:
                minUnlockPrice = pricesDict[vcd]
                minUnlockPriceVehCD = vcd

        if minUnlockPriceVehCD is None:
            return (isAvailable, 0, 0, 0, 0)
        return getUnlockProps(isAvailable, minUnlockPriceVehCD)
        return
Пример #7
0
    def getUnlockedVehicleItems(self, vehicle, unlocked):
        items = {}
        for unlockIdx, xpCost, nodeCD, required in vehicle.getUnlocksDescrs():
            if required.issubset(unlocked) and nodeCD in unlocked:
                items[nodeCD] = UnlockProps(vehicle.intCD, unlockIdx, xpCost,
                                            required)

        return items
    def getUnlockedVehicleItems(self, vehicle, unlocked):
        items = {}
        for unlockIdx, xpCost, nodeCD, required in vehicle.getUnlocksDescrs():
            if required.issubset(unlocked) and nodeCD in unlocked:
                discountData = self.getBlueprintDiscountData(vehicle.intCD, vehicle.level, xpCost)
                items[nodeCD] = UnlockProps(vehicle.intCD, unlockIdx, discountData[1], required, discountData[0], xpCost)

        return items
    def getAllPossibleItems2Unlock(self, vehicle, unlocked):
        items = {}
        for unlockIdx, xpCost, nodeCD, required in vehicle.getUnlocksDescrs():
            if required.issubset(unlocked) and nodeCD not in unlocked:
                level = self.itemsCache.items.getItemByCD(nodeCD).level
                discount, newCost = self.getBlueprintDiscountData(nodeCD, level, xpCost)
                items[nodeCD] = UnlockProps(parentID=vehicle.intCD, unlockIdx=unlockIdx, xpCost=newCost, required=required, discount=discount, xpFullCost=xpCost)

        return items
Пример #10
0
    def isNext2Unlock(self, vTypeCD, unlocked=set(), xps=None, freeXP=0):
        topLevel = self.getTopLevel(vTypeCD)
        available = False
        topIDs = set()
        compare = []
        result = makeDefUnlockProps()
        for parentCD in topLevel:
            nextLevel = self.__nextLevels[parentCD]
            idx, xpCost, required = nextLevel[vTypeCD]
            if required.issubset(unlocked) and parentCD in unlocked:
                topIDs.add(parentCD)
                compare.append(UnlockProps(parentCD, idx, xpCost, topIDs))
                available = True
            elif not result.xpCost or result.xpCost > xpCost:
                result = UnlockProps(parentCD, idx, xpCost, set())

        if available:
            result = self._findNext2Unlock(compare, xps=xps, freeXP=freeXP)
        return (available, result)
Пример #11
0
 def unlockModule(self):
     vehicle = self._itemsCache.items.getItemByCD(self._rootCD)
     unlockIdx, xpCost, required = vehicle.getUnlockDescrByIntCD(
         self._nodeCD)
     unlockProps = UnlockProps(self._rootCD, unlockIdx, xpCost, required, 0,
                               xpCost)
     ItemsActionsFactory.doAction(ItemsActionsFactory.UNLOCK_ITEM,
                                  self._nodeCD,
                                  unlockProps,
                                  skipConfirm=self.__skipConfirm)
    def isNext2Unlock(self, vTypeCD, unlocked=None, xps=None, freeXP=0, level=UNKNOWN_VEHICLE_LEVEL):
        unlocked = unlocked or set()
        topLevel = self.getTopLevel(vTypeCD)
        available = False
        topIDs = set()
        compare = []
        result = DEFAULT_UNLOCK_PROPS
        for parentCD in topLevel:
            nextLevel = self.__nextLevels[parentCD]
            idx, xpCost, required = nextLevel[vTypeCD]
            discount, newCost = self.getBlueprintDiscountData(vTypeCD, level, xpCost)
            if required.issubset(unlocked) and parentCD in unlocked:
                topIDs.add(parentCD)
                compare.append(UnlockProps(parentCD, idx, newCost, topIDs, discount, xpCost))
                available = True
            if not result.xpCost or result.xpCost > xpCost:
                result = UnlockProps(parentCD, idx, newCost, set(), discount, xpCost)

        if available:
            result = self._findNext2Unlock(compare, xps=xps, freeXP=freeXP)
        return (available, result)
Пример #13
0
    def getUnlockedVehicleItems(self, vehicle, unlocked):
        """ Gets all unlocked items on vehicle.
        :param vehicle: instance of vehicle gui item.
        :param unlocked: set of int-type compact descriptors.
        :return: dict(int-type compact descriptors: instance of UnlockProps).
        """
        items = {}
        for unlockIdx, xpCost, nodeCD, required in vehicle.getUnlocksDescrs():
            if required.issubset(unlocked) and nodeCD in unlocked:
                items[nodeCD] = UnlockProps(vehicle.intCD, unlockIdx, xpCost,
                                            required)

        return items
Пример #14
0
    def getNext2UnlockByItems(self,
                              itemCDs,
                              unlocked=set(),
                              xps=None,
                              freeXP=0):
        """ Returns list of vehicle are available to unlock (all required
        items are unlocked) by unlocked items.
        NOTE: if xps is defined than searches vehicles for which enough experience
            and available.
        :param itemCDs: list of unlocked items which determine available vehicles.
        :param unlocked: set of unlocked items (int compact descriptor).
        :param xps: dict of vehicles XPs { int compact descriptor : xp, ... }
        :param freeXP: value of free XP.
        :return: dict( <vehicle compact descriptor>: <instance of UnlockProps>, ... )
        """
        filtered = filter(lambda item: item in self.__topItems, itemCDs)
        if not filtered or not unlocked:
            return {}
        available = defaultdict(list)
        parentCDs = set(
            filter(lambda item: getTypeOfCompactDescr(item) == _VEHICLE,
                   itemCDs))
        for item in filtered:
            if item in unlocked:
                parentCDs |= self.__topItems[item]

        for parentCD in parentCDs:
            if parentCD not in unlocked:
                continue
            nextLevel = self.__nextLevels[parentCD]
            topIDs = set()
            for childCD, (idx, xpCost, required) in nextLevel.iteritems():
                if childCD not in unlocked and required.issubset(unlocked):
                    topIDs.add(parentCD)
                    available[childCD].append(
                        UnlockProps(parentCD, idx, xpCost, topIDs))

        result = {}
        for childCD, compare in available.iteritems():
            result[childCD] = self._findNext2Unlock(compare,
                                                    xps=xps,
                                                    freeXP=freeXP)

        return result