def requestTableData(self, nation, type, filter): Waiting.show('updateInventory') AccountSettings.setFilter('inventory_current', (nation, type)) AccountSettings.setFilter('inventory_' + type, filter) nation = int(nation) if nation >= 0 else None if nation is not None: nation = getNationIndex(nation) filter = list(filter) requestType = [type] checkFits = None checkFitsArtefacts = None checkExtra = False modulesFits = {} vehicleFits = [] extra = [] modulesAllVehicle = [] if type == self._MODULE: typeSize = int(filter.pop(0)) requestType = filter[0:typeSize] filter = filter[typeSize:] fitsType = filter.pop(0) fitsVehicle = getItemByCompact(filter.pop(0)) checkExtra = True extra = filter[:] checkFits = True if fitsType != 'otherVehicles' else False myVehicles = yield Requester(self._VEHICLE).getFromInventory() modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems(requestType) if fitsType == 'myVehicle': if fitsVehicle: for rType in requestType: modulesFits.update(_getComponentsByType(fitsVehicle, ITEM_TYPE_INDICES[rType])) else: for vehicle in myVehicles: for rType in requestType: modulesFits.update(_getComponentsByType(vehicle, ITEM_TYPE_INDICES[rType])) filter = requestType elif type == self._SHELL: filterSize = int(filter.pop(0)) fitsType = filter.pop(filterSize) fitsVehicle = getItemByCompact(filter.pop(filterSize)) checkFits = True if fitsType != 'otherGuns' else False if fitsType == 'myVehicleGun': for shoot in fitsVehicle.descriptor.gun['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif fitsType == 'myInventoryGuns': myGuns = yield Requester('vehicleGun').getFromInventory() for gun in myGuns: for shoot in gun.descriptor['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True else: myGuns = yield Requester('vehicleGun').getFromInventory() for gun in myGuns: for shoot in gun.descriptor['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True myVehicles = yield Requester(self._VEHICLE).getFromInventory() for vehicle in myVehicles: for shoot in vehicle.descriptor.gun['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif type == self._VEHICLE: filterSize = int(filter.pop(0)) extra = filter[filterSize:] checkExtra = True filter = filter[0:filterSize] else: fitsType = filter.pop(0) compact = filter.pop(0) fitsVehicle = getItemByCompact(compact) extra = filter checkExtra = type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) checkFitsArtefacts = True if fitsType != 'otherVehicles' else False myVehicles = yield Requester(self._VEHICLE).getFromInventory() modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems(requestType) if fitsType == 'myVehicle': vehicleFits = [fitsVehicle] else: vehicleFits = myVehicles filter = requestType filter = map(lambda w: w.lower(), filter) modulesAll = list() modulesShop = list() for rType in requestType: inv = yield Requester(rType).getFromInventory() shp = yield Requester(rType).getFromShop() modulesShop.extend(shp) modulesAll.extend(inv) vehPrices = {} if type == self._VEHICLE: compactDescrs = [ v.compactDescr for v in modulesAll ] vehPrices = yield StatsRequester().getVehiclesPrices(compactDescrs) vehPrices = dict(zip(compactDescrs, vehPrices)) if type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT): for vehModule in modulesAllVehicle: if vehModule not in modulesAll: if modulesShop.count(vehModule) != 0: modulesAll.append(vehModule) self.__clearTableData() self.__tableData = [type] excludeModules = [] for module in modulesAll: if modulesShop.count(module) != 0: module.priceOrder = modulesShop[modulesShop.index(module)].priceOrder elif constants.IS_DEVELOPMENT: excludeModules.append(module) LOG_ERROR("Not found module %s '%s' (%r) in shop." % (module.type, module.unicName, module.compactDescr)) modulesAll.sort() shopRqs = yield ShopRequester().request() for module in modulesAll: extraModuleInfo = None if module in excludeModules: continue if nation is not None: if module.nation != nation and module.nation != nations.NONE_INDEX: continue if module.type.lower() not in filter: continue if checkFits is not None: if (module.compactDescr in modulesFits.keys()) != checkFits: continue if module.isClipGun(): extraModuleInfo = CLIP_ICON_PATH if checkFitsArtefacts is not None: compatible = False for veh in vehicleFits: if nation is not None and veh.nation != nation: continue compatible |= module.descriptor.checkCompatibilityWithVehicle(veh.descriptor)[0] if compatible != checkFitsArtefacts: continue inventoryCount = 0 vehicleCount = 0 if isinstance(module, VehicleItem): vehicleCount = module.count else: inventoryCount = module.count if type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module in modulesAllVehicle: vehModule = modulesAllVehicle[modulesAllVehicle.index(module)] vehicleCount = vehModule.count if checkExtra: if type == self._VEHICLE and 'brocken' not in extra: if module.repairCost > 0: continue if type == self._VEHICLE and 'locked' not in extra: if module.lock != 0: continue if 'onVehicle' not in extra: if vehicleCount > 0 and inventoryCount == 0: continue disable = '' if type == self._VEHICLE and not module.canSell: disable = makeString(MENU.tankcarousel_vehiclestates(module.getState())) elif type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT) and isinstance(module, VehicleItem): if type == self._OPTIONAL_DEVICE: if not module.descriptor['removable']: disable = makeString(MENU.INVENTORY_DEVICE_ERRORS_NOT_REMOVABLE) else: disable = makeString(MENU.INVENTORY_DEVICE_ERRORS_RESERVED) else: disable = makeString(MENU.INVENTORY_ERRORS_RESERVED) sellPrice = isinstance(module, InventoryVehicle) and vehPrices.get(module.compactDescr, (0, 0)) else: sellPrice = (0, 0) item = g_itemsCache.items.getItemByCD(module.compactDescr) if item is not None: sellPrice = item.sellPrice valueElement = {'id': compactItem(module), 'name': module.name if type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) else module.longName, 'desc': getShortDescr(module.tableName), 'inventoryId': module.inventoryId if isinstance(module, InventoryVehicle) else None, 'inventoryCount': inventoryCount, 'vehicleCount': vehicleCount, 'credits': sellPrice[0], 'gold': sellPrice[1], 'price': sellPrice, 'currency': 'credits' if sellPrice[1] == 0 else 'gold', 'level': module.level, 'nation': module.nation, 'type': module.itemTypeName if type not in (self._VEHICLE, self._OPTIONAL_DEVICE, self._SHELL, self._EQUIPMENT) else module.icon, 'disabled': disable, 'statusLevel': module.getStateLevel() if isinstance(module, InventoryVehicle) else InventoryVehicle.STATE_LEVEL.INFO, 'removable': module.descriptor['removable'] if type == self._OPTIONAL_DEVICE else True, 'tankType': module.type if type == self._VEHICLE else type, 'isPremium': module.isPremium if type == self._VEHICLE else False, 'isElite': self.app.tooltipManager.isVehicleElite(module) if type == self._VEHICLE else False, 'itemTypeName': module.itemTypeName, 'goldShellsForCredits': shopRqs.isEnabledBuyingGoldShellsForCredits, 'goldEqsForCredits': shopRqs.isEnabledBuyingGoldEqsForCredits, EXTRA_MODULE_INFO: extraModuleInfo} self.__tableData.append(valueElement) requester = yield StatsRequesterr().request() self._table.as_setGoldS(requester.gold) self._table.as_setCreditsS(requester.credits) self._table.as_setTableS(self.__tableData) Waiting.hide('updateInventory') return
def requestTableData(self, nation, type, filter): Waiting.show('updateShop') AccountSettings.setFilter('shop_current', (nation, type)) AccountSettings.setFilter('shop_' + type, filter) nation = int(nation) if nation >= 0 else None if nation is not None: nation = getNationIndex(nation) filter = list(filter) requestType = [type] checkFits = None checkFitsArtefacts = None checkExtra = False modulesFits = {} vehicleFits = [] extra = [] modulesAllVehicle = [] if type == self._MODULE: typeSize = int(filter.pop(0)) requestType = filter[0:typeSize] filter = filter[typeSize:] fitsType = filter.pop(0) compact = filter.pop(0) if compact == '0': LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return fitsVehicle = getItemByCompact(compact) checkExtra = True extra = filter[:] checkFits = True if fitsType != 'otherVehicles' else None myVehicles = yield Requester(self._VEHICLE).getFromInventory() modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems( requestType) if fitsType == 'myVehicle': for rType in requestType: modulesFits.update( _getComponentsByType(fitsVehicle, ITEM_TYPE_INDICES[rType])) elif fitsType != 'otherVehicles': for vehicle in myVehicles: for rType in requestType: modulesFits.update( _getComponentsByType(vehicle, ITEM_TYPE_INDICES[rType])) filter = requestType elif type == self._SHELL: filterSize = int(filter.pop(0)) fitsType = filter.pop(filterSize) compact = filter.pop(filterSize) if compact == '0': LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return fitsVehicle = getItemByCompact(compact) checkFits = True if fitsType != 'otherGuns' else None if fitsType == 'myVehicleGun': for shoot in fitsVehicle.descriptor.gun['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif fitsType == 'myInventoryGuns': myGuns = yield Requester('vehicleGun').getFromInventory() for gun in myGuns: for shoot in gun.descriptor['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif fitsType != 'otherGuns': myGuns = yield Requester('vehicleGun').getFromInventory() for gun in myGuns: for shoot in gun.descriptor['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True myVehicles = yield Requester(self._VEHICLE).getFromInventory() for vehicle in myVehicles: for shoot in vehicle.descriptor.gun['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif type == self._VEHICLE: filterSize = int(filter.pop(0)) extra = filter[filterSize:] checkExtra = True filter = filter[0:filterSize] else: fitsType = filter.pop(0) compact = filter.pop(0) if compact == '0': LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return fitsVehicle = getItemByCompact(compact) extra = filter checkExtra = type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) checkFitsArtefacts = True if fitsType != 'otherVehicles' else None myVehicles = yield Requester(self._VEHICLE).getFromInventory() modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems( requestType) if fitsType == 'myVehicle': vehicleFits = [fitsVehicle] elif fitsType != 'otherVehicles': vehicleFits = [v for v in myVehicles if v.nation == nation ] if nation != None else myVehicles filter = requestType filter = map(lambda w: w.lower(), filter) modulesAll = list() modulesAllInventory = list() for rType in requestType: inv = yield Requester(rType).getFromInventory() modulesAllInventory.extend(inv) shp = yield Requester(rType).getFromShop(nation=nation) modulesAll.extend(shp) unlocks = yield StatsRequester().getUnlocks() shopRqs = yield ShopRequester().request() self.__clearTableData() self.__tableData = [type] modulesAll.sort() for module in modulesAll: extraModuleInfo = None if module.hidden: continue if module.type.lower() not in filter: continue if checkFits is not None: if (module.compactDescr in modulesFits.keys()) != checkFits: continue if checkFitsArtefacts is not None: for veh in vehicleFits: if module.descriptor.checkCompatibilityWithVehicle( veh.descriptor)[0] == checkFitsArtefacts: break else: continue if module.isClipGun(): extraModuleInfo = CLIP_ICON_PATH inventoryCount = 0 vehicleCount = 0 installedIn = '' if module in modulesAllInventory: inventoryCount = 1 if type != self._VEHICLE: inventoryModule = modulesAllInventory[ modulesAllInventory.index(module)] inventoryCount = inventoryModule.count if type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module in modulesAllVehicle: vehModule = modulesAllVehicle[modulesAllVehicle.index(module)] vehicleCount = vehModule.count installedIn = ', '.join( [v.shortName for v in vehModule.vehicles]) if checkExtra: if 'locked' not in extra: if type == self._VEHICLE: compdecs = module.descriptor.type.compactDescr if compdecs not in unlocks: continue elif type not in (self._SHELL, self._OPTIONAL_DEVICE, self._EQUIPMENT ) and module.compactDescr not in unlocks: continue if 'inHangar' not in extra and type not in ( self._OPTIONAL_DEVICE, self._EQUIPMENT): if inventoryCount > 0: continue if 'onVehicle' not in extra: if vehicleCount > 0: continue disabled = '' if type == self._VEHICLE: if BigWorld.player().isLongDisconnectedFromCenter: disabled = MENU.SHOP_ERRORS_CENTERISDOWN if inventoryCount > 0: disabled = MENU.SHOP_ERRORS_INHANGAR else: compdecs = module.descriptor.type.compactDescr if compdecs not in unlocks: disabled = MENU.SHOP_ERRORS_UNLOCKNEEDED elif type not in ( self._SHELL, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module.compactDescr not in unlocks: disabled = MENU.SHOP_ERRORS_UNLOCKNEEDED if not (shopRqs.isEnabledBuyingGoldShellsForCredits and module.itemTypeName == 'shell'): goldAmmoForCredits = shopRqs.isEnabledBuyingGoldEqsForCredits and module.itemTypeName == 'equipment' module.priceOrder = goldAmmoForCredits and ( module.priceOrder[0] + module.priceOrder[1] * shopRqs.exchangeRateForShellsAndEqs, module.priceOrder[1]) valueElement = { 'id': compactItem(module), 'name': module.name if type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) else module.longName, 'desc': getShortDescr(module.tableName), 'inventoryId': None, 'inventoryCount': inventoryCount, 'vehicleCount': vehicleCount, 'credits': module.priceOrder[0], 'gold': module.priceOrder[1], 'price': module.priceOrder, 'currency': 'credits' if module.priceOrder[1] == 0 else 'gold', 'level': module.level, 'nation': module.nation, 'type': module.itemTypeName if type not in (self._VEHICLE, self._OPTIONAL_DEVICE, self._SHELL, self._EQUIPMENT) else module.icon, 'disabled': disabled, 'statusLevel': InventoryVehicle.STATE_LEVEL.WARNING, 'removable': module.descriptor['removable'] if type == self._OPTIONAL_DEVICE else True, 'tankType': module.type if type == self._VEHICLE else type, 'isPremium': module.isPremium if type == self._VEHICLE else False, 'isElite': self.app.tooltipManager.isVehicleElite(module) if type == self._VEHICLE else False, 'itemTypeName': module.itemTypeName, 'goldShellsForCredits': shopRqs.isEnabledBuyingGoldShellsForCredits, 'goldEqsForCredits': shopRqs.isEnabledBuyingGoldEqsForCredits, EXTRA_MODULE_INFO: extraModuleInfo } self.__tableData.append(valueElement) requester = yield StatsRequesterr().request() self._table.as_setGoldS(requester.gold) self._table.as_setCreditsS(requester.credits) self._table.as_setTableS(self.__tableData) Waiting.hide('updateShop') return
def requestTableData(self, nation, type, filter): Waiting.show('updateShop') AccountSettings.setFilter('shop_current', (nation, type)) AccountSettings.setFilter('shop_' + type, filter) nation = int(nation) if nation >= 0 else None if nation is not None: nation = getNationIndex(nation) filter = list(filter) requestType = [type] checkFits = None checkFitsArtefacts = None checkExtra = False modulesFits = {} vehicleFits = [] extra = [] modulesAllVehicle = [] if type == self._MODULE: typeSize = int(filter.pop(0)) requestType = filter[0:typeSize] filter = filter[typeSize:] fitsType = filter.pop(0) compact = filter.pop(0) if compact == '0': LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return fitsVehicle = getItemByCompact(compact) checkExtra = True extra = filter[:] checkFits = True if fitsType != 'otherVehicles' else None myVehicles = yield Requester(self._VEHICLE).getFromInventory() modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems(requestType) if fitsType == 'myVehicle': for rType in requestType: modulesFits.update(_getComponentsByType(fitsVehicle, ITEM_TYPE_INDICES[rType])) elif fitsType != 'otherVehicles': for vehicle in myVehicles: for rType in requestType: modulesFits.update(_getComponentsByType(vehicle, ITEM_TYPE_INDICES[rType])) filter = requestType elif type == self._SHELL: filterSize = int(filter.pop(0)) fitsType = filter.pop(filterSize) compact = filter.pop(filterSize) if compact == '0': LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return fitsVehicle = getItemByCompact(compact) checkFits = True if fitsType != 'otherGuns' else None if fitsType == 'myVehicleGun': for shoot in fitsVehicle.descriptor.gun['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif fitsType == 'myInventoryGuns': myGuns = yield Requester('vehicleGun').getFromInventory() for gun in myGuns: for shoot in gun.descriptor['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif fitsType != 'otherGuns': myGuns = yield Requester('vehicleGun').getFromInventory() for gun in myGuns: for shoot in gun.descriptor['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True myVehicles = yield Requester(self._VEHICLE).getFromInventory() for vehicle in myVehicles: for shoot in vehicle.descriptor.gun['shots']: modulesFits[shoot[self._SHELL]['compactDescr']] = True elif type == self._VEHICLE: filterSize = int(filter.pop(0)) extra = filter[filterSize:] checkExtra = True filter = filter[0:filterSize] else: fitsType = filter.pop(0) compact = filter.pop(0) if compact == '0': LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return fitsVehicle = getItemByCompact(compact) extra = filter checkExtra = type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) checkFitsArtefacts = True if fitsType != 'otherVehicles' else None myVehicles = yield Requester(self._VEHICLE).getFromInventory() modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems(requestType) if fitsType == 'myVehicle': vehicleFits = [fitsVehicle] elif fitsType != 'otherVehicles': vehicleFits = [ v for v in myVehicles if v.nation == nation ] if nation != None else myVehicles filter = requestType filter = map(lambda w: w.lower(), filter) modulesAll = list() modulesAllInventory = list() for rType in requestType: inv = yield Requester(rType).getFromInventory() modulesAllInventory.extend(inv) shp = yield Requester(rType).getFromShop(nation=nation) modulesAll.extend(shp) unlocks = yield StatsRequester().getUnlocks() shopRqs = yield ShopRequester().request() self.__clearTableData() self.__tableData = [type] modulesAll.sort() for module in modulesAll: extraModuleInfo = None if module.hidden: continue if module.type.lower() not in filter: continue if checkFits is not None: if (module.compactDescr in modulesFits.keys()) != checkFits: continue if checkFitsArtefacts is not None: for veh in vehicleFits: if module.descriptor.checkCompatibilityWithVehicle(veh.descriptor)[0] == checkFitsArtefacts: break else: continue if module.isClipGun(): extraModuleInfo = CLIP_ICON_PATH inventoryCount = 0 vehicleCount = 0 installedIn = '' if module in modulesAllInventory: inventoryCount = 1 if type != self._VEHICLE: inventoryModule = modulesAllInventory[modulesAllInventory.index(module)] inventoryCount = inventoryModule.count if type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module in modulesAllVehicle: vehModule = modulesAllVehicle[modulesAllVehicle.index(module)] vehicleCount = vehModule.count installedIn = ', '.join([ v.shortName for v in vehModule.vehicles ]) if checkExtra: if 'locked' not in extra: if type == self._VEHICLE: compdecs = module.descriptor.type.compactDescr if compdecs not in unlocks: continue elif type not in (self._SHELL, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module.compactDescr not in unlocks: continue if 'inHangar' not in extra and type not in (self._OPTIONAL_DEVICE, self._EQUIPMENT): if inventoryCount > 0: continue if 'onVehicle' not in extra: if vehicleCount > 0: continue disabled = '' if type == self._VEHICLE: if BigWorld.player().isLongDisconnectedFromCenter: disabled = MENU.SHOP_ERRORS_CENTERISDOWN if inventoryCount > 0: disabled = MENU.SHOP_ERRORS_INHANGAR else: compdecs = module.descriptor.type.compactDescr if compdecs not in unlocks: disabled = MENU.SHOP_ERRORS_UNLOCKNEEDED elif type not in (self._SHELL, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module.compactDescr not in unlocks: disabled = MENU.SHOP_ERRORS_UNLOCKNEEDED if not (shopRqs.isEnabledBuyingGoldShellsForCredits and module.itemTypeName == 'shell'): goldAmmoForCredits = shopRqs.isEnabledBuyingGoldEqsForCredits and module.itemTypeName == 'equipment' module.priceOrder = goldAmmoForCredits and (module.priceOrder[0] + module.priceOrder[1] * shopRqs.exchangeRateForShellsAndEqs, module.priceOrder[1]) valueElement = {'id': compactItem(module), 'name': module.name if type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) else module.longName, 'desc': getShortDescr(module.tableName), 'inventoryId': None, 'inventoryCount': inventoryCount, 'vehicleCount': vehicleCount, 'credits': module.priceOrder[0], 'gold': module.priceOrder[1], 'price': module.priceOrder, 'currency': 'credits' if module.priceOrder[1] == 0 else 'gold', 'level': module.level, 'nation': module.nation, 'type': module.itemTypeName if type not in (self._VEHICLE, self._OPTIONAL_DEVICE, self._SHELL, self._EQUIPMENT) else module.icon, 'disabled': disabled, 'statusLevel': InventoryVehicle.STATE_LEVEL.WARNING, 'removable': module.descriptor['removable'] if type == self._OPTIONAL_DEVICE else True, 'tankType': module.type if type == self._VEHICLE else type, 'isPremium': module.isPremium if type == self._VEHICLE else False, 'isElite': self.app.tooltipManager.isVehicleElite(module) if type == self._VEHICLE else False, 'itemTypeName': module.itemTypeName, 'goldShellsForCredits': shopRqs.isEnabledBuyingGoldShellsForCredits, 'goldEqsForCredits': shopRqs.isEnabledBuyingGoldEqsForCredits, EXTRA_MODULE_INFO: extraModuleInfo} self.__tableData.append(valueElement) requester = yield StatsRequesterr().request() self._table.as_setGoldS(requester.gold) self._table.as_setCreditsS(requester.credits) self._table.as_setTableS(self.__tableData) Waiting.hide('updateShop') return