Example #1
0
 def __getDiscountBannerStr(self, root, rootNode):
     htmlStr = ''
     nodeState = rootNode.getState()
     if NODE_STATE.canTradeIn(
             nodeState
     ) and self.__tradeIn.tradeOffSelectedApplicableForLevel(root.level):
         return htmlStr
     if NODE_STATE.isRestoreAvailable(nodeState):
         restoreDueDate = getDueDateOrTimeStr(
             rootNode.getRestoreFinishTime())
         if restoreDueDate:
             return _BANNER_GETTERS[States.RESTORE](restoreDueDate)
     if not root.isUnlocked and not root.isCollectible:
         unlockDiscount = self._itemsCache.items.blueprints.getBlueprintDiscount(
             root.intCD, root.level)
         if unlockDiscount > 0:
             return _BANNER_GETTERS[States.UNLOCKED](unlockDiscount)
     if root.isRented:
         discount = rootNode.getActionDiscount()
         if discount != 0:
             return _BANNER_GETTERS[States.RENT](discount)
     if not NODE_STATE.inInventory(nodeState) and NODE_STATE.isActionVehicle(
             nodeState) or NODE_STATE.isCollectibleActionVehicle(nodeState):
         discount, isPersonalDiscount = rootNode.getActionDetails()
         if discount != 0:
             actionDueDate = '' if isPersonalDiscount else getDueDateOrTimeStr(
                 rootNode.getActionFinishTime(), isShortDateFormat=True)
             return _BANNER_GETTERS[States.ACTION](discount, actionDueDate)
     return htmlStr
Example #2
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
Example #3
0
 def _checkExpiredRent(self, state, item):
     state = NODE_STATE.addIfNot(state, NODE_STATE.VEHICLE_IN_RENT)
     if item.rentalIsOver:
         state = NODE_STATE.removeIfHas(state, NODE_STATE.IN_INVENTORY)
         state = NODE_STATE.removeIfHas(state, NODE_STATE.VEHICLE_IN_RENT)
         state |= NODE_STATE.VEHICLE_RENTAL_IS_OVER
     return state
Example #4
0
def _checkCollectibleEnabled(state, lobbyContext=None):
    if lobbyContext.getServerSettings().isCollectorVehicleEnabled():
        state = NODE_STATE.removeIfHas(state,
                                       NODE_STATE_FLAGS.PURCHASE_DISABLED)
    else:
        state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.PURCHASE_DISABLED)
    return state
 def _generateOptions(self, ctx = None):
     vehicle = self.itemsCache.items.getItemByCD(self._nodeCD)
     options = [self._makeItem(VEHICLE.INFO, MENU.CONTEXTMENU_VEHICLEINFOEX)]
     if vehicle.isPreviewAllowed():
         options.append(self._makeItem(VEHICLE.PREVIEW, MENU.CONTEXTMENU_SHOWVEHICLEPREVIEW))
     if NODE_STATE.isWasInBattle(self._nodeState):
         options.append(self._makeItem(VEHICLE.STATS, MENU.CONTEXTMENU_SHOWVEHICLESTATISTICS))
     self._manageVehCompareItem(options, vehicle)
     options.append(self._makeSeparator())
     if vehicle.isUnlocked:
         if not vehicle.isPremiumIGR and (not vehicle.isInInventory or vehicle.isRented):
             if vehicle.isRestoreAvailable():
                 label = MENU.CONTEXTMENU_RESTORE
             elif vehicle.canTradeIn:
                 label = MENU.CONTEXTMENU_BUYORTRADEIN
             else:
                 label = MENU.CONTEXTMENU_BUY
             options.append(self._makeItem(VEHICLE.BUY, label, {'enabled': NODE_STATE.isAvailable2Buy(self._nodeState)}))
     else:
         options.append(self._makeItem(VEHICLE.UNLOCK, MENU.CONTEXTMENU_UNLOCK, {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState) and not NODE_STATE.isPremium(self._nodeState)}))
     if not vehicle.isPremiumIGR:
         isAvailable2SellOrRemove = NODE_STATE.isAvailable2Sell(self._nodeState)
         if isAvailable2SellOrRemove:
             options.append(self._makeItem(VEHICLE.SELL, MENU.CONTEXTMENU_VEHICLEREMOVE if vehicle.isRented else MENU.CONTEXTMENU_SELL, {'enabled': isAvailable2SellOrRemove}))
     options.extend([self._makeSeparator(), self._makeItem(VEHICLE.SELECT, MENU.CONTEXTMENU_SELECTVEHICLEINHANGAR, {'enabled': (NODE_STATE.inInventory(self._nodeState) or NODE_STATE.isRentalOver(self._nodeState)) and NODE_STATE.isVehicleCanBeChanged(self._nodeState)})])
     return options
