def _loadItems(self, rootItem, unlockStats): itemGetter = self.getItem rootCD = rootItem.intCD maxPath = 0 nodes_ = [] for unlockIdx, xpCost, nodeCD, required in self._getRootUnlocksDescrs( rootItem): itemTypeID = getTypeOfCD(nodeCD) required.add(rootCD) path = required.copy() path = self.__fixPath(itemTypeID, path) maxPath = max(len(path), maxPath) nodes_.append((nodeCD, itemTypeID, UnlockProps(rootCD, unlockIdx, xpCost, required), path)) for nodeCD, itemTypeID, unlockProps, path in nodes_: node = self._getNodeData(nodeCD, rootItem, itemGetter(nodeCD), unlockStats, unlockProps, path, level=self.__fixLevel( itemTypeID, path, maxPath)) self._addNode(nodeCD, node)
def invalidateUnlocks(self, unlocks): """ Update status of nodes that became available to unlock or unlock after unlocks items (modules, vehicles). :param unlocks: set(<int:item compact descriptor>, ...) :return: tuple( <list of next to unlock>, <list of unlocked vehicles> ), where: list of next to unlock - [( <int:vehicle compact descriptor>, <new state>, <instance of UnlockProps> ), ... ] list of unlocked vehicles - [( <int:vehicle compact descriptor>, <new state>, ), ... ] """ next2Unlock = [] unlocked = [] unlockStats = self.getUnlockStats() items = g_techTreeDP.getNext2UnlockByItems(unlocks, **unlockStats._asdict()) if len(items): next2Unlock = map(lambda item: (item[0], self._changeNext2Unlock(item[0], item[1], unlockStats), item[1]._makeTuple()), items.iteritems()) filtered = filter(lambda unlock: getTypeOfCD(unlock) == GUI_ITEM_TYPE.VEHICLE, unlocks) if len(filtered): unlocked = map(lambda item: (item, self._change2UnlockedByCD(item)), filtered) return (next2Unlock, unlocked)
def _canSell(self, nodeCD): item = self.getItem(nodeCD) if getTypeOfCD(nodeCD) == GUI_ITEM_TYPE.VEHICLE: canSell = item.canSell else: canSell = item.isInInventory return canSell
def _loadItems(self, rootItem, unlockStats): itemGetter = self.getItem rootCD = rootItem.intCD maxPath = 0 nodes_ = [] for unlockIdx, oldCost, nodeCD, required in self._getRootUnlocksDescrs( rootItem): itemTypeID = getTypeOfCD(nodeCD) required.add(rootCD) path = required.copy() path = self.__fixPath(itemTypeID, path) maxPath = max(len(path), maxPath) xpCost = oldCost discount = 0 if itemTypeID == GUI_ITEM_TYPE.VEHICLE: item = self.getItem(nodeCD) xpCost, discount = self._getNewCost(nodeCD, item.level, oldCost) nodes_.append((nodeCD, itemTypeID, UnlockProps(rootCD, unlockIdx, xpCost, required, discount, oldCost), path)) for nodeCD, itemTypeID, unlockProps, path in nodes_: node = self._getNodeData(nodeCD, rootItem, itemGetter(nodeCD), unlockStats, unlockProps, path, level=self.__fixLevel( itemTypeID, path, maxPath)) self._addNode(nodeCD, node)
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 _loadItems(self, rootItem, unlockStats): """ Third, loads research items. :param rootItem: instance of gui item for root. @see gui.shared.gui_items. :param unlockStats: instance of unlockStats. """ itemGetter = self.getItem rootCD = rootItem.intCD maxPath = 0 nodes = [] for unlockIdx, xpCost, nodeCD, required in self._getRootUnlocksDescrs( rootItem): itemTypeID = getTypeOfCD(nodeCD) required.add(rootCD) path = required.copy() path = self.__fixPath(itemTypeID, path) maxPath = max(len(path), maxPath) nodes.append((nodeCD, itemTypeID, UnlockProps(rootCD, unlockIdx, xpCost, required), path)) for nodeCD, itemTypeID, unlockProps, path in nodes: node = self._getNodeData(nodeCD, rootItem, itemGetter(nodeCD), unlockStats, unlockProps, path, level=self.__fixLevel( itemTypeID, path, maxPath)) self._addNode(nodeCD, node)
def _mayObtainForMoney(self, nodeCD): result = False if getTypeOfCD( nodeCD) == GUI_ITEM_TYPE.VEHICLE or self.isInstallItemsEnabled( ): result = super(ResearchItemsData, self)._mayObtainForMoney(nodeCD) return result
def invalidateUnlocks(self, unlocks): """ Update status of nodes that became available to unlock or unlock after unlocks items (modules, vehicles). :param unlocks: set(<int:item compact descriptor>, ...) :return: tuple( <list of next to unlock>, <list of unlocked vehicles> ), where: list of next to unlock - [( <int:vehicle compact descriptor>, <new state>, <instance of UnlockProps> ), ... ] list of unlocked vehicles - [( <int:vehicle compact descriptor>, <new state>, ), ... ] """ next2Unlock = [] unlocked = [] unlockStats = self.getUnlockStats() items = g_techTreeDP.getNext2UnlockByItems(unlocks, **unlockStats._asdict()) if len(items): next2Unlock = map( lambda item: (item[0], self._changeNext2Unlock(item[0], item[1], unlockStats ), item[1]._makeTuple()), items.iteritems()) filtered = filter( lambda unlock: getTypeOfCD(unlock) == GUI_ITEM_TYPE.VEHICLE, unlocks) if len(filtered): unlocked = map( lambda item: (item, self._change2UnlockedByCD(item)), filtered) return (next2Unlock, unlocked)
def getVehicleCDs(self): """ :return: list with vehicle compact descriptors """ return [ i['id'] for i in self._getNodesToInvalidate() if getTypeOfCD(i['id']) == GUI_ITEM_TYPE.VEHICLE ]
def _canSell(self, nodeCD): item = self.getItem(nodeCD) if item.isInInventory: if getTypeOfCD(nodeCD) == GUI_ITEM_TYPE.VEHICLE: canSell = item.canSell else: canSell = item.isInstalled(self.getRootItem()) else: canSell = False return canSell
def _mayObtainForMoney(self, nodeCD): """ Can player buy item by nodeCD. :param nodeCD: int-type compact descriptor. :return: bool. """ result = False if getTypeOfCD(nodeCD) == GUI_ITEM_TYPE.VEHICLE or self.isInstallItemsEnabled(): result = super(ResearchItemsData, self)._mayObtainForMoney(nodeCD) return result
def invalidateUnlocks(self, unlocks): next2Unlock = [] unlocked = [] unlockStats = self.getUnlockStats() items = g_techTreeDP.getNext2UnlockByItems(unlocks, **unlockStats._asdict()) if items: next2Unlock = map(lambda item: (item[0], self._changeNext2Unlock(item[0], item[1], unlockStats), item[1].makeTuple()), items.iteritems()) filtered = [ unlock for unlock in unlocks if getTypeOfCD(unlock) == GUI_ITEM_TYPE.VEHICLE ] if filtered: unlocked = [ (item, self._change2UnlockedByCD(item)) for item in filtered ] return (next2Unlock, unlocked)
def _mayObtainForMoney(self, nodeCD): """ Can player buy item by nodeCD. :param nodeCD: int-type compact descriptor. :return: bool. """ result = False if getTypeOfCD( nodeCD) == GUI_ITEM_TYPE.VEHICLE or self.isInstallItemsEnabled( ): result = super(ResearchItemsData, self)._mayObtainForMoney(nodeCD) return result
def _canSell(self, nodeCD): """ Can player sell item by nodeCD. :param nodeCD: int-type compact descriptor. :return: bool. """ item = self.getItem(nodeCD) if item.isInInventory: if getTypeOfCD(nodeCD) == GUI_ITEM_TYPE.VEHICLE: canSell = item.canSell else: canSell = item.isInstalled(self.getRootItem()) else: canSell = False return canSell
def invalidatePrbState(self): nodes_ = self._getNodesToInvalidate() canChanged = self._isVehicleCanBeChanged() result = [] for node in nodes_: nodeCD = node.getNodeCD() state = node.getState() 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.setState(state) result.append((nodeCD, state)) return result
def invalidateHovered(self, nodeCD): result = [] if nodeCD == -1: for node in self._nodes: nodeCD = node.getNodeCD() state = node.getState() state = NODE_STATE.remove(state, NODE_STATE_FLAGS.DASHED) if state > -1: node.setState(state) result.append((nodeCD, state)) _logger.debug( '[ModuleDependencies] nodes with "dashed" state cleared: %s', result) else: conflicted = self._moduleInstaller.updateConflicted( nodeCD, self.getRootItem()) moduleDependencies = [ moduleCD for moduleTypes in conflicted for moduleCD in moduleTypes ] _logger.debug( '[ModuleDependencies] nodeCD = %s, module dependencies %s', nodeCD, moduleDependencies) for node in self._nodes: nodeCD = node.getNodeCD() if nodeCD not in moduleDependencies or getTypeOfCD( nodeCD) not in GUI_ITEM_TYPE.VEHICLE_MODULES: continue state = node.getState() state = NODE_STATE.add(state, NODE_STATE_FLAGS.DASHED) if state > -1: node.setState(state) result.append((node.getNodeCD(), state)) self._moduleInstaller.clearConflictedModules() _logger.debug( '[ModuleDependencies] nodes with "dashed" state set: %s', result) return result
def invalidateUnlocks(self, unlocks): next2Unlock = [] unlocked = [] prevUnlocked = [] unlockStats = self.getUnlockStats() items = g_techTreeDP.getNext2UnlockByItems(unlocks, **unlockStats._asdict()) if items: next2Unlock = [(item[0], self._changeNext2Unlock(item[0], item[1], unlockStats), item[1].makeTuple()) for item in items.iteritems()] filtered = [ unlock for unlock in unlocks if getTypeOfCD(unlock) == GUI_ITEM_TYPE.VEHICLE ] if filtered: unlocked = [(item, self._change2UnlockedByCD(item)) for item in filtered] parents = map(g_techTreeDP.getTopLevel, filtered) prevUnlocked = [(item, self._changePreviouslyUnlockedByCD(item)) for item in chain(*parents)] return (next2Unlock, unlocked, prevUnlocked)
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 _loadItems(self, rootItem, unlockStats): """ Third, loads research items. :param rootItem: instance of gui item for root. @see gui.shared.gui_items. :param unlockStats: instance of unlockStats. """ itemGetter = self.getItem rootCD = rootItem.intCD maxPath = 0 nodes = [] for unlockIdx, xpCost, nodeCD, required in self._getRootUnlocksDescrs(rootItem): itemTypeID = getTypeOfCD(nodeCD) required.add(rootCD) path = required.copy() path = self.__fixPath(itemTypeID, path) maxPath = max(len(path), maxPath) nodes.append((nodeCD, itemTypeID, UnlockProps(rootCD, unlockIdx, xpCost, required), path)) for nodeCD, itemTypeID, unlockProps, path in nodes: node = self._getNodeData(nodeCD, rootItem, itemGetter(nodeCD), unlockStats, unlockProps, path, level=self.__fixLevel(itemTypeID, path, maxPath)) self._addNode(nodeCD, node)
def getVehicleCDs(self): return [ i.getNodeCD() for i in self._getNodesToInvalidate() if getTypeOfCD(i.getNodeCD()) == GUI_ITEM_TYPE.VEHICLE ]