Beispiel #1
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
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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']
            if self.hasInvItem(nodeCD):
                state = NODE_STATE.addIfNot(state, NODE_STATE.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_MONEY)
                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.CAN_SELL)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.SELECTED)
                if self._canBuy(nodeCD):
                    state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_MONEY)
                else:
                    state = NODE_STATE.removeIfHas(state,
                                                   NODE_STATE.ENOUGH_MONEY)
            node['state'] = state
            result.append((nodeCD, state, self.getItem(nodeCD).pack()))

        return result
Beispiel #6
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']
            if self.hasInvItem(nodeCD):
                state = NODE_STATE.addIfNot(state, NODE_STATE.IN_INVENTORY)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_MONEY)
                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.CAN_SELL)
                state = NODE_STATE.removeIfHas(state, NODE_STATE.SELECTED)
                if self._canBuy(nodeCD):
                    state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_MONEY)
                else:
                    state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_MONEY)
            node['state'] = state
            result.append((nodeCD, state, self.getItem(nodeCD).pack()))

        return result
Beispiel #7
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
Beispiel #8
0
    def _changeNext2Unlock(self, nodeCD, unlockProps):
        state = NODE_STATE.NEXT_2_UNLOCK
        totalXP = max(self._accFreeXP, 0) + self._xps.get(unlockProps.parentID, 0)
        if totalXP >= unlockProps.xpCost:
            state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
        else:
            state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
        if nodeCD in self._elite:
            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
Beispiel #9
0
    def _changeNext2Unlock(self, nodeCD, unlockProps):
        state = NODE_STATE.NEXT_2_UNLOCK
        totalXP = max(self._accFreeXP, 0) + self._xps.get(
            unlockProps.parentID, 0)
        if totalXP >= unlockProps.xpCost:
            state = NODE_STATE.addIfNot(state, NODE_STATE.ENOUGH_XP)
        else:
            state = NODE_STATE.removeIfHas(state, NODE_STATE.ENOUGH_XP)
        if nodeCD in self._elite:
            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
Beispiel #10
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
Beispiel #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)
     return state
Beispiel #12
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