Example #6
0
    def invalidatePrbState(self):
        """
        Finds vehicles that is in inventory,
        :return: [(<int:vehicle compact descriptor>, <new state>), ... ].
        """
        nodes = self._getNodesToInvalidate()
        canChanged = self._isVehicleCanBeChanged()
        result = []
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            if getTypeOfCD(nodeCD) == GUI_ITEM_TYPE.VEHICLE:
                item = self.getItem(nodeCD)
                if not item.isInInventory:
                    continue
                if canChanged:
                    state = NODE_STATE.addIfNot(
                        state, NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED)
                else:
                    state = NODE_STATE.removeIfHas(
                        state, NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED)
                if state > -1:
                    node['state'] = state
                    result.append((nodeCD, state))

        return result
Example #7
0
 def _checkCollectibleActionState(self, state, item):
     state = NODE_STATE.removeIfHas(state,
                                    NODE_STATE_FLAGS.COLLECTIBLE_ACTION)
     if item.buyPrices.itemPrice.isActionPrice():
         state = NODE_STATE.addIfNot(state,
                                     NODE_STATE_FLAGS.COLLECTIBLE_ACTION)
     return state
Example #8
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
Example #9
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
Example #10
0
    def getNationTreeData(self, nationName):
        data = super(BCTechTree,
                     self).getNationTreeData(NATION_NAMES[g_bootcamp.nation])
        dataNodes = data.get('nodes', None)
        nationData = g_bootcamp.getNationData()
        if dataNodes is not None:
            dataNodes = [
                node for node in dataNodes
                if not NODE_STATE.isPremium(node['state'])
            ]
            for node in dataNodes:
                if 'vehCompareTreeNodeData' in node:
                    node['vehCompareTreeNodeData']['modeAvailable'] = False
                nodeState = node['state']
                if not NODE_STATE.inInventory(nodeState):
                    isUnlocked = NODE_STATE.isUnlocked(nodeState)
                    isVehicleSecond = node['id'] == nationData[
                        'vehicle_second']
                    if not (isVehicleSecond and isUnlocked):
                        node['state'] = NODE_STATE_FLAGS.LOCKED
                    if isUnlocked:
                        node['state'] |= NODE_STATE_FLAGS.PURCHASE_DISABLED
                    if isVehicleSecond:
                        node['state'] |= NODE_STATE_FLAGS.NEXT_2_UNLOCK
                    if NODE_STATE.isAnnouncement(nodeState):
                        node['state'] |= NODE_STATE_FLAGS.ANNOUNCEMENT
                        node['state'] |= NODE_STATE_FLAGS.NOT_CLICKABLE

            data['nodes'] = dataNodes
        return data
Example #11
0
 def _checkExpiredRent(self, state, item):
     state = NODE_STATE.addIfNot(state, NODE_STATE.VEHICLE_IN_RENT)
     if item.rentalIsOver:
         state = NODE_STATE.removeIfHas(state, NODE_STATE.IN_INVENTORY)
         state = NODE_STATE.removeIfHas(state, NODE_STATE.VEHICLE_IN_RENT)
         state |= NODE_STATE.VEHICLE_RENTAL_IS_OVER
     return state
Example #12
0
 def _checkRestoreState(self, state, item):
     state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.RESTORE_AVAILABLE)
     money = self._stats.money
     exchangeRate = self._items.shop.exchangeRate
     mayRent, rentReason = item.mayRent(money)
     if item.isRestoreAvailable():
         if item.mayRestoreWithExchange(money, exchangeRate) or not mayRent:
             state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.RESTORE_AVAILABLE)
     return state
def interceptSetResearchButton(self, nation, data):
    data = self._data.dump()
    state = data['nodes'][0]['state']
    if (state & NODE_STATE_FLAGS.LOCKED > 0):
        state = NODE_STATE.remove(state, NODE_STATE_FLAGS.LOCKED)
        state = NODE_STATE.add(state, NODE_STATE_FLAGS.NEXT_2_UNLOCK)
        state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_XP)
        data['nodes'][0]['state'] = state
    origSetItems(self, nation, data)
 def _addTopNode(self, nodeCD, node):
     state = node.getState()
     if self.__overrideResearch:
         if not NODE_STATE.inInventory(state):
             state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.NOT_CLICKABLE)
     if nodeCD != self.__firstVehicleNode:
         state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.LOCKED)
     node.setState(state)
     return super(BCResearchItemsData, self)._addTopNode(nodeCD, node)
