Пример #1
0
 def _getNodeData(self, nodeCD, displayInfo, invCDs):
     earnedXP = self._xps.get(nodeCD, 0)
     gameCredits, gold = self.getShopPrice(nodeCD)
     freeXP = max(self._accFreeXP, 0)
     state = NODE_STATE.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(
         nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=freeXP)
     if nodeCD in self._unlocks:
         state = NODE_STATE.UNLOCKED
         if nodeCD in invCDs:
             state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
     elif available:
         state = NODE_STATE.NEXT_2_UNLOCK
         totalXP = freeXP + self._xps.get(unlockProps.parentID, 0)
         if totalXP >= unlockProps.xpCost:
             state |= NODE_STATE.ENOUGH_XP
     if nodeCD in self._elite:
         state |= NODE_STATE.ELITE
     return {
         'id': nodeCD,
         'earnedXP': earnedXP,
         'state': state,
         'unlockProps': unlockProps,
         'shopPrice': (gameCredits, gold),
         'displayInfo': displayInfo
     }
Пример #2
0
    def _findNext2UnlockItems(self, nodes):
        result = []
        topLevelCDs = self._topLevelCDs.keys()
        freeXP = max(self._accFreeXP, 0)
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
            if itemTypeID == _VEHICLE and nodeCD in topLevelCDs:
                available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=freeXP)
                xp = freeXP + self._xps.get(unlockProps.parentID, 0)
            else:
                unlockProps = node['unlockProps']
                required = unlockProps.required
                available = len(required) and required.issubset(self._unlocks) and nodeCD not in self._unlocks
                xp = freeXP + self._earnedXP
            if available and state & NODE_STATE.LOCKED > 0:
                state ^= NODE_STATE.LOCKED
                state = NODE_STATE.addIfNot(state, NODE_STATE.NEXT_2_UNLOCK)
                if xp >= unlockProps.xpCost:
                    state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
                node['state'] = state
                result.append((node['id'], state, unlockProps._makeTuple()))

        return result
Пример #3
0
    def _findNext2UnlockItems(self, nodes):
        result = []
        topLevelCDs = self._topLevelCDs.keys()
        unlockStats = self.getUnlockStats()
        unlockKwargs = unlockStats._asdict()
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
            if itemTypeID == GUI_ITEM_TYPE.VEHICLE and (
                    nodeCD in topLevelCDs or nodeCD == self.getRootCD()):
                available, unlockProps = g_techTreeDP.isNext2Unlock(
                    nodeCD, **unlockKwargs)
                xp = g_techTreeDP.getAllVehiclePossibleXP(
                    unlockProps.parentID, unlockStats)
            else:
                unlockProps = node['unlockProps']
                required = unlockProps.required
                available = len(required) and unlockStats.isSeqUnlocked(
                    required) and not unlockStats.isUnlocked(nodeCD)
                xp = g_techTreeDP.getAllVehiclePossibleXP(
                    self.getRootCD(), unlockStats)
            if available and state & NODE_STATE.LOCKED > 0:
                state ^= NODE_STATE.LOCKED
                state = NODE_STATE.addIfNot(state, NODE_STATE.NEXT_2_UNLOCK)
                if xp >= unlockProps.xpCost:
                    state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
                node['state'] = state
                result.append((node['id'], state, unlockProps._makeTuple()))

        return result
Пример #4
0
    def _findNext2UnlockItems(self, nodes):
        result = []
        topLevelCDs = self._topLevelCDs.keys()
        unlockStats = self.getUnlockStats()
        unlockKwargs = unlockStats._asdict()
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
            if itemTypeID == GUI_ITEM_TYPE.VEHICLE and (nodeCD in topLevelCDs or nodeCD == self.getRootCD()):
                available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockKwargs)
                xp = self._getAllPossibleXP(unlockProps.parentID, unlockStats)
            else:
                unlockProps = node['unlockProps']
                required = unlockProps.required
                available = len(required) and unlockStats.isSeqUnlocked(required) and not unlockStats.isUnlocked(nodeCD)
                xp = self._getAllPossibleXP(self.getRootCD(), unlockStats)
            if available and state & NODE_STATE.LOCKED > 0:
                state ^= NODE_STATE.LOCKED
                state = NODE_STATE.addIfNot(state, NODE_STATE.NEXT_2_UNLOCK)
                if xp >= unlockProps.xpCost:
                    state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
                node['state'] = state
                result.append((node['id'], state, unlockProps._makeTuple()))

        return result
Пример #5
0
 def _makeRealExposedNode(self, node, guiItem, unlockStats, displayInfo):
     nodeCD = node.nodeCD
     earnedXP = unlockStats.getVehXP(nodeCD)
     state = NODE_STATE_FLAGS.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(
         nodeCD, level=guiItem.level, **unlockStats._asdict())
     if guiItem.isUnlocked:
         state = NODE_STATE_FLAGS.UNLOCKED
         if guiItem.isInInventory:
             state |= NODE_STATE_FLAGS.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE_FLAGS.CAN_SELL
         else:
             if canBuyGoldForItemThroughWeb(
                     nodeCD) or self._mayObtainForMoney(nodeCD):
                 state |= NODE_STATE_FLAGS.ENOUGH_MONEY
             if self._isLastUnlocked(nodeCD):
                 state |= NODE_STATE_FLAGS.LAST_2_BUY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE_FLAGS.WAS_IN_BATTLE
         if guiItem.buyPrices.itemPrice.isActionPrice(
         ) and not guiItem.isRestorePossible():
             state |= NODE_STATE_FLAGS.ACTION
     else:
         if available:
             state = NODE_STATE_FLAGS.NEXT_2_UNLOCK
             if g_techTreeDP.getAllVehiclePossibleXP(
                     unlockProps.parentID,
                     unlockStats) >= unlockProps.xpCost:
                 state |= NODE_STATE_FLAGS.ENOUGH_XP
         if unlockProps.discount:
             state |= NODE_STATE_FLAGS.ACTION
     if guiItem.isElite:
         state |= NODE_STATE_FLAGS.ELITE
     if guiItem.isPremium:
         state |= NODE_STATE_FLAGS.PREMIUM
     if guiItem.isRented and not guiItem.isPremiumIGR:
         state = self._checkExpiredRent(state, guiItem)
         state = self._checkMoney(state, nodeCD)
     if guiItem.isRentable and not guiItem.isInInventory:
         state = self._checkMoney(state, nodeCD)
     if self._isVehicleCanBeChanged():
         state |= NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED
     bpfProps = self._getBlueprintsProps(node.nodeCD, guiItem.level)
     if bpfProps is not None and bpfProps.totalCount > 0:
         state |= NODE_STATE_FLAGS.BLUEPRINT
     state = self._checkRestoreState(state, guiItem)
     state = self._checkRentableState(state, guiItem)
     state = self._checkTradeInState(state, guiItem)
     state = self._checkTechTreeEvents(state, guiItem, unlockProps)
     price = getGUIPrice(guiItem, self._stats.money,
                         self._items.shop.exchangeRate)
     return nodes.RealNode(node.nodeCD,
                           guiItem,
                           earnedXP,
                           state,
                           displayInfo,
                           unlockProps=unlockProps,
                           bpfProps=bpfProps,
                           price=price)
