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 _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
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 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
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
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 _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 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 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
def updateNode(self, node): node['state'] = 0 node['state'] = NODE_STATE.addIfNot(node['state'], NODE_STATE_FLAGS.UNLOCKED)
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
def setSecondVehicleNode(self, secondVehicleNode): self.updateNode(secondVehicleNode) secondVehicleNode.setState(NODE_STATE.addIfNot(secondVehicleNode.getState(), NODE_STATE_FLAGS.WAS_IN_BATTLE))
def setModuleNode(self, moduleNode): self.__moduleNode = deepcopy(moduleNode) node = self.__moduleNode self.updateNode(node) node['state'] = NODE_STATE.addIfNot(node['state'], NODE_STATE_FLAGS.IN_INVENTORY)
def setSecondVehicleNode(self, secondVehicleNode): self.__secondVehicleNode = deepcopy(secondVehicleNode) node = self.__secondVehicleNode self.updateNode(node) node['state'] = NODE_STATE.addIfNot(node['state'], NODE_STATE_FLAGS.WAS_IN_BATTLE)
def _checkBuyingActionState(self, state, item): state = NODE_STATE.removeIfHas(state, NODE_STATE_FLAGS.ACTION) if item.buyPrices.itemPrice.isActionPrice( ) and not item.isRestorePossible(): state = NODE_STATE.addIfNot(state, NODE_STATE_FLAGS.ACTION) return state
def setModuleNode(self, moduleNode): self.updateNode(moduleNode) moduleNode.setState(NODE_STATE.addIfNot(moduleNode.getState(), NODE_STATE_FLAGS.IN_INVENTORY))