Example #15
0
 def _checkRestoreState(self, state, item):
     state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.RESTORE_AVAILABLE)
     money = self._stats.money
     exchangeRate = self._items.shop.exchangeRate
     mayRent, _ = item.mayRent(money)
     if item.isRestoreAvailable():
         if item.mayRestoreWithExchange(money, exchangeRate) or not mayRent:
             state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.RESTORE_AVAILABLE)
     return state
 def _generateOptions(self, ctx = None):
     options = [self._makeItem(MODULE.INFO, MENU.contextmenu(MODULE.INFO)), self._makeSeparator(), self._makeItem(MODULE.UNLOCK, MENU.contextmenu(MODULE.UNLOCK), {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState)})]
     if NODE_STATE.isUnlocked(self._nodeState):
         if NODE_STATE.inInventory(self._nodeState) or NODE_STATE.isInstalled(self._nodeState):
             options.extend([self._makeItem(MODULE.EQUIP, MENU.contextmenu(MODULE.EQUIP), {'enabled': self._isAvailable2Install()}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': not NODE_STATE.isInstalled(self._nodeState)})])
         else:
             options.extend([self._makeItem(MODULE.BUY_AND_EQUIP, MENU.CONTEXTMENU_BUYANDEQUIP, {'enabled': self._isAvailable2Buy()}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': NODE_STATE.isAvailable2Sell(self._nodeState)})])
     else:
         options.extend([self._makeItem(MODULE.BUY_AND_EQUIP, MENU.CONTEXTMENU_BUYANDEQUIP, {'enabled': False}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': False})])
     return options
Example #17
0
 def _checkTechTreeEvents(self, state, guiItem, unlockProps):
     if g_techTreeDP.techTreeEventsListener.hasActiveAction(
             guiItem.intCD) and guiItem.itemTypeID == GUI_ITEM_TYPE.VEHICLE:
         state |= NODE_STATE_FLAGS.HAS_TECH_TREE_EVENT
         NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ACTION)
         noUnlockDiscount = not unlockProps or not unlockProps.discount
         if noUnlockDiscount and guiItem.buyPrices.itemPrice.isActionPrice(
         ) and not guiItem.isRestorePossible():
             NODE_STATE.add(state, NODE_STATE_FLAGS.ACTION)
     return state
Example #18
0
 def _checkTradeInState(self, state, item):
     if item.itemTypeID != GUI_ITEM_TYPE.VEHICLE:
         return state
     state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.CAN_TRADE_IN)
     if item.canTradeIn:
         state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.CAN_TRADE_IN)
     state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.CAN_TRADE_OFF)
     if item.canTradeOff:
         state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.CAN_TRADE_OFF)
     return state
 def _generateOptions(self, ctx = None):
     options = [self._makeItem(MODULE.INFO, MENU.contextmenu(MODULE.INFO)), self._makeSeparator(), self._makeItem(MODULE.UNLOCK, MENU.contextmenu(MODULE.UNLOCK), {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState)})]
     if NODE_STATE.isUnlocked(self._nodeState):
         if NODE_STATE.inInventory(self._nodeState) or NODE_STATE.isInstalled(self._nodeState):
             options.extend([self._makeItem(MODULE.EQUIP, MENU.contextmenu(MODULE.EQUIP), {'enabled': self._isAvailable2Install()}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': not NODE_STATE.isInstalled(self._nodeState)})])
         else:
             options.extend([self._makeItem(MODULE.BUY_AND_EQUIP, MENU.CONTEXTMENU_BUYANDEQUIP, {'enabled': self._isAvailable2Buy()}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': NODE_STATE.isAvailable2Sell(self._nodeState)})])
     else:
         options.extend([self._makeItem(MODULE.BUY_AND_EQUIP, MENU.CONTEXTMENU_BUYANDEQUIP, {'enabled': False}), self._makeSeparator(), self._makeItem(MODULE.SELL, MENU.CONTEXTMENU_SELLFROMINVENTORY, {'enabled': False})])
     return options
Example #20
0
    def invalidateInventory(self, nodeCDs):
        result = []
        nodes_ = filter(lambda node: node.getNodeCD() in nodeCDs, self._getNodesToInvalidate())
        for node in nodes_:
            nodeCD = node.getNodeCD()
            state = node.getState()
            item = self.getItem(nodeCD)
            if item.isInInventory:
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
                state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.VEHICLE_IN_RENT)
                if item.isRented and not item.isPremiumIGR:
                    state = self._checkExpiredRent(state, item)
                    state = self._checkMoney(state, nodeCD)
                if self._canSell(nodeCD):
                    state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.CAN_SELL)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.CAN_SELL)
            else:
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.VEHICLE_IN_RENT)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.CAN_SELL)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.SELECTED)
                state = self._checkMoney(state, nodeCD)
            state = self._checkRestoreState(state, item)
            state = self._checkRentableState(state, item)
            state = self._checkTradeInState(state, item)
            node.setState(state)
            result.append((nodeCD, state))

        return result
Example #21
0
    def invalidateInventory(self, nodeCDs):
        result = []
        nodes = filter(lambda node: node['id'] in nodeCDs,
                       self._getNodesToInvalidate())
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            item = self.getItem(nodeCD)
            if item.isInInventory:
                state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_MONEY)
                state = NODE_STATE.addIfNot(state, NODE_STATE.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state,
                                               NODE_STATE.VEHICLE_IN_RENT)
                if item.isRented and not item.isPremiumIGR:
                    state = self._checkExpiredRent(state, item)
                    state = self._checkMoneyForRentOrBuy(state, nodeCD)
                if self._canSell(nodeCD):
                    state = NODE_STATE.addIfNot(state, NODE_STATE.CAN_SELL)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.CAN_SELL)
            else:
                state = NODE_STATE.removeIfHas(state, NODE_STATE.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state,
                                               NODE_STATE.VEHICLE_IN_RENT)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.CAN_SELL)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.SELECTED)
                state = self._checkMoneyForRentOrBuy(state, nodeCD)
            node['state'] = state
            result.append((nodeCD, state))

        return result