Пример #6
0
 def _getNodeData(self, nodeCD, displayInfo, invCDs):
     earnedXP = self._xps.get(nodeCD, 0)
     gameCredits, gold = self.getShopPrice(nodeCD)
     freeXP = max(self._accFreeXP, 0)
     state = NODE_STATE.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=freeXP)
     if nodeCD in self._unlocks:
         state = NODE_STATE.UNLOCKED
         if nodeCD in invCDs:
             state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
     elif available:
         state = NODE_STATE.NEXT_2_UNLOCK
         totalXP = freeXP + self._xps.get(unlockProps.parentID, 0)
         if totalXP >= unlockProps.xpCost:
             state |= NODE_STATE.ENOUGH_XP
     if nodeCD in self._elite:
         state |= NODE_STATE.ELITE
     return {'id': nodeCD,
      'earnedXP': earnedXP,
      'state': state,
      'unlockProps': unlockProps,
      'shopPrice': (gameCredits, gold),
      'displayInfo': displayInfo}
Пример #7
0
    def _findNext2UnlockItems(self, nodes):
        result = []
        topLevelCDs = self._topLevelCDs.keys()
        freeXP = max(self._accFreeXP, 0)
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
            if itemTypeID == _VEHICLE and nodeCD in topLevelCDs:
                available, unlockProps = g_techTreeDP.isNext2Unlock(
                    nodeCD,
                    unlocked=self._unlocks,
                    xps=self._xps,
                    freeXP=freeXP)
                xp = freeXP + self._xps.get(unlockProps.parentID, 0)
            else:
                unlockProps = node['unlockProps']
                required = unlockProps.required
                available = len(required) and required.issubset(
                    self._unlocks) and nodeCD not in self._unlocks
                xp = freeXP + self._earnedXP
            if available and state & NODE_STATE.LOCKED > 0:
                state ^= NODE_STATE.LOCKED
                state = NODE_STATE.addIfNot(state, NODE_STATE.NEXT_2_UNLOCK)
                if xp >= unlockProps.xpCost:
                    state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
                node['state'] = state
                result.append((node['id'], state, unlockProps._makeTuple()))

        return result
Пример #8
0
    def _findNext2UnlockItems(self, nodes):
        """
        Finds nodes that statuses changed to "next to unlock".
        :param nodes: list of nodes data.
        :return: [(<int:vehicle compact descriptor>, <new state>,
            <new UnlockProps>), ... ].
        """
        result = []
        topLevelCDs = self._topLevelCDs.keys()
        unlockStats = self.getUnlockStats()
        unlockKwargs = unlockStats._asdict()
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
            if itemTypeID == GUI_ITEM_TYPE.VEHICLE and (nodeCD in topLevelCDs or nodeCD == self.getRootCD()):
                available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockKwargs)
                xp = g_techTreeDP.getAllVehiclePossibleXP(unlockProps.parentID, unlockStats)
            else:
                unlockProps = node['unlockProps']
                required = unlockProps.required
                available = len(required) and unlockStats.isSeqUnlocked(required) and not unlockStats.isUnlocked(nodeCD)
                xp = g_techTreeDP.getAllVehiclePossibleXP(self.getRootCD(), unlockStats)
            if available and state & NODE_STATE_FLAGS.LOCKED > 0:
                state ^= NODE_STATE_FLAGS.LOCKED
                state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.NEXT_2_UNLOCK)
                if xp >= unlockProps.xpCost:
                    state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.ENOUGH_XP)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ENOUGH_XP)
                node['state'] = state
                result.append((node['id'], state, unlockProps._makeTuple()))

        return result
Пример #9
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
Пример #10
0
 def __availableToUnlock(cls, vehicle):
     unlockAvailable, _ = g_techTreeDP.isNext2Unlock(
         vehicle.intCD,
         unlocked=cls.__itemsCache.items.stats.unlocks,
         xps=cls.__itemsCache.items.stats.vehiclesXPs,
         freeXP=cls.__itemsCache.items.stats.actualFreeXP,
         level=vehicle.level)
     return unlockAvailable
Пример #11
0
 def _getNodeData(self, nodeCD, rootItem, guiItem, unlockStats, unlockProps, path, level=-1, topLevel=False):
     itemTypeID = guiItem.itemTypeID
     available = False
     xp = 0
     state = NODE_STATE_FLAGS.LOCKED
     if topLevel and itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockStats._asdict())
         xp = g_techTreeDP.getAllVehiclePossibleXP(unlockProps.parentID, unlockStats)
     if guiItem.isUnlocked:
         state = NODE_STATE_FLAGS.UNLOCKED
         if itemTypeID != GUI_ITEM_TYPE.VEHICLE and rootItem.isInInventory and guiItem.isInstalled(rootItem):
             state |= NODE_STATE_FLAGS.INSTALLED
         elif guiItem.isInInventory:
             if rootItem.isInInventory or itemTypeID == GUI_ITEM_TYPE.VEHICLE:
                 state |= NODE_STATE_FLAGS.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE_FLAGS.CAN_SELL
         elif canBuyGoldForItemThroughWeb(nodeCD) or self._mayObtainForMoney(nodeCD):
             state |= NODE_STATE_FLAGS.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE_FLAGS.WAS_IN_BATTLE
         if guiItem.buyPrices.itemPrice.isActionPrice():
             state |= NODE_STATE_FLAGS.SHOP_ACTION
     else:
         if not topLevel:
             available = unlockStats.isSeqUnlocked(unlockProps.required) and unlockStats.isUnlocked(self._rootCD)
             xp = g_techTreeDP.getAllVehiclePossibleXP(self._rootCD, unlockStats)
         if available:
             state = NODE_STATE_FLAGS.NEXT_2_UNLOCK
             if xp >= unlockProps.xpCost:
                 state |= NODE_STATE_FLAGS.ENOUGH_XP
     if itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         if guiItem.isElite:
             state |= NODE_STATE_FLAGS.ELITE
         if guiItem.isPremium:
             state |= NODE_STATE_FLAGS.PREMIUM
         if guiItem.isRented and not guiItem.isPremiumIGR and not guiItem.isTelecom:
             state = self._checkExpiredRent(state, guiItem)
             state = self._checkMoney(state, nodeCD)
         if guiItem.isRentable and not guiItem.isInInventory and not guiItem.isTelecom:
             state = self._checkMoney(state, nodeCD)
         if self._isVehicleCanBeChanged():
             state |= NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED
         if guiItem.isHidden:
             state |= NODE_STATE_FLAGS.PURCHASE_DISABLED
         state = self._checkRestoreState(state, guiItem)
         state = self._checkRentableState(state, guiItem)
         state = self._checkTradeInState(state, guiItem)
         renderer = 'root' if self._rootCD == nodeCD else 'vehicle'
     else:
         renderer = 'item'
     price = getGUIPrice(guiItem, self._stats.money, self._items.shop.exchangeRate)
     displayInfo = {'path': path,
      'renderer': renderer,
      'level': level}
     return nodes.RealNode(nodeCD, guiItem, unlockStats.getVehXP(nodeCD), state, displayInfo, unlockProps=unlockProps, price=price)
