コード例 #1
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
コード例 #2
0
ファイル: game_vars.py プロジェクト: kblw/wot_client
def _isItemXPEnough(itemCD, vehicleCD):
    if itemCD is None:
        return False
    vehicle = getVehicleByIntCD(vehicleCD)
    if vehicle is None:
        return False
    stats = g_itemsCache.items.stats
    costs = g_techTreeDP.getUnlockPrices(itemCD)
    if vehicleCD in costs:
        xp = costs[vehicleCD]
    else:
        xp = 0
    return stats.vehiclesXPs.get(vehicleCD, 0) + stats.actualFreeXP >= xp
コード例 #3
0
ファイル: game_vars.py プロジェクト: jamesxia4/wot_client
def _isItemXPEnough(itemCD, vehicleCD):
    if itemCD is None:
        return False
    vehicle = getVehicleByIntCD(vehicleCD)
    if vehicle is None:
        return False
    stats = g_itemsCache.items.stats
    costs = g_techTreeDP.getUnlockPrices(itemCD)
    if vehicleCD in costs:
        xp = costs[vehicleCD]
    else:
        xp = 0
    return stats.vehiclesXPs.get(vehicleCD, 0) + stats.actualFreeXP >= xp
コード例 #4
0
    def maxResearchCost(self, excludes=None):
        res = []
        for intCD, module in self._items.items():
            if excludes and module in excludes:
                continue
            unlockPrices = g_techTreeDP.getUnlockPrices(intCD)
            if unlockPrices:
                vehIntCD = self._vehicle.intCD
                if vehIntCD in unlockPrices:
                    res.append((unlockPrices[vehIntCD], module))

        if not res:
            return (False, None)
        else:
            res = sorted(res)
            return (True, res[-1][1])
コード例 #5
0
def getUnlockPrice(compactDescr, parentCD=None):
    item_type_id, _, _ = vehicles.parseIntCompactDescr(compactDescr)
    itemsCache = dependency.instance(IItemsCache)
    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):
        unlockPrice = pricesDict.get(vehCompDescr, 0)
        pVehXp = xpVehs.get(vehCompDescr, 0)
        need = unlockPrice - pVehXp
        needWithFreeXP = need - freeXP
        return (isAvailable, unlockPrice, min(need, needWithFreeXP))

    if item_type_id == vehicles._VEHICLE:
        isAvailable, props = g_techTreeDP.isNext2Unlock(
            compactDescr, unlocks, xpVehs, freeXP)
        if parentCD is not None:
            return getUnlockProps(isAvailable, parentCD)
        return getUnlockProps(isAvailable, props.parentID)
    else:
        isAvailable = compactDescr in unlocks
        if not pricesDict:
            return (isAvailable, 0, 0)
        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)
        return getUnlockProps(isAvailable, minUnlockPriceVehCD)
        return
コード例 #6
0
    def maxResearchCost(self, excludes=None):
        """Return module with maximum research points cost
        :param excludes: modules for exclude from search
        :return: True, module with max research cost or (False, None)
        """
        res = []
        for intCD, module in self._items.items():
            if excludes and module in excludes:
                continue
            unlockPrices = g_techTreeDP.getUnlockPrices(intCD)
            if unlockPrices:
                vehIntCD = self._vehicle.intCD
                if vehIntCD in unlockPrices:
                    res.append((unlockPrices[vehIntCD], module))

        if not res:
            return (False, None)
        else:
            res = sorted(res)
            return (True, res[-1][1])
コード例 #7
0
ファイル: __init__.py プロジェクト: krzcho/WOTDecompiled
def getUnlockPrice(compactDescr, parentCD = None):
    item_type_id, _, _ = vehicles.parseIntCompactDescr(compactDescr)
    freeXP = g_itemsCache.items.stats.actualFreeXP
    unlocks = g_itemsCache.items.stats.unlocks
    xpVehs = g_itemsCache.items.stats.vehiclesXPs
    g_techTreeDP.load()
    pricesDict = g_techTreeDP.getUnlockPrices(compactDescr)

    def getUnlockProps(isAvailable, vehCompDescr):
        unlockPrice = pricesDict.get(vehCompDescr, 0)
        pVehXp = xpVehs.get(vehCompDescr, 0)
        need = unlockPrice - pVehXp
        needWithFreeXP = need - freeXP
        return (isAvailable, unlockPrice, min(need, needWithFreeXP))

    if item_type_id == vehicles._VEHICLE:
        g_techTreeDP.load()
        isAvailable, props = g_techTreeDP.isNext2Unlock(compactDescr, unlocks, xpVehs, freeXP)
        if parentCD is not None:
            return getUnlockProps(isAvailable, parentCD)
        return getUnlockProps(isAvailable, props.parentID)
    else:
        isAvailable = compactDescr in unlocks
        if not pricesDict:
            return (isAvailable, 0, 0)
        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)
        return getUnlockProps(isAvailable, minUnlockPriceVehCD)
        return