Example #22
0
    def invalidateInventory(self, nodeCDs):
        result = []
        nodes = filter(lambda node: node['id'] in nodeCDs, self._getNodesToInvalidate())
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            item = self.getItem(nodeCD)
            if item.isInInventory:
                state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_MONEY)
                state = NODE_STATE.addIfNot(state, NODE_STATE.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.VEHICLE_IN_RENT)
                if item.isRented and not item.isPremiumIGR:
                    state = self._checkExpiredRent(state, item)
                    state = self._checkMoneyForRentOrBuy(state, nodeCD)
                if self._canSell(nodeCD):
                    state = NODE_STATE.addIfNot(state, NODE_STATE.CAN_SELL)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.CAN_SELL)
            else:
                state = NODE_STATE.removeIfHas(state, NODE_STATE.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.VEHICLE_IN_RENT)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.CAN_SELL)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.SELECTED)
                state = self._checkMoneyForRentOrBuy(state, nodeCD)
            node['state'] = state
            result.append((nodeCD, state))

        return result
Example #23
0
    def invalidateInventory(self, nodeCDs):
        """
        Updates states of nodes that have been purchased.
        :param nodeCDs: list(<int:item compact descriptor>, ...).
        :return: [(<int:vehicle compact descriptor>, <new state>), ... ].
        """
        result = []
        nodes = filter(lambda node: node['id'] in nodeCDs, self._getNodesToInvalidate())
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            item = self.getItem(nodeCD)
            if item.isInInventory:
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
                state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.VEHICLE_IN_RENT)
                if item.isRented and not item.isPremiumIGR:
                    state = self._checkExpiredRent(state, item)
                    state = self._checkMoney(state, nodeCD)
                if self._canSell(nodeCD):
                    state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.CAN_SELL)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.CAN_SELL)
            else:
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.VEHICLE_IN_RENT)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.CAN_SELL)
                state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.SELECTED)
                state = self._checkMoney(state, nodeCD)
            state = self._checkRestoreState(state, item)
            state = self._checkRentableState(state, item)
            node['state'] = state
            result.append((nodeCD, state))

        return result
Example #24
0
 def _addTopNode(self, nodeCD, node):
     state = node['state']
     if self.__overrideResearch:
         if not NODE_STATE.inInventory(state):
             state = NODE_STATE.addIfNot(state,
                                         NODE_STATE_FLAGS.NOT_CLICKABLE)
             state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ELITE)
     if nodeCD != self.__firstVehicleNode:
         state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.LOCKED)
     node['state'] = state
     return super(BCResearchItemsData, self)._addTopNode(nodeCD, node)