Пример #12
0
 def unlockVehicle(self):
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs,
                               stats.freeXP)
     unlockKwargs = unlockStats._asdict()
     _, unlockProps = g_techTreeDP.isNext2Unlock(self._nodeCD,
                                                 **unlockKwargs)
     ItemsActionsFactory.doAction(ItemsActionsFactory.UNLOCK_ITEM,
                                  self._nodeCD, unlockProps.parentID,
                                  unlockProps.unlockIdx, unlockProps.xpCost)
Пример #13
0
 def _getNodeData(self,
                  nodeCD,
                  earnedXP,
                  unlockProps,
                  path,
                  level=-1,
                  renderer=None,
                  topLevel=False):
     gameCredits, gold = self.getShopPrice(nodeCD)
     itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
     available = False
     xp = 0
     freeXP = max(self._accFreeXP, 0)
     state = NODE_STATE.LOCKED
     if topLevel and itemTypeID == _VEHICLE:
         available, unlockProps = g_techTreeDP.isNext2Unlock(
             nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=freeXP)
         xp = freeXP + self._xps.get(unlockProps.parentID, 0)
     if nodeCD in self._unlocks:
         state = NODE_STATE.UNLOCKED
         if nodeCD in self._installed:
             state |= NODE_STATE.INSTALLED
         elif nodeCD in self._invItems.keys(
         ) and self._invItems[nodeCD].count is not None:
             if len(self._installed) or itemTypeID == _VEHICLE:
                 state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
     elif not topLevel:
         if unlockProps.required.issubset(self._unlocks):
             available = self._rootCD in self._unlocks
             xp = freeXP + self._earnedXP
         if available:
             state = NODE_STATE.NEXT_2_UNLOCK
             xp >= unlockProps.xpCost and state |= NODE_STATE.ENOUGH_XP
     if nodeCD in self._elite:
         state |= NODE_STATE.ELITE
     if renderer is None:
         renderer = 'vehicle' if itemTypeID == _VEHICLE else 'item'
     return {
         'id': nodeCD,
         'earnedXP': earnedXP,
         'state': state,
         'unlockProps': unlockProps,
         'shopPrice': (gameCredits, gold),
         'displayInfo': {
             'path': list(path),
             'renderer': renderer,
             'level': level
         }
     }
Пример #14
0
 def _getNodeData(self, nodeCD, rootItem, guiItem, unlockStats, unlockProps, path, level = -1, topLevel = False):
     itemTypeID = guiItem.itemTypeID
     available = False
     xp = 0
     state = NODE_STATE.LOCKED
     if topLevel and itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockStats._asdict())
         xp = self._getAllPossibleXP(unlockProps.parentID, unlockStats)
     if guiItem.isUnlocked:
         state = NODE_STATE.UNLOCKED
         if itemTypeID != GUI_ITEM_TYPE.VEHICLE and rootItem.isInInventory and guiItem.isInstalled(rootItem):
             state |= NODE_STATE.INSTALLED
         elif guiItem.isInInventory:
             if rootItem.isInInventory or itemTypeID == GUI_ITEM_TYPE.VEHICLE:
                 state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
         if guiItem.buyPrice != guiItem.defaultPrice:
             state |= NODE_STATE.SHOP_ACTION
     else:
         if not topLevel:
             available = unlockStats.isSeqUnlocked(unlockProps.required) and unlockStats.isUnlocked(self._rootCD)
             xp = self._getAllPossibleXP(self._rootCD, unlockStats)
         if available:
             state = NODE_STATE.NEXT_2_UNLOCK
             if xp >= unlockProps.xpCost:
                 state |= NODE_STATE.ENOUGH_XP
     if itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         if guiItem.isElite:
             state |= NODE_STATE.ELITE
         if guiItem.isPremium:
             state |= NODE_STATE.PREMIUM
         if guiItem.isRented and not guiItem.isPremiumIGR and not guiItem.isTelecom:
             state = self._checkExpiredRent(state, guiItem)
             state = self._checkMoneyForRentOrBuy(state, nodeCD)
         if guiItem.isRentable and not guiItem.isInInventory and not guiItem.isTelecom:
             state = self._checkMoneyForRentOrBuy(state, nodeCD)
         if self._isVehicleCanBeChanged():
             state |= NODE_STATE.VEHICLE_CAN_BE_CHANGED
         if guiItem.isDisabledForBuy:
             state |= NODE_STATE.PURCHASE_DISABLED
         renderer = 'root' if self._rootCD == nodeCD else 'vehicle'
     else:
         renderer = 'item'
     return {'id': nodeCD,
      'earnedXP': unlockStats.getVehXP(nodeCD),
      'state': state,
      'unlockProps': unlockProps,
      'displayInfo': {'path': list(path),
                      'renderer': renderer,
                      'level': level}}
Пример #15
0
 def _getNodeData(self, nodeCD, guiItem, unlockStats, displayInfo):
     """
     Gets node data that stores to node list.
     """
     earnedXP = unlockStats.getVehXP(nodeCD)
     state = NODE_STATE_FLAGS.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(
         nodeCD, **unlockStats._asdict())
     if guiItem.isUnlocked:
         state = NODE_STATE_FLAGS.UNLOCKED
         if guiItem.isInInventory:
             state |= NODE_STATE_FLAGS.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE_FLAGS.CAN_SELL
         elif self._mayObtainForMoney(nodeCD):
             state |= NODE_STATE_FLAGS.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE_FLAGS.WAS_IN_BATTLE
         if guiItem.buyPrice != guiItem.defaultPrice:
             state |= NODE_STATE_FLAGS.SHOP_ACTION
     elif available:
         state = NODE_STATE_FLAGS.NEXT_2_UNLOCK
         if g_techTreeDP.getAllVehiclePossibleXP(
                 unlockProps.parentID, unlockStats) >= unlockProps.xpCost:
             state |= NODE_STATE_FLAGS.ENOUGH_XP
     if guiItem.isElite:
         state |= NODE_STATE_FLAGS.ELITE
     if guiItem.isPremium:
         state |= NODE_STATE_FLAGS.PREMIUM
     if guiItem.isRented and not guiItem.isPremiumIGR:
         state = self._checkExpiredRent(state, guiItem)
         state = self._checkMoney(state, nodeCD)
     if guiItem.isRentable and not guiItem.isInInventory:
         state = self._checkMoney(state, nodeCD)
     if self._isVehicleCanBeChanged():
         state |= NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED
     state = self._checkRestoreState(state, guiItem)
     state = self._checkRentableState(state, guiItem)
     return {
         'id':
         nodeCD,
         'earnedXP':
         earnedXP,
         'state':
         state,
         'unlockProps':
         unlockProps,
         'GUIPrice':
         getGUIPrice(guiItem, self._stats.money,
                     self._items.shop.exchangeRate),
         'displayInfo':
         displayInfo
     }
