def getExtendedParameters(currModule, module, vehicle): params = [] if currModule is None: moduleDescr = _getModuleDescr(module, vehicle) currModule = _getCurrentModule(moduleDescr) typeCDCurrentModule = getTypeOfCompactDescr(currModule.intCD) typeCDNewModule = getTypeOfCompactDescr(module.intCD) difference = 0 if typeCDCurrentModule == GUI_ITEM_TYPE.CHASSIS and typeCDNewModule == GUI_ITEM_TYPE.CHASSIS: defaultHull = vehicle.typeDescr.hulls[0] newNull = [ hull for hull in vehicle.typeDescr.hulls if module.innationID in hull.variantMatch ] newNull = newNull[0] if newNull else None if newNull: difference = newNull.maxHealth - defaultHull.maxHealth elif typeCDCurrentModule == GUI_ITEM_TYPE.TURRET and typeCDNewModule == GUI_ITEM_TYPE.TURRET: difference = module.descriptor.maxHealth - currModule.descriptor.maxHealth if difference: fmtValue = params_formatters.formatParameter('maxHealth', difference, 'better', _DELTA_SCHEME, _CMP_FORMAT_SETTINGS) params.append({ 'value': str(fmtValue), 'description': params_formatters.formatVehicleParamName('increaseHealth') }) return params
def __loadItems(self, rootItem, unlockStats): itemGetter = self.getItem rootCD = rootItem.intCD maxPath = 0 nodes = [] for unlockIdx, xpCost, nodeCD, required in rootItem.getUnlocksDescrs(): itemTypeID = getTypeOfCompactDescr(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 getFormattedParamsList(descriptor, parameters, excludeRelative=False): if vehicles.isVehicleDescr(descriptor): compactDescr = descriptor.type.compactDescr else: compactDescr = descriptor.compactDescr itemTypeIdx = getTypeOfCompactDescr(compactDescr) if itemTypeIdx == ITEM_TYPES.equipment: eqDescr = vehicles.getItemByCompactDescr(compactDescr) paramsList = ITEMS_PARAMS_LIST[itemTypeIdx].get(type(eqDescr), []) else: paramsList = ITEMS_PARAMS_LIST[itemTypeIdx] params = [] for paramName in paramsList: if excludeRelative and isRelativeParameter(paramName): continue paramValue = parameters.get(paramName) if paramValue: fmtValue = formatParameter(paramName, paramValue) if fmtValue: if paramName == 'autoReloadTime' and descriptor.gun.autoreloadHasBoost: paramName = 'autoReloadTimeBoost' elif paramName == CHASSIS_REPAIR_TIME and descriptor.isTrackWithinTrack: paramName = CHASSIS_REPAIR_TIME_YOH params.append((paramName, fmtValue)) return params
def update(self, diff=None, callback=None): yield self.falloutQuestsProgress.request() yield self.randomQuestsProgress.request() yield self.__questsProgress.request() isNeedToInvalidate = True isNeedToClearItemsCaches = False def _cbWrapper(*args): self.__random.update(self, diff) self.__fallout.update(self, diff) callback(*args) if diff is not None: isQPUpdated = 'quests' in diff or 'tokens' in diff isEventsDataUpdated = ('eventsData', '_r') in diff or diff.get( 'eventsData', {}) isNeedToInvalidate = isQPUpdated or isEventsDataUpdated hasVehicleUnlocks = False for intCD in diff.get('stats', {}).get('unlocks', set()): if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE: hasVehicleUnlocks = True break isNeedToClearItemsCaches = 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff[ 'inventory'] or hasVehicleUnlocks if isNeedToInvalidate: self.__invalidateData(_cbWrapper) return else: if isNeedToClearItemsCaches: self.__clearQuestsItemsCache() _cbWrapper(True) return
def _getRootUnlocksDescrs(self, rootItem): unlockedDescrs = super(_PreviewItemsData, self)._getRootUnlocksDescrs(rootItem) for unlockIdx, xpCost, nodeCD, required in unlockedDescrs: itemTypeID = getTypeOfCompactDescr(nodeCD) if itemTypeID != GUI_ITEM_TYPE.VEHICLE: yield (unlockIdx, xpCost, nodeCD, required)
def update(self, diff = None, callback = None): yield self.__progress.request() isNeedToInvalidate = True isNeedToClearItemsCaches = False def _cbWrapper(*args): self.__potapov.update(diff) callback(*args) if diff is not None: isQPUpdated = 'quests' in diff isEventsDataUpdated = ('eventsData', '_r') in diff or 'eventsData' in diff isNeedToInvalidate = isQPUpdated or isEventsDataUpdated hasVehicleUnlocks = False for intCD in diff.get('stats', {}).get('unlocks', set()): if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE: hasVehicleUnlocks = True break isNeedToClearItemsCaches = 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff['inventory'] or hasVehicleUnlocks if isNeedToInvalidate: self.__invalidateData(_cbWrapper) return else: if isNeedToClearItemsCaches: self.__clearQuestsItemsCache() _cbWrapper(True) return
def _canBuy(self, nodeCD): result = False if getTypeOfCompactDescr( nodeCD) == GUI_ITEM_TYPE.VEHICLE or self.isInstallItemsEnabled( ): result = super(ResearchItemsData, self)._canBuy(nodeCD) return result
def __getCommonParameters(self, itemTypeCompDescr, paramsDict, excluded=tuple()): result = list() if GUI_SETTINGS.technicalInfo: compDescrType = getTypeOfCompactDescr(itemTypeCompDescr) params = self.__itemCommonParamsList.get(compDescrType, {}) if compDescrType == vehicles._EQUIPMENT: eqDescr = vehicles.getDictDescr(itemTypeCompDescr) params = params.get(type(eqDescr), []) else: params = self.__itemCommonParamsList.get(compDescrType, []) for param in params: if type(param) == str: if param not in excluded: result.append([param, paramsDict.get(param)]) else: paramName = param[0] paramValue = paramsDict.get(param[0]) formatFunc = param[1] formattedValue = formatFunc(paramValue) if formattedValue is not None and paramName not in excluded: result.append([paramName, formattedValue]) return result
def updateConflicted(self, moduleId, vehicle): moduleId = int(moduleId) self.__initConflictedList() if moduleId: module = _getModule(moduleId) isFit, reason = module.mayInstall(vehicle) if not isFit: if reason == 'need turret': turretsCDs, chassisCDs = self.__getSuitableModulesForGun(moduleId, vehicle) self.__addConflicted(GUI_ITEM_TYPE.TURRET, turretsCDs) self.__addConflicted(GUI_ITEM_TYPE.CHASSIS, chassisCDs) elif reason == 'too heavy': chassis = [] for _, _, nodeCD, _ in vehicle.getUnlocksDescrs(): itemTypeID = getTypeOfCompactDescr(nodeCD) if itemTypeID == GUI_ITEM_TYPE.CHASSIS: chassisCand = _getModule(nodeCD) if chassisCand.mayInstall(vehicle) and not chassisCand.isInstalled(vehicle): chassis.append(nodeCD) if chassis: self.__addConflicted(GUI_ITEM_TYPE.CHASSIS, chassis) elif reason == 'too heavy chassis': for i, stockCD in enumerate(self.__stockModules): if stockCD is not None and not _getModule(stockCD).isInstalled(vehicle): self.__addConflicted(GUI_ITEM_TYPE.VEHICLE_MODULES[i], (stockCD,)) elif reason == 'need gun': stockGunCD = self.__stockModules[GUI_ITEM_TYPE.VEHICLE_MODULES.index(GUI_ITEM_TYPE.GUN)] if stockGunCD is not None and not _getModule(stockGunCD).isInstalled(vehicle): self.__addConflicted(GUI_ITEM_TYPE.GUN, (stockGunCD,)) else: LOG_DEBUG('Install component. Unsupported error type: "{}"'.format(reason)) return self.__conflictedModulesCD
def update(self, diff = None, callback = None): if diff is not None: if diff.get('eventsData', {}).get(EVENT_CLIENT_DATA.INGAME_EVENTS): self.__companies.setNotificators() yield self.falloutQuestsProgress.request() yield self.randomQuestsProgress.request() yield self.__questsProgress.request() isNeedToInvalidate = True isNeedToClearItemsCaches = False def _cbWrapper(*args): self.__random.update(self, diff) self.__fallout.update(self, diff) callback(*args) if diff is not None: isQPUpdated = 'quests' in diff isEventsDataUpdated = ('eventsData', '_r') in diff or diff.get('eventsData', {}) isNeedToInvalidate = isQPUpdated or isEventsDataUpdated hasVehicleUnlocks = False for intCD in diff.get('stats', {}).get('unlocks', set()): if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE: hasVehicleUnlocks = True break isNeedToClearItemsCaches = 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff['inventory'] or hasVehicleUnlocks if isNeedToInvalidate: self.__invalidateData(_cbWrapper) return else: if isNeedToClearItemsCaches: self.__clearQuestsItemsCache() _cbWrapper(True) return
def getNext2UnlockByItems(self, itemCDs, unlocked=set(), xps=None, freeXP=0): filtered = filter(lambda item: item in self.__topItems, itemCDs) if not len(filtered) or not len(unlocked): return {} available = defaultdict(list) parentCDs = set( filter(lambda item: getTypeOfCompactDescr(item) == _VEHICLE, itemCDs)) for item in filtered: if item in unlocked: parentCDs |= self.__topItems[item] for parentCD in parentCDs: if parentCD not in unlocked: continue nextLevel = self.__nextLevels[parentCD] topIDs = set() for childCD, (idx, xpCost, required) in nextLevel.iteritems(): if childCD not in unlocked and required.issubset(unlocked): topIDs.add(parentCD) available[childCD].append( UnlockProps(parentCD, idx, xpCost, topIDs)) result = {} for childCD, compare in available.iteritems(): result[childCD] = self._findNext2Unlock(compare, xps=xps, freeXP=freeXP) return result
def update(self, diff=None, callback=None): if diff is not None: if diff.get('eventsData', {}).get(EVENT_CLIENT_DATA.INGAME_EVENTS): self.__companies.setNotificators() yield self.__progress.request() isNeedToInvalidate = True isNeedToClearItemsCaches = False def _cbWrapper(*args): self.__potapov.update(diff) callback(*args) if diff is not None: isQPUpdated = 'quests' in diff isEventsDataUpdated = ('eventsData', '_r') in diff or diff.get( 'eventsData', {}) isNeedToInvalidate = isQPUpdated or isEventsDataUpdated hasVehicleUnlocks = False for intCD in diff.get('stats', {}).get('unlocks', set()): if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE: hasVehicleUnlocks = True break isNeedToClearItemsCaches = 'inventory' in diff and GUI_ITEM_TYPE.VEHICLE in diff[ 'inventory'] or hasVehicleUnlocks if isNeedToInvalidate: self.__invalidateData(_cbWrapper) return if isNeedToClearItemsCaches: self.__clearQuestsItemsCache() _cbWrapper(True)
def getStockVehicle(self, typeCompDescr, useInventory=False): if getTypeOfCompactDescr(typeCompDescr) == GUI_ITEM_TYPE.VEHICLE: proxy = self if useInventory else None return self.itemsFactory.createVehicle(typeCompDescr=typeCompDescr, proxy=proxy) else: return
def getNext2UnlockByItems(self, itemCDs, unlocked = set(), xps = None, freeXP = 0): filtered = filter(lambda item: item in self.__topItems, itemCDs) if not len(filtered) or not len(unlocked): return {} available = defaultdict(list) parentCDs = set(filter(lambda item: getTypeOfCompactDescr(item) == _VEHICLE, itemCDs)) for item in filtered: if item in unlocked: parentCDs |= self.__topItems[item] for parentCD in parentCDs: if parentCD not in unlocked: continue nextLevel = self.__nextLevels[parentCD] topIDs = set() for childCD, (idx, xpCost, required) in nextLevel.iteritems(): if childCD not in unlocked and required.issubset(unlocked): topIDs.add(parentCD) available[childCD].append(UnlockProps(parentCD, idx, xpCost, topIDs)) result = {} for childCD, compare in available.iteritems(): result[childCD] = self._findNext2Unlock(compare, xps=xps, freeXP=freeXP) return result
def request4Restore(self, itemCD): itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_VEHICLE, itemCD, False, VehicleBuyActionTypes.RESTORE, skipConfirm=self._skipConfirm)
def request4Buy(self, itemCD): itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: self.buyVehicle(itemCD) else: if RequestState.inProcess('buyAndInstall'): SystemMessages.pushI18nMessage('#system_messages:shop/item/buy_and_equip_in_processing', type=SystemMessages.SM_TYPE.Warning) self.buyAndInstallItem(itemCD, 'buyAndInstall')
def onUnlocksChanged(self, unlocks): isChanged = False for unlock in list(unlocks): if getTypeOfCompactDescr(unlock) == ITEM_TYPE_INDICES['vehicle']: isChanged = True if isChanged: self.handle()
def _getInstalledModuleVehicle(vehicleDescr, itemDescr): curVehicle = None if vehicleDescr: compDescrType = getTypeOfCompactDescr(itemDescr.compactDescr) module = MODULES[compDescrType](vehicleDescr) if module.id[1] == itemDescr.id[1]: curVehicle = vehicleDescr.type.userString return curVehicle
def __get(self, itemDescr, vehicleDescr = None, isParameters = True, isCompatibles = True): try: compactDescr = itemDescr.type.compactDescr if isinstance(itemDescr, vehicles.VehicleDescr) else itemDescr['compactDescr'] handler = self.__itemTypeHandlers.get(getTypeOfCompactDescr(compactDescr), lambda *args: None) return handler(itemDescr, vehicleDescr, isParameters, isCompatibles) except Exception: LOG_CURRENT_EXCEPTION() return dict()
def _getInstalledModuleVehicle(vehicleDescr, itemDescr): curVehicle = None if vehicleDescr: compDescrType = getTypeOfCompactDescr(itemDescr['compactDescr']) module = MODULES[compDescrType](vehicleDescr) if module['id'][1] == itemDescr['id'][1]: curVehicle = vehicleDescr.type.userString return curVehicle
def request4Buy(self, itemCD): """ Overridden method of the class ResearchViewMeta.request4Buy. """ itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_VEHICLE, itemCD) else: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_AND_INSTALL_ITEM, itemCD, self._data.getRootCD())
def request4Buy(self, itemCD): """ Overridden method of the class ResearchViewMeta.request4Buy. """ itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_VEHICLE, itemCD, skipConfirm=self._skipConfirm) else: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_AND_INSTALL_ITEM, itemCD, self._data.getRootCD(), skipConfirm=self._skipConfirm)
def request4Buy(self, itemCD): itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_VEHICLE, itemCD) else: ItemsActionsFactory.doAction( ItemsActionsFactory.BUY_AND_INSTALL_ITEM, itemCD, self._data.getRootCD())
def isItemVehicleHull(intCD, vehicle, itemsFactory=None): typeCD = getTypeOfCompactDescr(intCD) if typeCD == GUI_ITEM_TYPE.CHASSIS: item = itemsFactory.createGuiItem(typeCD, intCompactDescr=intCD) hulls = vehicle.descriptor.type.hulls for hull in hulls: if item.innationID in hull.variantMatch: return True return False
def getSuitableChassis(vehicle, itemsCache=None): chassis = [] for _, _, nodeCD, _ in vehicle.getUnlocksDescrs(): itemTypeID = getTypeOfCompactDescr(nodeCD) if itemTypeID == GUI_ITEM_TYPE.CHASSIS: chassisCand = itemsCache.items.getItemByCD(nodeCD) if chassisCand.mayInstall(vehicle) and not chassisCand.isInstalled(vehicle): chassis.append(chassisCand) return chassis
def _canSell(self, nodeCD): item = self.getItem(nodeCD) if item.isInInventory: if getTypeOfCompactDescr(nodeCD) == GUI_ITEM_TYPE.VEHICLE: canSell = item.canSell else: canSell = item.isInstalled(self.getRootItem()) else: canSell = False return canSell
def _getModuleDescr(module, vehicle): vDescr = vehicle.descriptor currModuleDescr, _ = vDescr.getComponentsByType(module.itemTypeName) intCD = currModuleDescr.compactDescr typeCD = getTypeOfCompactDescr(intCD) return _ModuleDescr(vDescr=vDescr, currentModuleDescr=currModuleDescr, intCD=intCD, typeCD=typeCD, moduleParams=_getParameters(typeCD, module, vDescr))
def __installInitialModules(self): cachedModules = { getTypeOfCompactDescr(module): module for module in self.__initialModulesRecord.getModules() } for typeID, module in cachedModules.iteritems(): if typeID != GUI_ITEM_TYPE.TURRET: self.__vehicleHolder.setInitialModule(module) self.__vehicleHolder.setInitialTurret( module, cachedModules[GUI_ITEM_TYPE.GUN])
def getStockVehicle(self, typeCompDescr, useInventory=False): """ Make vehicle copy with stock configuration """ if getTypeOfCompactDescr(typeCompDescr) == GUI_ITEM_TYPE.VEHICLE: proxy = self if useInventory else None return self.itemsFactory.createVehicle(typeCompDescr=typeCompDescr, proxy=proxy) else: return
def invalidateUnlocks(self, unlocks): 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: getTypeOfCompactDescr(unlock) == GUI_ITEM_TYPE.VEHICLE, unlocks) if len(filtered): unlocked = map(lambda item: (item, self._change2UnlockedByCD(item)), filtered) return (next2Unlock, unlocked)
def __makeSimpleItem(self, typeCompDescr): itemTypeID = getTypeOfCompactDescr(typeCompDescr) cache = self.__itemsCache[itemTypeID] if typeCompDescr in cache: return cache[typeCompDescr] itemsInvData = self.getCacheValue(itemTypeID, {}) if typeCompDescr not in itemsInvData: return None data = self.ITEM_DATA(typeCompDescr, vehicles.getDictDescr(typeCompDescr), itemsInvData[typeCompDescr]) item = cache[typeCompDescr] = data return item
def createGuiItemFromCompactDescr(self, compactDescr, *args, **kwargs): """ Creates a GUI item by the item compact descriptor. :param compactDescr: item compact descriptor. :param args: args to be passed in constructor :param kwargs: kwargs to be passed in constructor :return: An instance of GUI item or None if the compactDescr is invalid. """ return self.createGuiItem(getTypeOfCompactDescr(compactDescr), *args, **kwargs)
def request4Buy(self, itemCD): itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: vehicle = self._itemsCache.items.getItemByCD(itemCD) if canBuyGoldForVehicleThroughWeb(vehicle): shared_events.showVehicleBuyDialog( vehicle, actionType=VehicleBuyActionTypes.BUY) else: self._doBuyVehicleAction(itemCD) else: self._doBuyAndInstallItemAction(itemCD)
def getItemByCD(self, typeCompDescr): """ Trying to return item from inventory by item int compact descriptor, otherwise - from shop. @param typeCompDescr: item int compact descriptor @return: item object """ if getTypeOfCompactDescr(typeCompDescr) == GUI_ITEM_TYPE.VEHICLE: return self.__makeVehicle(typeCompDescr) return self.__makeSimpleItem(typeCompDescr)
def invalidateUnlocks(self, unlocks): self._unlocks |= unlocks next2Unlock = [] unlocked = [] items = g_techTreeDP.getNext2UnlockByItems(unlocks, unlocked=self._unlocks, xps=self._xps, freeXP=max(self._accFreeXP, 0)) if len(items): next2Unlock = map(lambda item: (item[0], self._changeNext2Unlock(item[0], item[1]), item[1]._makeTuple()), items.iteritems()) filtered = filter(lambda unlock: getTypeOfCompactDescr(unlock) == _VEHICLE, unlocks) if len(filtered): unlocked = map(lambda item: (item, self._change2UnlockedByCD(item)), filtered) return (next2Unlock, unlocked)
def _invalidateUnlocks(self, unlocked, result): vehInCache = self.__itemsCache[GUI_ITEM_TYPE.VEHICLE] for itemCD in unlocked: itemTypeID = getTypeOfCompactDescr(itemCD) if itemTypeID == GUI_ITEM_TYPE.VEHICLE: result[itemTypeID].add(itemCD) if itemCD in vehInCache: self._invalidateUnlocks(vehInCache[itemCD].getAutoUnlockedItems(), result) elif itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES: result[itemTypeID].add(itemCD) elif itemTypeID != GUI_ITEM_TYPE.FUEL_TANK: LOG_WARNING('Item is not vehicle or module', itemTypeID)
def _invalidateUnlocks(self, unlocked, result): vehInCache = self.__itemsCache[GUI_ITEM_TYPE.VEHICLE] for itemCD in unlocked: itemTypeID = getTypeOfCompactDescr(itemCD) if itemTypeID == GUI_ITEM_TYPE.VEHICLE: result[itemTypeID].add(itemCD) if itemCD in vehInCache: self._invalidateUnlocks(vehInCache[itemCD].getAutoUnlockedItems(), result) if itemTypeID in GUI_ITEM_TYPE.VEHICLE_MODULES: result[itemTypeID].add(itemCD) if itemTypeID != GUI_ITEM_TYPE.FUEL_TANK: LOG_WARNING('Item is not vehicle or module', itemTypeID)
def atCall(self, cd): function = cd.function.__name__ trigger = self.__triggerRef() if trigger is None: return else: if function == 'updateVehicleAmmo': cd, quantity, quantityInClip, _ = cd.args if ITEM_TYPE_INDICES['shell'] == getTypeOfCompactDescr(cd): trigger.setAmmoLayout(cd, quantity) elif function == 'shoot': trigger.toggle(isOn=trigger.isOn(shoot=True)) return
def getSuitableChassis(vehicle): """ :param vehicle: instance of vehicle :return: list of chassis that is not installed and fit provided vehicle """ chassis = [] for _, _, nodeCD, _ in vehicle.getUnlocksDescrs(): itemTypeID = getTypeOfCompactDescr(nodeCD) if itemTypeID == GUI_ITEM_TYPE.CHASSIS: chassisCand = g_itemsCache.items.getItemByCD(nodeCD) if chassisCand.mayInstall(vehicle) and not chassisCand.isInstalled(vehicle): chassis.append(chassisCand) return chassis
def __getCommonParameters(self, itemTypeCompDescr, paramsDict, excluded = tuple()): result = list() if GUI_SETTINGS.technicalInfo: for param in self.__itemCommonParamsList.get(getTypeOfCompactDescr(itemTypeCompDescr), tuple()): if type(param) == str: if param not in excluded: result.append([param, paramsDict.get(param)]) else: paramName = param[0] paramValue = paramsDict.get(param[0]) formatFunc = param[1] formattedValue = formatFunc(paramValue) if formattedValue is not None and paramName not in excluded: result.append([paramName, formattedValue]) return result
def getFormattedParamsList(descriptor, parameters, excludeRelative = False): compactDescr = descriptor.type.compactDescr if isinstance(descriptor, vehicles.VehicleDescr) else descriptor['compactDescr'] itemTypeIdx = getTypeOfCompactDescr(compactDescr) if itemTypeIdx == ITEM_TYPES.equipment: eqDescr = vehicles.getDictDescr(compactDescr) paramsList = ITEMS_PARAMS_LIST[itemTypeIdx].get(type(eqDescr), []) else: paramsList = ITEMS_PARAMS_LIST[itemTypeIdx] params = [] for paramName in paramsList: if excludeRelative and isRelativeParameter(paramName): continue paramValue = parameters.get(paramName) fmtValue = paramValue if paramValue is None else baseFormatParameter(paramName, paramValue) if fmtValue: params.append((paramName, fmtValue)) return params
def __loadItems(self, rootItem, unlockStats): itemGetter = self.getItem rootCD = rootItem.intCD maxPath = 0 nodes = [] for unlockIdx, xpCost, nodeCD, required in rootItem.getUnlocksDescrs(): itemTypeID = getTypeOfCompactDescr(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 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 __getCommonParameters(self, itemTypeCompDescr, paramsDict, excluded = tuple()): result = list() if GUI_SETTINGS.technicalInfo: compDescrType = getTypeOfCompactDescr(itemTypeCompDescr) params = self.__itemCommonParamsList.get(compDescrType, {}) if compDescrType == vehicles._EQUIPMENT: eqDescr = vehicles.getDictDescr(itemTypeCompDescr) params = params.get(type(eqDescr), []) else: params = self.__itemCommonParamsList.get(compDescrType, []) for param in params: if type(param) == str: if param not in excluded: result.append([param, paramsDict.get(param)]) else: paramName = param[0] paramValue = paramsDict.get(param[0]) formatFunc = param[1] formattedValue = formatFunc(paramValue) if formattedValue is not None and paramName not in excluded: result.append([paramName, formattedValue]) return result
def _canBuy(self, nodeCD): result = False if getTypeOfCompactDescr(nodeCD) == GUI_ITEM_TYPE.VEHICLE or self.isInstallItemsEnabled(): result = super(ResearchItemsData, self)._canBuy(nodeCD) return result
def __readNation(self, shared, nation, clearCache = False): xmlPath = NATION_TREE_REL_FILE_PATH % nation if clearCache: ResMgr.purge(xmlPath) section = ResMgr.openSection(xmlPath) if section is None: LOG_ERROR('can not open or read nation tree: ', nation, xmlPath) return {} else: xmlCtx = (None, xmlPath) settingsName = _xml.readString(xmlCtx, section, 'settings') if settingsName not in shared['settings']: LOG_ERROR('not found settings (<settings> tag): ', settingsName, xmlPath) return {} precessed = _xml.getSubsection(xmlCtx, section, 'grid') gridName = precessed.asString if gridName not in shared['grids']: LOG_ERROR('not found grid (<grid> tag): ', gridName, xmlPath) return {} xPath = '{0:>s}/grid'.format(xmlPath) xmlCtx = (None, xPath) grid = shared['grids'][gridName] settings = shared['settings'][settingsName] rows = _xml.readInt(xmlCtx, precessed, 'rows') columns = _xml.readInt(xmlCtx, precessed, 'columns') self.__displaySettings[nations.INDICES[nation]] = settings nationIndex = self.__availableNations.index(nation) hasRoot = settings['hasRoot'] if hasRoot: coords = self.__makeGridCoordsWithRoot(grid, nationIndex, rows, columns) else: coords = self.__makeGridCoordsWoRoot(grid, rows, columns) getIDsByName = vehicles.g_list.getIDsByName makeIntCDByID = vehicles.makeIntCompactDescrByID getVehicle = vehicles.g_cache.vehicle precessed = _xml.getChildren(xmlCtx, section, 'nodes') displayInfo = {} for name, nodeSection in precessed: xPath = '{0:>s}/nodes/{1:>s}'.format(xmlPath, name) xmlCtx = (None, xPath) uName = '{0:>s}:{1:>s}'.format(nation, name) try: nationID, vTypeID = getIDsByName(uName) except Exception: raise _ConfigError(xmlCtx, 'Unknown vehicle type name {0:>s}'.format(uName)) nodeCD = makeIntCDByID(_VEHICLE_TYPE_NAME, nationID, vTypeID) vType = getVehicle(nationID, vTypeID) nextLevel = filter(lambda data: getTypeOfCompactDescr(data[1][1]) == _VEHICLE, enumerate(vType.unlocksDescrs)) for unlockDescr in vType.unlocksDescrs: self.__unlockPrices[unlockDescr[1]][vType.compactDescr] = unlockDescr[0] for idx, data in nextLevel: xpCost = data[0] nextCD = data[1] required = data[2:] self.__nextLevels[nodeCD][nextCD] = (idx, xpCost, set(required)) self.__topLevels[nextCD].add(nodeCD) for itemCD in required: self.__topItems[itemCD].add(nodeCD) row = _xml.readInt(xmlCtx, nodeSection, 'row') column = _xml.readInt(xmlCtx, nodeSection, 'column') if hasRoot and row > 1 and column is 1: raise _ConfigError(xmlCtx, 'In first column must be one node - root node, {0:>s} '.format(uName)) elif row > rows or column > columns: raise _ConfigError(xmlCtx, 'Invalid row or column index: {0:>s}, {1:d}, {2:d}'.format(uName, row, column)) lines = self.__readNodeLines(nodeCD, nation, xmlCtx, nodeSection, shared) displayInfo[nodeCD] = {'row': row, 'column': column, 'position': coords[column - 1][row - 1], 'lines': lines} return displayInfo
def request4Restore(self, itemCD): itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: ItemsActionsFactory.doAction(ItemsActionsFactory.BUY_VEHICLE, itemCD)
def request4Sell(self, itemCD): itemCD = int(itemCD) if getTypeOfCompactDescr(itemCD) == GUI_ITEM_TYPE.VEHICLE: self.sellVehicle(itemCD) else: self.sellItem(itemCD)
def getItemData(self, typeCompDescr): itemTypeID = getTypeOfCompactDescr(typeCompDescr) if itemTypeID == GUI_ITEM_TYPE.VEHICLE: return self.getVehicleData(self.__vehsIDsByCD.get(typeCompDescr, -1)) return self.__makeSimpleItem(typeCompDescr)
def __makeSimpleItem(self, typeCompDescr): return self.__makeItem(getTypeOfCompactDescr(typeCompDescr), typeCompDescr, intCompactDescr=typeCompDescr, proxy=self)
def __onItemUnlocked(self, unlocks): for intCD in unlocks: if getTypeOfCompactDescr(intCD) == GUI_ITEM_TYPE.VEHICLE: return self.__onEventsUpdated()