Example #25
0
 def _change2Unlocked(self, node):
     state = NODE_STATE.change2Unlocked(node['state'])
     if state < 0:
         return node['state']
     node['state'] = state
     if self._canBuy(node['id']):
         state = NODE_STATE.add(state, NODE_STATE.ENOUGH_MONEY)
     else:
         state = NODE_STATE.remove(state, NODE_STATE.ENOUGH_MONEY)
     if state < 0:
         return node['state']
     node['state'] = state
     return state
 def _change2Unlocked(self, node):
     state = NODE_STATE.change2Unlocked(node.getState())
     if state < 0:
         return node.getState()
     node.setState(state)
     if self._mayObtainForMoney(node.getNodeCD()):
         state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
     else:
         state = NODE_STATE.remove(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
     if state < 0:
         return node.getState()
     node.setState(state)
     return state
Example #27
0
 def _change2Unlocked(self, node):
     state = NODE_STATE.change2Unlocked(node['state'])
     if state < 0:
         return node['state']
     node['state'] = state
     if self._canBuy(node['id']):
         state = NODE_STATE.add(state, NODE_STATE.ENOUGH_MONEY)
     else:
         state = NODE_STATE.remove(state, NODE_STATE.ENOUGH_MONEY)
     if state < 0:
         return node['state']
     node['state'] = state
     return state
Example #28
0
    def _invalidateMoney(self, nodes):
        result = []
        for node in nodes:
            state = node['state']
            nodeID = node['id']
            if self._canRentOrBuy(nodeID):
                state = NODE_STATE.add(state, NODE_STATE.ENOUGH_MONEY)
            else:
                state = NODE_STATE.remove(state, NODE_STATE.ENOUGH_MONEY)
            if state > -1:
                node['state'] = state
                result.append((nodeID, state))

        return result
Example #29
0
    def _invalidateMoney(self, nodes):
        result = []
        for node in nodes:
            state = node['state']
            nodeID = node['id']
            if self._canRentOrBuy(nodeID):
                state = NODE_STATE.add(state, NODE_STATE.ENOUGH_MONEY)
            else:
                state = NODE_STATE.remove(state, NODE_STATE.ENOUGH_MONEY)
            if state > -1:
                node['state'] = state
                result.append((nodeID, state))

        return result
Example #30
0
    def _invalidateXP(self, nodes):
        result = []
        stats = self.getUnlockStats()
        for node in nodes:
            state = node['state']
            props = node['unlockProps']
            if self._getAllPossibleXP(props.parentID, stats) >= props.xpCost:
                state = NODE_STATE.add(state, NODE_STATE.ENOUGH_XP)
            else:
                state = NODE_STATE.remove(state, NODE_STATE.ENOUGH_XP)
            if state > -1:
                node['state'] = state
                result.append((node['id'], state))

        return result
Example #31
0
    def _invalidateMoney(self, nodes_):
        result = []
        for node in nodes_:
            state = node.getState()
            nodeID = node.getNodeCD()
            node.setGuiPrice(getGUIPrice(self.getItem(nodeID), self._stats.money, self._items.shop.exchangeRate))
            if canBuyGoldForItemThroughWeb(nodeID) or self._mayObtainForMoney(nodeID):
                state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
            else:
                state = NODE_STATE.remove(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
            if state > -1:
                node.setState(state)
                result.append((nodeID, state))

        return result
Example #32
0
    def _invalidateXP(self, nodes_):
        result = []
        stats = self.getUnlockStats()
        for node in nodes_:
            state = node.getState()
            props = node.getUnlockProps()
            if g_techTreeDP.getAllVehiclePossibleXP(props.parentID, stats) >= props.xpCost:
                state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_XP)
            else:
                state = NODE_STATE.remove(state, NODE_STATE_FLAGS.ENOUGH_XP)
            if state > -1:
                node.setState(state)
                result.append((node.getNodeCD(), state))

        return result
Example #33
0
    def _invalidateXP(self, nodes):
        result = []
        stats = self.getUnlockStats()
        for node in nodes:
            state = node['state']
            props = node['unlockProps']
            if self._getAllPossibleXP(props.parentID, stats) >= props.xpCost:
                state = NODE_STATE.add(state, NODE_STATE.ENOUGH_XP)
            else:
                state = NODE_STATE.remove(state, NODE_STATE.ENOUGH_XP)
            if state > -1:
                node['state'] = state
                result.append((node['id'], state))

        return result
Example #34
0
    def invalidateBlueprints(self, blueprints):
        result = []
        allNodes = self._getNodesToInvalidate()
        for node in allNodes:
            nodeCD = node.getNodeCD()
            if nodeCD not in blueprints:
                continue
            state = node.getState()
            if blueprints[nodeCD]:
                NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.BLUEPRINT)
            else:
                NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.BLUEPRINT)
            result.append((nodeCD, state))

        return result
Example #35
0
    def getNationTreeData(self, nationName):
        data = super(BCTechTree,
                     self).getNationTreeData(NATION_NAMES[g_bootcamp.nation])
        dataNodes = data.get('nodes', None)
        if dataNodes is not None:
            for node in dataNodes:
                node['state'] = NODE_STATE.removeIfHas(node['state'],
                                                       NODE_STATE_FLAGS.ELITE)
                if 'vehCompareTreeNodeData' in node:
                    node['vehCompareTreeNodeData']['modeAvailable'] = False
                if not NODE_STATE.inInventory(node['state']):
                    node['state'] = NODE_STATE_FLAGS.LOCKED

        data['nodes'][0]['displayInfo']['position'] = [16, 90]
        data['nodes'][0]['displayInfo']['lines'][0]['outPin'] = [144, 108]
        return data