Пример #16
0
 def unlockVehicle(self):
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
     unlockKwargs = unlockStats._asdict()
     _, unlockProps = g_techTreeDP.isNext2Unlock(self._nodeCD, **unlockKwargs)
     ItemsActionsFactory.doAction(
         ItemsActionsFactory.UNLOCK_ITEM,
         self._nodeCD,
         unlockProps.parentID,
         unlockProps.unlockIdx,
         unlockProps.xpCost,
     )
Пример #17
0
 def _getNodeData(self, nodeCD, rootItem, guiItem, unlockStats, unlockProps, path, level = -1, topLevel = False):
     itemTypeID = guiItem.itemTypeID
     available = False
     xp = 0
     state = NODE_STATE.LOCKED
     if topLevel and itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockStats._asdict())
         xp = self._getAllPossibleXP(unlockProps.parentID, unlockStats)
     if guiItem.isUnlocked:
         state = NODE_STATE.UNLOCKED
         if itemTypeID != GUI_ITEM_TYPE.VEHICLE and rootItem.isInInventory and guiItem.isInstalled(rootItem):
             state |= NODE_STATE.INSTALLED
         elif guiItem.isInInventory:
             if rootItem.isInInventory or itemTypeID == GUI_ITEM_TYPE.VEHICLE:
                 state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
         if guiItem.buyPrice != guiItem.defaultPrice:
             state |= NODE_STATE.SHOP_ACTION
     else:
         if not topLevel:
             available = unlockStats.isSeqUnlocked(unlockProps.required) and unlockStats.isUnlocked(self._rootCD)
             xp = self._getAllPossibleXP(self._rootCD, unlockStats)
         if available:
             state = NODE_STATE.NEXT_2_UNLOCK
             if xp >= unlockProps.xpCost:
                 state |= NODE_STATE.ENOUGH_XP
     if itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         if guiItem.isElite:
             state |= NODE_STATE.ELITE
         if guiItem.isPremium:
             state |= NODE_STATE.PREMIUM
         if guiItem.isRented and not guiItem.isPremiumIGR:
             state = self._checkExpiredRent(state, guiItem)
             state = self._checkMoneyForRentOrBuy(state, nodeCD)
         if guiItem.isRentable and not guiItem.isInInventory:
             state = self._checkMoneyForRentOrBuy(state, nodeCD)
         if self._isVehicleCanBeChanged():
             state |= NODE_STATE.VEHICLE_CAN_BE_CHANGED
         renderer = 'root' if self._rootCD == nodeCD else 'vehicle'
     else:
         renderer = 'item'
     return {'id': nodeCD,
      'earnedXP': unlockStats.getVehXP(nodeCD),
      'state': state,
      'unlockProps': unlockProps,
      'displayInfo': {'path': list(path),
                      'renderer': renderer,
                      'level': level}}
Пример #18
0
    def invalidateXpCosts(self):
        result = []
        nodes = filter(lambda item: NODE_STATE.NEXT_2_UNLOCK & item['state'], self._getNodesToInvalidate())
        for node in nodes:
            nodeCD = node['id']
            props = node['unlockProps']
            _, newProps = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=max(self._accFreeXP, 0))
            if newProps.parentID != props.parentID:
                node['unlockProps'] = newProps
                result.append((nodeCD, newProps))

        return result
Пример #19
0
    def invalidateXpCosts(self):
        result = []
        nodes_ = filter(lambda item: NODE_STATE_FLAGS.NEXT_2_UNLOCK & item.getState(), self._getNodesToInvalidate())
        statsAsDict = self.getUnlockStats()._asdict()
        for node in nodes_:
            nodeCD = node.getNodeCD()
            props = node.getUnlockProps()
            _, newProps = g_techTreeDP.isNext2Unlock(nodeCD, **statsAsDict)
            if newProps.parentID != props.parentID:
                node.setUnlockProps(newProps)
                result.append((nodeCD, newProps))

        return result
Пример #20
0
    def invalidateXpCosts(self):
        result = []
        nodes = filter(lambda item: NODE_STATE.NEXT_2_UNLOCK & item['state'], self._getNodesToInvalidate())
        statsAsDict = self.getUnlockStats()._asdict()
        for node in nodes:
            nodeCD = node['id']
            props = node['unlockProps']
            _, newProps = g_techTreeDP.isNext2Unlock(nodeCD, **statsAsDict)
            if newProps.parentID != props.parentID:
                node['unlockProps'] = newProps
                result.append((nodeCD, newProps))

        return result
Пример #21
0
    def invalidateXpCosts(self):
        result = []
        nodes = filter(lambda item: NODE_STATE.NEXT_2_UNLOCK & item['state'], self._getNodesToInvalidate())
        statsAsDict = self.getUnlockStats()._asdict()
        for node in nodes:
            nodeCD = node['id']
            props = node['unlockProps']
            _, newProps = g_techTreeDP.isNext2Unlock(nodeCD, **statsAsDict)
            if newProps.parentID != props.parentID:
                node['unlockProps'] = newProps
                result.append((nodeCD, newProps))

        return result
Пример #22
0
 def _makeRealExposedNode(self, node, guiItem, unlockStats, displayInfo):
     """
     Gets node data that stores to node list.
     """
     nodeCD = node.nodeCD
     earnedXP = unlockStats.getVehXP(nodeCD)
     state = NODE_STATE_FLAGS.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(
         nodeCD, **unlockStats._asdict())
     if guiItem.isUnlocked:
         state = NODE_STATE_FLAGS.UNLOCKED
         if guiItem.isInInventory:
             state |= NODE_STATE_FLAGS.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE_FLAGS.CAN_SELL
         elif self._mayObtainForMoney(nodeCD):
             state |= NODE_STATE_FLAGS.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE_FLAGS.WAS_IN_BATTLE
         if guiItem.buyPrices.itemPrice.isActionPrice():
             state |= NODE_STATE_FLAGS.SHOP_ACTION
     elif available:
         state = NODE_STATE_FLAGS.NEXT_2_UNLOCK
         if g_techTreeDP.getAllVehiclePossibleXP(
                 unlockProps.parentID, unlockStats) >= unlockProps.xpCost:
             state |= NODE_STATE_FLAGS.ENOUGH_XP
     if guiItem.isElite:
         state |= NODE_STATE_FLAGS.ELITE
     if guiItem.isPremium:
         state |= NODE_STATE_FLAGS.PREMIUM
     if guiItem.isRented and not guiItem.isPremiumIGR:
         state = self._checkExpiredRent(state, guiItem)
         state = self._checkMoney(state, nodeCD)
     if guiItem.isRentable and not guiItem.isInInventory:
         state = self._checkMoney(state, nodeCD)
     if self._isVehicleCanBeChanged():
         state |= NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED
     state = self._checkRestoreState(state, guiItem)
     state = self._checkRentableState(state, guiItem)
     state = self._checkTradeInState(state, guiItem)
     price = getGUIPrice(guiItem, self._stats.money,
                         self._items.shop.exchangeRate)
     return nodes.RealNode(node.nodeCD,
                           guiItem,
                           earnedXP,
                           state,
                           displayInfo,
                           unlockProps=unlockProps,
                           price=price)
