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
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
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
def _generateOptions(self): 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
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
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
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 _invalidateMoney(self, nodes): result = [] for node in nodes: state = node['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 > -1: node['state'] = state result.append((node['id'], state)) return result
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
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
def _invalidateXP(self, nodes): result = [] xpGetter = self._xps.get freeXP = max(self._accFreeXP, 0) for node in nodes: state = node['state'] props = node['unlockProps'] xp = xpGetter(props.parentID, 0) if freeXP + xp >= 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
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
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
def invalidateInstalled(self): self.__loadInstalledItems(self._rootCD) nodes = self._getNodesToInvalidate() result = [] for node in nodes: nodeCD = node['id'] state = node['state'] if nodeCD in self._installed: state = NODE_STATE.add(state, NODE_STATE.INSTALLED) else: state = NODE_STATE.remove(state, NODE_STATE.INSTALLED) if nodeCD in self._elite: state = NODE_STATE.add(state, NODE_STATE.ELITE) if state > -1: node['state'] = state result.append((nodeCD, state, self.getItem(nodeCD).pack())) return result
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 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
def _generateOptions(self): 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
def invalidateCredits(self, accCredits): self._accCredits = accCredits return self._invalidateMoney(filter(lambda item: NODE_STATE.isBuyForCredits(item['state']), self._getNodesToInvalidate()))
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
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
def invalidateCredits(self, accCredits): self._accCredits = accCredits return self._invalidateMoney( filter(lambda item: NODE_STATE.isBuyForCredits(item['state']), self._getNodesToInvalidate()))
def invalidateGold(self, gold): self._accGold = gold return self._invalidateMoney( filter(lambda item: NODE_STATE.isBuyForGold(item['state']), self._getNodesToInvalidate()))
def _isAvailable2Buy(self): return not NODE_STATE.isInstalled(self._nodeState) and NODE_STATE.isAvailable2Buy(self._nodeState) and self._canInstallItems()
def invalidateGold(self): return self._invalidateMoney(filter(lambda item: NODE_STATE.isBuyForGold(item['state']), self._getNodesToInvalidate()))