Example #36
0
 def __getMainButtonLabel(self, rootItem, rootNode):
     if NODE_STATE.isCollectible(rootNode.getState()):
         btnLabel = R.strings.menu.research.labels.button.toCollection()
     elif not rootItem.isUnlocked:
         btnLabel = R.strings.menu.unlocks.unlockButton()
     elif NODE_STATE.isRestoreAvailable(rootNode.getState()):
         btnLabel = R.strings.menu.research.labels.button.restore()
     elif NODE_STATE.inInventory(rootNode.getState(
     )) and not rootItem.isRented or rootItem.isHidden:
         btnLabel = R.strings.menu.research.labels.button.showInHangar()
     elif NODE_STATE.canTradeIn(rootNode.getState(
     )) and self.__tradeIn.getActiveTradeOffVehicle() is not None:
         btnLabel = R.strings.menu.research.labels.button.trade_in()
     else:
         btnLabel = R.strings.menu.research.labels.button.buy()
     return backport.text(btnLabel)
Example #37
0
 def invalidateGold(self):
     """
     Updates states of nodes for which changed their access to buy after
     updates value of gold.
     :return: [(<int:vehicle compact descriptor>, <new state>), ... ]
     """
     return self._invalidateMoney(filter(lambda item: NODE_STATE.isBuyForGold(item['state']), self._getNodesToInvalidate()))
Example #38
0
 def _getNodesToInvalidate(self):
     toInvalidate = self._nodes[:]
     toInvalidate.extend(self._topLevel)
     return [
         node for node in toInvalidate
         if not NODE_STATE.isAnnouncement(node.getState())
     ]
Example #39
0
    def _changeNext2Unlock(self, nodeCD, unlockProps, unlockStats):
        state = NODE_STATE.NEXT_2_UNLOCK
        totalXP = self._getAllPossibleXP(unlockProps.parentID, unlockStats)
        if totalXP >= unlockProps.xpCost:
            state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
        else:
            state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
        if self.getItem(nodeCD).isElite:
            state = NODE_STATE.addIfNot(state, NODE_STATE.ELITE)
        try:
            data = self._nodes[self._nodesIdx[nodeCD]]
            data['state'] = state
            data['unlockProps'] = unlockProps
        except KeyError:
            LOG_CURRENT_EXCEPTION()

        return state
Example #40
0
    def _changeNext2Unlock(self, nodeCD, unlockProps, unlockStats):
        state = NODE_STATE.NEXT_2_UNLOCK
        totalXP = self._getAllPossibleXP(unlockProps.parentID, unlockStats)
        if totalXP >= unlockProps.xpCost:
            state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
        else:
            state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
        if self.getItem(nodeCD).isElite:
            state = NODE_STATE.addIfNot(state, NODE_STATE.ELITE)
        try:
            data = self._nodes[self._nodesIdx[nodeCD]]
            data['state'] = state
            data['unlockProps'] = unlockProps
        except KeyError:
            LOG_CURRENT_EXCEPTION()

        return state
Example #41
0
 def _generateOptions(self, ctx=None):
     options = [
         self._makeItem(VEHICLE.BLUEPRINT, MENU.CONTEXTMENU_GOTOBLUEPRINT),
         self._makeItem(
             VEHICLE.UNLOCK, MENU.CONTEXTMENU_UNLOCK,
             {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState)})
     ]
     return options
Example #42
0
    def getNationTreeData(self, nationName):
        data = super(BCTechTree, self).getNationTreeData(NATION_NAMES[g_bootcamp.nation])
        dataNodes = data.get('nodes', None)
        if dataNodes is not None:
            for node in dataNodes:
                if 'vehCompareTreeNodeData' in node:
                    node['vehCompareTreeNodeData']['modeAvailable'] = False
                nodeState = node['state']
                if not NODE_STATE.inInventory(nodeState) and not NODE_STATE.isPremium(nodeState):
                    node['state'] = NODE_STATE_FLAGS.LOCKED
                    if NODE_STATE.isAnnouncement(nodeState):
                        node['state'] |= NODE_STATE_FLAGS.ANNOUNCEMENT
                        node['state'] |= NODE_STATE_FLAGS.NOT_CLICKABLE

        data['nodes'][0]['displayInfo']['position'] = [16, 90]
        data['nodes'][0]['displayInfo']['lines'][0]['outPin'] = [144, 108]
        return data