Пример #23
0
    def isNext2Unlock(self, nodeCD):
        itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
        topLevelCDs = []
        if itemTypeID == _VEHICLE:
            topLevelCDs = map(lambda node: node['id'], self._topLevel)
        if nodeCD in topLevelCDs:
            result, _ = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=max(self._accFreeXP, 0))
        else:
            try:
                node = self._nodes[self._nodesIdx[nodeCD]]
                result = node['unlockProps'].required.issubset(self._unlocks)
            except (KeyError, IndexError):
                result = False

        return result
Пример #24
0
 def __getBtnDataLockedVehicle(self, vehicle):
     stats = self.itemsCache.items.stats
     tooltip = ''
     nodeCD = vehicle.intCD
     isAvailableToUnlock, xpCost, _ = g_techTreeDP.isVehicleAvailableToUnlock(nodeCD)
     if not isAvailableToUnlock:
         g_techTreeDP.load()
         unlocks = self.itemsCache.items.stats.unlocks
         next2Unlock, _ = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=set(unlocks), xps=stats.vehiclesXPs, freeXP=stats.freeXP)
         if next2Unlock:
             tooltip = _buildBuyButtonTooltip('notEnoughXp')
         elif any((bool(cd in unlocks) for cd in g_techTreeDP.getTopLevel(nodeCD))):
             tooltip = _buildBuyButtonTooltip('parentModuleIsLocked')
         else:
             tooltip = _buildBuyButtonTooltip('parentVehicleIsLocked')
     return _ButtonState(isAvailableToUnlock, ['xp', xpCost], VEHICLE_PREVIEW.BUYINGPANEL_BUYBTN_LABEL_RESEARCH, None, tooltip, self.__packTitle)
Пример #25
0
    def invalidateXpCosts(self):
        result = []
        nodes = filter(lambda item: NODE_STATE.NEXT_2_UNLOCK & item['state'],
                       self._getNodesToInvalidate())
        for node in nodes:
            nodeCD = node['id']
            props = node['unlockProps']
            _, newProps = g_techTreeDP.isNext2Unlock(nodeCD,
                                                     unlocked=self._unlocks,
                                                     xps=self._xps,
                                                     freeXP=max(
                                                         self._accFreeXP, 0))
            if newProps.parentID != props.parentID:
                node['unlockProps'] = newProps
                result.append((nodeCD, newProps))

        return result
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
 def __getBtnDataLockedVehicle(self, vehicle):
     stats = self._itemsCache.items.stats
     tooltip = ''
     buttonIcon = None
     buttonIconAlign = None
     nodeCD = vehicle.intCD
     _, isXpEnough = g_techTreeDP.isVehicleAvailableToUnlock(
         nodeCD, self._vehicleLevel)
     unlocks = self._itemsCache.items.stats.unlocks
     isNext2Unlock, unlockProps = g_techTreeDP.isNext2Unlock(
         nodeCD,
         unlocked=set(unlocks),
         xps=stats.vehiclesXPs,
         freeXP=stats.freeXP,
         level=self._vehicleLevel)
     isAvailableToUnlock = isXpEnough and isNext2Unlock
     if not isAvailableToUnlock:
         if not isXpEnough:
             tooltip = _buildBuyButtonTooltip('notEnoughXp')
         elif any((bool(cd in unlocks)
                   for cd in g_techTreeDP.getTopLevel(nodeCD))):
             tooltip = _buildBuyButtonTooltip('parentModuleIsLocked')
         else:
             tooltip = _buildBuyButtonTooltip('parentVehicleIsLocked')
     specialData = getHeroTankPreviewParams() if self.__isHeroTank else None
     if specialData is not None and specialData.buyButtonLabel:
         buyLabel = backport.text(specialData.buyButtonLabel)
     else:
         buyLabel = backport.text(
             R.strings.vehicle_preview.buyingPanel.buyBtn.label.research())
     return _ButtonState(enabled=isAvailableToUnlock,
                         itemPrice=getItemUnlockPricesVO(unlockProps),
                         label=buyLabel,
                         icon=buttonIcon,
                         iconAlign=buttonIconAlign,
                         isAction=unlockProps.discount > 0,
                         actionTooltip=None,
                         tooltip=tooltip,
                         title=self.__title,
                         isMoneyEnough=isXpEnough,
                         isUnlock=True,
                         isPrevItemsUnlock=isNext2Unlock,
                         customOffer=None,
                         isShowSpecial=False)
Пример #28
0
    def _findNext2UnlockItems(self, nodes):
        """
        Finds nodes that statuses changed to "next to unlock".
        :param nodes: list of nodes data.
        :return: [(<int:vehicle compact descriptor>, <new state>,
            <new UnlockProps>), ... ].
        """
        result = []
        topLevelCDs = self._topLevelCDs.keys()
        unlockStats = self.getUnlockStats()
        unlockKwargs = unlockStats._asdict()
        for node in nodes:
            nodeCD = node.getNodeCD()
            state = node.getState()
            itemTypeID, _, _ = vehicles_core.parseIntCompactDescr(nodeCD)
            if itemTypeID == GUI_ITEM_TYPE.VEHICLE and (
                    nodeCD in topLevelCDs or nodeCD == self.getRootCD()):
                available, unlockProps = g_techTreeDP.isNext2Unlock(
                    nodeCD, **unlockKwargs)
                xp = g_techTreeDP.getAllVehiclePossibleXP(
                    unlockProps.parentID, unlockStats)
            else:
                unlockProps = node.getUnlockProps()
                required = unlockProps.required
                available = len(required) and unlockStats.isSeqUnlocked(
                    required) and not unlockStats.isUnlocked(nodeCD)
                xp = g_techTreeDP.getAllVehiclePossibleXP(
                    self.getRootCD(), unlockStats)
            if available and state & NODE_STATE_FLAGS.LOCKED > 0:
                state ^= NODE_STATE_FLAGS.LOCKED
                state = NODE_STATE.addIfNot(state,
                                            NODE_STATE_FLAGS.NEXT_2_UNLOCK)
                if xp >= unlockProps.xpCost:
                    state = NODE_STATE.addIfNot(state,
                                                NODE_STATE_FLAGS.ENOUGH_XP)
                else:
                    state = NODE_STATE.removeIfHas(state,
                                                   NODE_STATE_FLAGS.ENOUGH_XP)
                node.setState(state)
                result.append(
                    (node.getNodeCD(), state, unlockProps.makeTuple()))

        return result
Пример #29
0
    def isNext2Unlock(self, nodeCD):
        itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
        topLevelCDs = []
        if itemTypeID == _VEHICLE:
            topLevelCDs = map(lambda node: node['id'], self._topLevel)
        if nodeCD in topLevelCDs:
            result, _ = g_techTreeDP.isNext2Unlock(nodeCD,
                                                   unlocked=self._unlocks,
                                                   xps=self._xps,
                                                   freeXP=max(
                                                       self._accFreeXP, 0))
        else:
            try:
                node = self._nodes[self._nodesIdx[nodeCD]]
                result = node['unlockProps'].required.issubset(self._unlocks)
            except (KeyError, IndexError):
                result = False

        return result
Пример #30
0
 def __getBtnData(self):
     vehicle = g_currentPreviewVehicle.item
     stats = self.itemsCache.items.stats
     tooltip = ''
     if vehicle.isUnlocked:
         money = stats.money
         money = self.tradeIn.addTradeInPriceIfNeeded(vehicle, money)
         exchangeRate = self.itemsCache.items.shop.exchangeRate
         price = getGUIPrice(vehicle, money, exchangeRate)
         currency = price.getCurrency(byWeight=True)
         action = getActionPriceData(vehicle)
         mayObtainForMoney = vehicle.mayObtainWithMoneyExchange(money, exchangeRate)
         if currency == Currency.GOLD:
             currencyIcon = RES_ICONS.MAPS_ICONS_LIBRARY_GOLDICONBIG
             if mayObtainForMoney:
                 formatter = text_styles.goldTextBig
             else:
                 formatter = text_styles.errCurrencyTextBig
                 tooltip = _buildBuyButtonTooltip('notEnoughGold')
         else:
             currencyIcon = RES_ICONS.MAPS_ICONS_LIBRARY_CREDITSICONBIG
             formatter = text_styles.creditsTextBig if mayObtainForMoney else text_styles.errCurrencyTextBig
             if not mayObtainForMoney:
                 tooltip = _buildBuyButtonTooltip('notEnoughCredits')
         if self._disableBuyButton:
             mayObtainForMoney = False
         return _ButtonState(mayObtainForMoney, formatter(BigWorld.wg_getIntegralFormat(price.getSignValue(currency))), VEHICLE_PREVIEW.BUYINGPANEL_BUYBTN_LABEL_RESTORE if vehicle.isRestorePossible() else VEHICLE_PREVIEW.BUYINGPANEL_BUYBTN_LABEL_BUY, action is not None, currencyIcon, action, tooltip)
     else:
         nodeCD = vehicle.intCD
         currencyIcon = RES_ICONS.MAPS_ICONS_LIBRARY_XPCOSTICONBIG
         isAvailableToUnlock, xpCost, possibleXp = g_techTreeDP.isVehicleAvailableToUnlock(nodeCD)
         formatter = text_styles.creditsTextBig if possibleXp >= xpCost else text_styles.errCurrencyTextBig
         if not isAvailableToUnlock:
             unlocks = self.itemsCache.items.stats.unlocks
             next2Unlock, _ = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=set(unlocks), xps=stats.vehiclesXPs, freeXP=stats.freeXP)
             if next2Unlock:
                 tooltip = _buildBuyButtonTooltip('notEnoughXp')
             elif any(map(lambda cd: cd in unlocks, g_techTreeDP.getTopLevel(nodeCD))):
                 tooltip = _buildBuyButtonTooltip('parentModuleIsLocked')
             else:
                 tooltip = _buildBuyButtonTooltip('parentVehicleIsLocked')
         return _ButtonState(isAvailableToUnlock, formatter(BigWorld.wg_getIntegralFormat(xpCost)), VEHICLE_PREVIEW.BUYINGPANEL_BUYBTN_LABEL_RESEARCH, False, currencyIcon, None, tooltip)
         return None
Пример #31
0
 def _getNodeData(self, nodeCD, guiItem, unlockStats, displayInfo):
     """
     Gets node data that stores to node list.
     """
     earnedXP = unlockStats.getVehXP(nodeCD)
     state = NODE_STATE_FLAGS.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockStats._asdict())
     if guiItem.isUnlocked:
         state = NODE_STATE_FLAGS.UNLOCKED
         if guiItem.isInInventory:
             state |= NODE_STATE_FLAGS.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE_FLAGS.CAN_SELL
         elif self._mayObtainForMoney(nodeCD):
             state |= NODE_STATE_FLAGS.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE_FLAGS.WAS_IN_BATTLE
         if guiItem.buyPrice != guiItem.defaultPrice:
             state |= NODE_STATE_FLAGS.SHOP_ACTION
     elif available:
         state = NODE_STATE_FLAGS.NEXT_2_UNLOCK
         if g_techTreeDP.getAllVehiclePossibleXP(unlockProps.parentID, unlockStats) >= unlockProps.xpCost:
             state |= NODE_STATE_FLAGS.ENOUGH_XP
     if guiItem.isElite:
         state |= NODE_STATE_FLAGS.ELITE
     if guiItem.isPremium:
         state |= NODE_STATE_FLAGS.PREMIUM
     if guiItem.isRented and not guiItem.isPremiumIGR:
         state = self._checkExpiredRent(state, guiItem)
         state = self._checkMoney(state, nodeCD)
     if guiItem.isRentable and not guiItem.isInInventory:
         state = self._checkMoney(state, nodeCD)
     if self._isVehicleCanBeChanged():
         state |= NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED
     state = self._checkRestoreState(state, guiItem)
     state = self._checkRentableState(state, guiItem)
     return {'id': nodeCD,
      'earnedXP': earnedXP,
      'state': state,
      'unlockProps': unlockProps,
      'GUIPrice': getGUIPrice(guiItem, self._stats.money, self._items.shop.exchangeRate),
      'displayInfo': displayInfo}