Example #43
0
 def _change2Unlocked(self, node):
     """
     Changes state of node to 'unlocked'.
     :param node: node data.
     :return: int containing new state of node.
     """
     state = NODE_STATE.change2Unlocked(node['state'])
     if state < 0:
         return node['state']
     node['state'] = state
     if self._mayObtainForMoney(node['id']):
         state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
     else:
         state = NODE_STATE.remove(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
     if state < 0:
         return node['state']
     node['state'] = state
     return state
Example #44
0
    def invalidateInstalled(self):
        nodes = self._getNodesToInvalidate()
        rootItem = self.getRootItem()
        result = []
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            item = self.getItem(nodeCD)
            if rootItem.isInInventory and item.isInstalled(rootItem):
                state = NODE_STATE.add(state, NODE_STATE.INSTALLED)
            else:
                state = NODE_STATE.remove(state, NODE_STATE.INSTALLED)
            if item.itemTypeID == GUI_ITEM_TYPE.VEHICLE and item.isElite:
                state = NODE_STATE.add(state, NODE_STATE.ELITE)
            if state > -1:
                node['state'] = state
                result.append((nodeCD, state))

        return result
 def _generateOptions(self, ctx = None):
     vehicle = g_itemsCache.items.getItemByCD(self._nodeCD)
     options = [self._makeItem(VEHICLE.INFO, MENU.CONTEXTMENU_VEHICLEINFOEX)]
     if vehicle.isPreviewAllowed():
         options.append(self._makeItem(VEHICLE.PREVIEW, MENU.CONTEXTMENU_SHOWVEHICLEPREVIEW))
     if NODE_STATE.isWasInBattle(self._nodeState):
         options.append(self._makeItem(VEHICLE.STATS, MENU.CONTEXTMENU_SHOWVEHICLESTATISTICS))
     options.append(self._makeSeparator())
     if vehicle.isUnlocked:
         if not vehicle.isPremiumIGR and (not vehicle.isInInventory or vehicle.isRented):
             options.append(self._makeItem(VEHICLE.BUY, MENU.CONTEXTMENU_BUY, {'enabled': NODE_STATE.isAvailable2Buy(self._nodeState)}))
     else:
         options.append(self._makeItem(VEHICLE.UNLOCK, MENU.CONTEXTMENU_UNLOCK, {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState) and not NODE_STATE.isPremium(self._nodeState)}))
     if not vehicle.isPremiumIGR:
         isAvailable2SellOrRemove = NODE_STATE.isAvailable2Sell(self._nodeState)
         if isAvailable2SellOrRemove:
             options.append(self._makeItem(VEHICLE.SELL, MENU.CONTEXTMENU_VEHICLEREMOVE if vehicle.isRented else MENU.CONTEXTMENU_SELL, {'enabled': isAvailable2SellOrRemove}))
     options.extend([self._makeSeparator(), self._makeItem(VEHICLE.SELECT, MENU.CONTEXTMENU_SELECTVEHICLEINHANGAR, {'enabled': (NODE_STATE.inInventory(self._nodeState) or NODE_STATE.isRentalOver(self._nodeState)) and NODE_STATE.isVehicleCanBeChanged(self._nodeState)})])
     return options
Example #46
0
    def invalidatePrbState(self):
        nodes = self._getNodesToInvalidate()
        canChanged = self._isVehicleCanBeChanged()
        result = []
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            if getTypeOfCompactDescr(nodeCD) == GUI_ITEM_TYPE.VEHICLE:
                item = self.getItem(nodeCD)
                if not item.isInInventory:
                    continue
                if canChanged:
                    state = NODE_STATE.addIfNot(state, NODE_STATE.VEHICLE_CAN_BE_CHANGED)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.VEHICLE_CAN_BE_CHANGED)
                if state > -1:
                    node['state'] = state
                    result.append((nodeCD, state))

        return result
Example #47
0
    def _invalidateXP(self, nodes):
        """
        Updates states of nodes that have become available/unavailable for unlock.
        :param nodes: list of nodes where search changes.
        :return: list( (<node ID>, <new state>), ... ) for nodes where changed the state.
        """
        result = []
        stats = self.getUnlockStats()
        for node in nodes:
            state = node['state']
            props = node['unlockProps']
            if g_techTreeDP.getAllVehiclePossibleXP(props.parentID, stats) >= props.xpCost:
                state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_XP)
            else:
                state = NODE_STATE.remove(state, NODE_STATE_FLAGS.ENOUGH_XP)
            if state > -1:
                node['state'] = state
                result.append((node['id'], state))

        return result