Пример #32
0
 def _getNodeData(self, nodeCD, earnedXP, unlockProps, path, level = -1, renderer = None, topLevel = False):
     gameCredits, gold = self.getShopPrice(nodeCD)
     itemTypeID, _, _ = vehicles.parseIntCompactDescr(nodeCD)
     available = False
     xp = 0
     freeXP = max(self._accFreeXP, 0)
     state = NODE_STATE.LOCKED
     if topLevel and itemTypeID == _VEHICLE:
         available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=freeXP)
         xp = freeXP + self._xps.get(unlockProps.parentID, 0)
     if nodeCD in self._unlocks:
         state = NODE_STATE.UNLOCKED
         if nodeCD in self._installed:
             state |= NODE_STATE.INSTALLED
         elif nodeCD in self._invItems.keys() and self._invItems[nodeCD].count is not None:
             if len(self._installed) or itemTypeID == _VEHICLE:
                 state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
     elif not topLevel:
         if unlockProps.required.issubset(self._unlocks):
             available = self._rootCD in self._unlocks
             xp = freeXP + self._earnedXP
         if available:
             state = NODE_STATE.NEXT_2_UNLOCK
             xp >= unlockProps.xpCost and state |= NODE_STATE.ENOUGH_XP
     if nodeCD in self._elite:
         state |= NODE_STATE.ELITE
     if renderer is None:
         renderer = 'vehicle' if itemTypeID == _VEHICLE else 'item'
     return {'id': nodeCD,
      'earnedXP': earnedXP,
      'state': state,
      'unlockProps': unlockProps,
      'shopPrice': (gameCredits, gold),
      'displayInfo': {'path': list(path),
                      'renderer': renderer,
                      'level': level}}
Пример #33
0
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
Пример #34
0
 def _getNodeData(self, nodeCD, guiItem, unlockStats, displayInfo):
     earnedXP = unlockStats.getVehXP(nodeCD)
     state = NODE_STATE.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(
         nodeCD, **unlockStats._asdict())
     if guiItem.isUnlocked:
         state = NODE_STATE.UNLOCKED
         if guiItem.isInInventory:
             state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
         if guiItem.buyPrice != guiItem.defaultPrice:
             state |= NODE_STATE.SHOP_ACTION
     elif available:
         state = NODE_STATE.NEXT_2_UNLOCK
         if g_techTreeDP.getAllVehiclePossibleXP(
                 unlockProps.parentID, unlockStats) >= unlockProps.xpCost:
             state |= NODE_STATE.ENOUGH_XP
     if guiItem.isElite:
         state |= NODE_STATE.ELITE
     if guiItem.isPremium:
         state |= NODE_STATE.PREMIUM
     if guiItem.isRented and not guiItem.isPremiumIGR:
         state = self._checkExpiredRent(state, guiItem)
         state = self._checkMoneyForRentOrBuy(state, nodeCD)
     if guiItem.isRentable and not guiItem.isInInventory:
         state = self._checkMoneyForRentOrBuy(state, nodeCD)
     if self._isVehicleCanBeChanged():
         state |= NODE_STATE.VEHICLE_CAN_BE_CHANGED
     return {
         'id': nodeCD,
         'earnedXP': earnedXP,
         'state': state,
         'unlockProps': unlockProps,
         'displayInfo': displayInfo
     }
Пример #35
0
 def _validate(self):
     unlockCD, vehCD, unlockIdx, xpCost = self._unlockCtx[:]
     itemGetter = g_itemsCache.items.getItemByCD
     vehicle = itemGetter(vehCD)
     item = itemGetter(unlockCD)
     if vehicle.itemTypeID != GUI_ITEM_TYPE.VEHICLE:
         LOG_ERROR('Int compact descriptor is not for vehicle', vehCD)
         return plugins.makeError('vehicle_invalid')
     if not vehicle.isUnlocked:
         LOG_ERROR('Vehicle is not unlocked', unlockCD, vehCD)
         return plugins.makeError('vehicle_locked')
     if item.isUnlocked:
         return plugins.makeError('already_unlocked')
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs,
                               stats.freeXP)
     if item.itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         result, _ = g_techTreeDP.isNext2Unlock(unlockCD,
                                                **unlockStats._asdict())
         if not result:
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     else:
         _xpCost, _itemCD, required = vehicle.getUnlocksDescr(
             self._unlockCtx.unlockIdx)
         if _itemCD != unlockCD:
             LOG_ERROR('Item is invalid', self._unlockCtx)
             return plugins.makeError('item_invalid')
         if _xpCost != xpCost:
             LOG_ERROR('XP cost is invalid', self._unlockCtx)
             return plugins.makeError('xp_cost_invalid')
         if not unlockStats.isSeqUnlocked(required):
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     if unlockStats.getVehTotalXP(vehCD) < xpCost:
         LOG_ERROR('XP not enough for unlock', self._unlockCtx)
         return plugins.makeError()
     if RequestState.inProcess('unlock'):
         return plugins.makeError('in_processing')
     return plugins.makeSuccess()
Пример #36
0
 def _validate(self):
     unlockCD, vehCD, unlockIdx, xpCost = self._unlockCtx[:]
     itemGetter = g_itemsCache.items.getItemByCD
     vehicle = itemGetter(vehCD)
     item = itemGetter(unlockCD)
     if vehicle.itemTypeID != GUI_ITEM_TYPE.VEHICLE:
         LOG_ERROR('Int compact descriptor is not for vehicle', vehCD)
         return plugins.makeError('vehicle_invalid')
     if not vehicle.isUnlocked:
         LOG_ERROR('Vehicle is not unlocked', unlockCD, vehCD)
         return plugins.makeError('vehicle_locked')
     if item.isUnlocked:
         return plugins.makeError('already_unlocked')
     stats = g_itemsCache.items.stats
     unlockStats = UnlockStats(stats.unlocks, stats.vehiclesXPs, stats.freeXP)
     if item.itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         result, _ = g_techTreeDP.isNext2Unlock(unlockCD, **unlockStats._asdict())
         if not result:
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     else:
         _xpCost, _itemCD, required = vehicle.getUnlocksDescr(self._unlockCtx.unlockIdx)
         if _itemCD != unlockCD:
             LOG_ERROR('Item is invalid', self._unlockCtx)
             return plugins.makeError('item_invalid')
         if _xpCost != xpCost:
             LOG_ERROR('XP cost is invalid', self._unlockCtx)
             return plugins.makeError('xp_cost_invalid')
         if not unlockStats.isSeqUnlocked(required):
             LOG_ERROR('Required items are not unlocked', self._unlockCtx)
             return plugins.makeError('required_locked')
     if unlockStats.getVehTotalXP(vehCD) < xpCost:
         LOG_ERROR('XP not enough for unlock', self._unlockCtx)
         return plugins.makeError()
     if RequestState.inProcess('unlock'):
         return plugins.makeError('in_processing')
     return plugins.makeSuccess()
Пример #37
0
 def _getNodeData(self, nodeCD, guiItem, unlockStats, displayInfo):
     earnedXP = unlockStats.getVehXP(nodeCD)
     state = NODE_STATE.LOCKED
     available, unlockProps = g_techTreeDP.isNext2Unlock(nodeCD, **unlockStats._asdict())
     if guiItem.isUnlocked:
         state = NODE_STATE.UNLOCKED
         if guiItem.isInInventory:
             state |= NODE_STATE.IN_INVENTORY
             if self._canSell(nodeCD):
                 state |= NODE_STATE.CAN_SELL
         elif self._canBuy(nodeCD):
             state |= NODE_STATE.ENOUGH_MONEY
         if nodeCD in self._wereInBattle:
             state |= NODE_STATE.WAS_IN_BATTLE
         if guiItem.buyPrice != guiItem.defaultPrice:
             state |= NODE_STATE.SHOP_ACTION
     elif available:
         state = NODE_STATE.NEXT_2_UNLOCK
         if self._getAllPossibleXP(unlockProps.parentID, unlockStats) >= unlockProps.xpCost:
             state |= NODE_STATE.ENOUGH_XP
     if guiItem.isElite:
         state |= NODE_STATE.ELITE
     if guiItem.isPremium:
         state |= NODE_STATE.PREMIUM
     if guiItem.isRented and not guiItem.isPremiumIGR:
         state = self._checkExpiredRent(state, guiItem)
         state = self._checkMoneyForRentOrBuy(state, nodeCD)
     if guiItem.isRentable and not guiItem.isInInventory:
         state = self._checkMoneyForRentOrBuy(state, nodeCD)
     if self._isVehicleCanBeChanged():
         state |= NODE_STATE.VEHICLE_CAN_BE_CHANGED
     return {'id': nodeCD,
      'earnedXP': earnedXP,
      'state': state,
      'unlockProps': unlockProps,
      'displayInfo': displayInfo}
Пример #38
0
 def isNext2Unlock(self, nodeCD):
     result, _ = g_techTreeDP.isNext2Unlock(nodeCD,
                                            unlocked=self._unlocks,
                                            xps=self._xps,
                                            freeXP=max(self._accFreeXP, 0))
     return result
Пример #39
0
 def isNext2Unlock(self, nodeCD):
     result, _ = g_techTreeDP.isNext2Unlock(nodeCD, unlocked=self._unlocks, xps=self._xps, freeXP=max(self._accFreeXP, 0))
     return result
 def _buildVehicle(self, item):
     bpRequester = self._itemsCache.items.blueprints
     name = getVehicleName(vehicle=item)
     intelligenceIcon = RES_ICONS.getBlueprintFragment(
         'small', 'intelligence')
     nationalIcon = RES_ICONS.getBlueprintFragment('small', item.nationName)
     current, total = bpRequester.getBlueprintCount(item.intCD, item.level)
     nationalCost, intelligenceCost = bpRequester.getRequiredIntelligenceAndNational(
         item.level)
     availableCount = bpRequester.getConvertibleFragmentCount(
         item.intCD, item.level)
     if availableCount > 0:
         description = self.__getConvertAvailableDescription(availableCount)
     else:
         existingNational = bpRequester.getNationalFragments(item.intCD)
         existingIntelligence = bpRequester.getIntelligenceData()
         intelligenceRequired = max(
             (0, intelligenceCost - existingIntelligence))
         nationalRequired = max((0, nationalCost - existingNational))
         description = self.__getConvertRequiredDescription(
             intelligenceRequired, intelligenceIcon, nationalRequired,
             nationalIcon)
     availableToUnlock, _ = g_techTreeDP.isNext2Unlock(
         item.intCD,
         unlocked=self._itemsCache.items.stats.unlocks,
         xps=self._itemsCache.items.stats.vehiclesXPs,
         freeXP=self._itemsCache.items.stats.actualFreeXP,
         level=item.level)
     fragmentsCostText = self.__formatFragmentsCost(
         intelligenceCost=intelligenceCost,
         intelligenceIcon=intelligenceIcon,
         nationalCost=nationalCost,
         nationalIcon=nationalIcon)
     discount = bpRequester.getBlueprintDiscount(item.intCD, item.level)
     fragmentsProgress = self.__formatFragmentProgress(
         current, total, discount)
     image = func_utils.makeFlashPath(
         item.getShopIcon(STORE_CONSTANTS.ICON_SIZE_SMALL))
     return {
         'id':
         item.intCD,
         'title':
         name,
         'description':
         description,
         'image':
         image,
         'imageAlt':
         RES_SHOP.getVehicleIcon(STORE_CONSTANTS.ICON_SIZE_SMALL,
                                 'empty_tank'),
         'fragmentsCostText':
         fragmentsCostText,
         'fragmentsProgress':
         fragmentsProgress,
         'hasDiscount':
         discount > 0,
         'availableToUnlock':
         availableToUnlock,
         'convertAvailable':
         availableCount > 0,
         'contextMenuId':
         CONTEXT_MENU_HANDLER_TYPE.STORAGE_BLUEPRINTS_ITEM
     }
Пример #41
0
 def _buildVehicle(self, item):
     bpRequester = self._itemsCache.items.blueprints
     name = getVehicleName(vehicle=item)
     intelligenceIcon = RES_ICONS.getBlueprintFragment(
         'special', 'intelligence')
     current, total = bpRequester.getBlueprintCount(item.intCD, item.level)
     _, intelligenceCost = bpRequester.getRequiredIntelligenceAndNational(
         item.level)
     nationalsCost = bpRequester.getNationalRequiredOptions(
         item.intCD, item.level)
     availableCount = bpRequester.getConvertibleFragmentCount(
         item.intCD, item.level)
     if availableCount > 0:
         description = makeString(
             STORAGE.BLUEPRINTS_CARD_CONVERTAVAILABLE,
             count=text_styles.stats(
                 backport.getIntegralFormat(availableCount)))
     else:
         description = text_styles.error(
             STORAGE.BLUEPRINTS_CARD_CONVERTREQUIRED)
     availableToUnlock, _ = g_techTreeDP.isNext2Unlock(
         item.intCD,
         unlocked=self._itemsCache.items.stats.unlocks,
         xps=self._itemsCache.items.stats.vehiclesXPs,
         freeXP=self._itemsCache.items.stats.actualFreeXP,
         level=item.level)
     intelligenceCostText, fragmentsCost = self.__formatFragmentsCost(
         intelligenceCost=intelligenceCost,
         intelligenceIcon=intelligenceIcon,
         nationalsCost=nationalsCost)
     discount = bpRequester.getBlueprintDiscount(item.intCD, item.level)
     fragmentsProgress = self.__formatFragmentProgress(
         current, total, discount)
     image = func_utils.makeFlashPath(
         item.getShopIcon(STORE_CONSTANTS.ICON_SIZE_SMALL))
     return {
         'id':
         item.intCD,
         'title':
         name,
         'description':
         description,
         'image':
         image,
         'imageAlt':
         RES_SHOP.getVehicleIcon(STORE_CONSTANTS.ICON_SIZE_SMALL,
                                 'empty_tank'),
         'fragmentsCost':
         fragmentsCost,
         'intelligenceCostText':
         intelligenceCostText,
         'fragmentsProgress':
         fragmentsProgress,
         'hasDiscount':
         discount > 0,
         'availableToUnlock':
         availableToUnlock,
         'convertAvailable':
         availableCount > 0,
         'contextMenuId':
         CONTEXT_MENU_HANDLER_TYPE.STORAGE_BLUEPRINTS_ITEM
     }