Example #48
0
    def _invalidateMoney(self, nodes):
        """
        Updates states of nodes that have become available/unavailable for purchase.
        :param nodes: list of nodes where search changes.
        :return: list( (<node ID>, <new state>), ... ) for nodes where changed the state.
        """
        result = []
        for node in nodes:
            state = node['state']
            nodeID = node['id']
            node['GUIPrice'] = getGUIPrice(self.getItem(nodeID), self._stats.money, self._items.shop.exchangeRate)
            if self._mayObtainForMoney(nodeID):
                state = NODE_STATE.add(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
            else:
                state = NODE_STATE.remove(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
            if state > -1:
                node['state'] = state
                result.append((nodeID, state))

        return result
 def _generateOptions(self, ctx = None):
     vehicle = g_itemsCache.items.getItemByCD(self._nodeCD)
     options = [self._makeItem(VEHICLE.INFO, MENU.CONTEXTMENU_VEHICLEINFOEX),
      self._makeItem(VEHICLE.STATS, MENU.CONTEXTMENU_SHOWVEHICLESTATISTICS, {'enabled': NODE_STATE.isWasInBattle(self._nodeState)}),
      self._makeSeparator(),
      self._makeItem(VEHICLE.UNLOCK, MENU.CONTEXTMENU_UNLOCK, {'enabled': NODE_STATE.isAvailable2Unlock(self._nodeState) and not NODE_STATE.isPremium(self._nodeState)})]
     if not vehicle.isPremiumIGR:
         options.extend([self._makeItem(VEHICLE.BUY, MENU.CONTEXTMENU_BUY, {'enabled': NODE_STATE.isAvailable2Buy(self._nodeState)}),
          self._makeItem(VEHICLE.SELL, MENU.CONTEXTMENU_VEHICLEREMOVE if vehicle.isRented else MENU.CONTEXTMENU_SELL, {'enabled': NODE_STATE.isAvailable2Sell(self._nodeState)}),
          self._makeSeparator(),
          self._makeItem(VEHICLE.SELECT, MENU.CONTEXTMENU_SELECTVEHICLEINHANGAR, {'enabled': NODE_STATE.inInventory(self._nodeState) and NODE_STATE.isVehicleCanBeChanged(self._nodeState)})])
     return options
Example #50
0
    def invalidateInstalled(self):
        """
        Finds items that were installed/uninstalled on root vehicle.
        :return: [(<int:item compact descriptor>, <new state>), ... ].
        """
        nodes = self._getNodesToInvalidate()
        rootItem = self.getRootItem()
        result = []
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            item = self.getItem(nodeCD)
            if rootItem.isInInventory and item.isInstalled(rootItem):
                state = NODE_STATE.add(state, NODE_STATE_FLAGS.INSTALLED)
            else:
                state = NODE_STATE.remove(state, NODE_STATE_FLAGS.INSTALLED)
            if item.itemTypeID == GUI_ITEM_TYPE.VEHICLE and item.isElite:
                state = NODE_STATE.add(state, NODE_STATE_FLAGS.ELITE)
            if state > -1:
                node['state'] = state
                result.append((nodeCD, state))

        return result
Example #51
0
    def invalidatePrbState(self):
        """
        Finds vehicles that is in inventory,
        :return: [(<int:vehicle compact descriptor>, <new state>), ... ].
        """
        nodes = self._getNodesToInvalidate()
        canChanged = self._isVehicleCanBeChanged()
        result = []
        for node in nodes:
            nodeCD = node['id']
            state = node['state']
            if getTypeOfCD(nodeCD) == GUI_ITEM_TYPE.VEHICLE:
                item = self.getItem(nodeCD)
                if not item.isInInventory:
                    continue
                if canChanged:
                    state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.VEHICLE_CAN_BE_CHANGED)
                if state > -1:
                    node['state'] = state
                    result.append((nodeCD, state))

        return result
Example #52
0
 def _checkMoney(self, state, nodeCD):
     state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ENOUGH_MONEY)
     if self._mayObtainForMoney(nodeCD):
         state |= NODE_STATE_FLAGS.ENOUGH_MONEY
     return state
 def _isAvailable2Install(self):
     return (
         not NODE_STATE.isInstalled(self._nodeState)
         and NODE_STATE.inInventory(self._nodeState)
         and self._canInstallItems()
     )
 def _isAvailable2Buy(self):
     return not NODE_STATE.isInstalled(self._nodeState) and NODE_STATE.isAvailable2Buy(self._nodeState) and self._canInstallItems()
Example #55
0
 def _checkMoneyForRentOrBuy(self, state, nodeCD):
     state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_MONEY)
     if self._canRentOrBuy(nodeCD):
         state |= NODE_STATE.ENOUGH_MONEY
     return state
Example #56
0
 def invalidateGold(self):
     return self._invalidateMoney(filter(lambda item: NODE_STATE.isBuyForGold(item['state']), self._getNodesToInvalidate()))
Example #57
0
 def _checkRentableState(self, state, item):
     state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.RENT_AVAILABLE)
     if not item.isRented and item.isRentable and item.isRentAvailable:
         state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.RENT_AVAILABLE)
     return state