def getRetrainingData(self, callback): items = g_itemsCache.items tankman = items.getTankman(self.tmanInvID) criteria = REQ_CRITERIA.NATIONS([tankman.nationID ]) | REQ_CRITERIA.UNLOCKED vData = items.getVehicles(criteria) tDescr = tankman.descriptor vehiclesData = sorted(vData.values()) result = [] for vehicle in vehiclesData: vDescr = vehicle.descriptor if isVehicleObserver(vDescr.type.compactDescr): continue for role in vDescr.type.crewRoles: if tDescr.role == role[0]: result.append({ 'innationID': vehicle.innationID, 'vehicleType': vehicle.type, 'userName': vehicle.shortUserName }) break callback({ 'money': (items.stats.credits, items.stats.gold), 'tankmanCost': items.shop.tankmanCost, 'vehicles': result })
def showVehicles(self): filterCriteria = REQ_CRITERIA.INVENTORY if self.__vehiclesFilter['nation'] != -1: if self.__vehiclesFilter['nation'] == 100: filterCriteria |= REQ_CRITERIA.VEHICLE.IS_PREMIUM_IGR else: filterCriteria |= REQ_CRITERIA.NATIONS( [self.__vehiclesFilter['nation']]) if self.__vehiclesFilter['tankType'] != 'none': filterCriteria |= REQ_CRITERIA.VEHICLE.CLASSES( [self.__vehiclesFilter['tankType']]) if self.__vehiclesFilter['ready']: filterCriteria |= REQ_CRITERIA.VEHICLE.FAVORITE if self.__vehiclesFilter[ 'gameModeFilter'] and self.__multiselectionMode: filterCriteria |= REQ_CRITERIA.VEHICLE.FALLOUT.AVAILABLE items = g_itemsCache.items filteredVehs = items.getVehicles(filterCriteria) def sorting(v1, v2): if v1.isFavorite and not v2.isFavorite: return -1 if not v1.isFavorite and v2.isFavorite: return 1 return v1.__cmp__(v2) vehsCDs = map(attrgetter('intCD'), sorted(filteredVehs.values(), sorting)) LOG_DEBUG('Showing carousel vehicles: ', vehsCDs) self.as_showVehiclesS(vehsCDs)
def getRetrainingData(self, callback): items = g_itemsCache.items tankman = items.getTankman(self.tmanInvID) nativeVehicleCD = tankman.vehicleNativeDescr.type.compactDescr criteria = REQ_CRITERIA.NATIONS([tankman.nationID ]) | REQ_CRITERIA.UNLOCKED vData = items.getVehicles(criteria) tDescr = tankman.descriptor vehiclesData = vData.values() if nativeVehicleCD not in vData: vehiclesData.append(items.getItemByCD(nativeVehicleCD)) result = [] for vehicle in sorted(vehiclesData): vDescr = vehicle.descriptor if isVehicleObserver(vDescr.type.compactDescr): continue for role in vDescr.type.crewRoles: if tDescr.role == role[0]: result.append({ 'innationID': vehicle.innationID, 'vehicleType': vehicle.type, 'userName': vehicle.shortUserName }) break shopPrices, action = items.shop.getTankmanCostWithDefaults() callback({ 'money': (items.stats.credits, items.stats.gold), 'tankmanCost': shopPrices, 'action': action, 'vehicles': result })
def _getAllPossibleXP(self, nodeCD, unlockStats): criteria = REQ_CRITERIA.VEHICLE.ELITE | ~REQ_CRITERIA.IN_CD_LIST([nodeCD]) eliteVehicles = g_itemsCache.items.getVehicles(criteria) dirtyResult = sum(map(operator.attrgetter('xp'), eliteVehicles.values())) exchangeRate = self._items.shop.freeXPConversion[0] result = min(int(dirtyResult / exchangeRate) * exchangeRate, self._stats.gold * exchangeRate) result += unlockStats.getVehTotalXP(nodeCD) return result
def _getOptionalDeviceCD(name): if name is None: return opts = g_itemsCache.items.getItems( GUI_ITEM_TYPE.OPTIONALDEVICE, REQ_CRITERIA.CUSTOM(lambda opt: name in opt.name)) if opts: result, _ = opts.popitem() else: result = None return result
def _getEquipmentForCreditsCD(tag): if tag is None: return equipments = g_itemsCache.items.getItems( GUI_ITEM_TYPE.EQUIPMENT, REQ_CRITERIA.CUSTOM(lambda eq: tag in eq.tags and eq.buyPrice[0] > 0)) if equipments: result, _ = equipments.popitem() else: result = None return result
def updateNationDropdown(self): vehsItems = g_itemsCache.items.getVehicles(self.__getNationsCriteria()) data = [{'id': None, 'label': DIALOGS.RECRUITWINDOW_MENUEMPTYROW}] for name in GUI_NATIONS: nationIdx = nations.INDICES[name] vehiclesAvailable = len( vehsItems.filter(REQ_CRITERIA.NATIONS([nationIdx]))) > 0 if name in nations.AVAILABLE_NAMES and vehiclesAvailable: data.append({'id': nationIdx, 'label': MENU.nations(name)}) self.flashObject.as_setNations(data)
def updateVehicles(self, vehicles=None, updateFallout=True): isSet = vehicles is None filterCriteria = REQ_CRITERIA.INVENTORY if vehicles is not None: filterCriteria |= REQ_CRITERIA.IN_CD_LIST(vehicles) items = g_itemsCache.items filteredVehs = items.getVehicles(filterCriteria) if vehicles is None: vehicles = filteredVehs.keys() isSuitablePredicate = lambda vehIntCD: True if self.preQueueFunctional.getQueueType( ) == constants.QUEUE_TYPE.HISTORICAL: battle = self.preQueueFunctional.getItemData() if battle is not None: isSuitablePredicate = battle.canParticipateWith hasEmptySlots = self.__multiselectionMode and len( self.__falloutCtrl.getEmptySlots()) > 0 vehsData = {} for intCD in vehicles: vehicle = filteredVehs.get(intCD) if vehicle is not None: vState, vStateLvl = vehicle.getState() isSuitableVeh = vState != Vehicle.VEHICLE_STATE.BATTLE and not isSuitablePredicate( vehicle.intCD) isSuitableVeh |= self.__multiselectionMode and not vehicle.isFalloutAvailable if isSuitableVeh: vState, vStateLvl = Vehicle.VEHICLE_STATE.NOT_SUITABLE, Vehicle.VEHICLE_STATE_LEVEL.WARNING canSelect, tooltip = self.__falloutCtrl.canSelectVehicle( vehicle) rentInfoStr = RentLeftFormatter( vehicle.rentInfo, vehicle.isPremiumIGR).getRentLeftStr() vehsData[intCD] = self._getVehicleData(vehicle, vState, vStateLvl, rentInfoStr, hasEmptySlots, canSelect, tooltip) LOG_DEBUG('Updating carousel vehicles: ', vehsData if not isSet else 'full sync') self.as_updateVehiclesS(vehsData, isSet) self.showVehicles() isVehTypeLock = sum( (len(v) for v in items.stats.vehicleTypeLocks.itervalues())) isGlobalVehLock = sum( (len(v) for v in items.stats.globalVehicleLocks.itervalues())) if self.__updateVehiclesTimerId is None and (isVehTypeLock or isGlobalVehLock): self.__updateVehiclesTimerId = BigWorld.callback( self.UPDATE_LOCKS_PERIOD, self.updateLockTimers) LOG_DEBUG('Lock timer updated') if updateFallout: self._updateFallout()
def updateVehiclesList(self): battle = g_eventsCache.getHistoricalBattles().get(self.selectedBattleID) teamARoster = battle.getTeamRoster(HistoricalBattle.SIDES.A) teamBRoster = battle.getTeamRoster(HistoricalBattle.SIDES.B) teamAVehicles = g_itemsCache.items.getVehicles(REQ_CRITERIA.IN_CD_LIST(teamARoster)).itervalues() teamBVehicles = g_itemsCache.items.getVehicles(REQ_CRITERIA.IN_CD_LIST(teamBRoster)).itervalues() def sortFunction(a, b): if a.isInInventory and not b.isInInventory: return -1 if not a.isInInventory and b.isInInventory: return 1 if a.isReadyToFight and not b.isReadyToFight: return -1 if not a.isReadyToFight and b.isReadyToFight: return 1 return 0 teamAVehicles = sorted(teamAVehicles, sortFunction) teamBVehicles = sorted(teamBVehicles, sortFunction) teamAData = map(self._makeVehicleListItemVO, teamAVehicles) teamBData = map(self._makeVehicleListItemVO, teamBVehicles) self.as_setTeamsDataS(teamAData, teamBData)
def updateNationDropdown(self): try: vehsItems = g_itemsCache.items.getVehicles(REQ_CRITERIA.UNLOCKED) data = [{'id': None, 'label': DIALOGS.RECRUITWINDOW_MENUEMPTYROW}] for name in GUI_NATIONS: nationIdx = nations.INDICES[name] vehiclesAvailable = len( vehsItems.filter(REQ_CRITERIA.NATIONS([nationIdx]))) > 0 if name in nations.AVAILABLE_NAMES and vehiclesAvailable: data.append({'id': nationIdx, 'label': MENU.nations(name)}) self.flashObject.as_setNations(data) except Exception: LOG_ERROR( 'There is exception while setting data to the recruit window') LOG_CURRENT_EXCEPTION() return
def _getRequestCriteria(self): criteria = ~REQ_CRITERIA.SECRET | ~REQ_CRITERIA.HIDDEN if 'nation' in self._params: criteria |= REQ_CRITERIA.NATIONS( [nations.INDICES[self._params['nation']]]) if 'levelEqual' in self._params: criteria |= REQ_CRITERIA.VEHICLE.LEVELS( [int(self._params['levelEqual'])]) else: criteria |= REQ_CRITERIA.VEHICLE.LEVELS( range( int(self._params.get('levelMoreThan', 0)) + 1, int( self._params.get('levelLessThan', constants.MAX_VEHICLE_LEVEL + 1)))) if 'vehClass' in self._params: criteria |= REQ_CRITERIA.VEHICLE.CLASSES( [self._params['vehClass']]) return criteria
def _parse(self): criteria = ~REQ_CRITERIA.SECRET | self._getCustomFilter() if 'types' in self._value: criteria |= REQ_CRITERIA.VEHICLE.SPECIFIC_BY_CD( self._value['types']['value']) else: if 'nations' in self._value: criteria |= REQ_CRITERIA.NATIONS( self._value['nations']['value']) if 'levels' in self._value: criteria |= REQ_CRITERIA.VEHICLE.LEVELS( self._value['levels']['value']) if 'classes' in self._value: classes = [ name for name, index in constants.VEHICLE_CLASS_INDICES.items() if index in self._value['classes']['value'] ] criteria |= REQ_CRITERIA.VEHICLE.CLASSES(classes) return sorted(g_itemsCache.items.getVehicles(criteria).itervalues())
def __getRoleCriteria(self, nationID, vclass, typeID): return self.__getVehicleTypeCriteria( nationID, vclass) | REQ_CRITERIA.INNATION_IDS([typeID])
def __getClassesCriteria(self, nationID): return self.__getNationsCriteria() | REQ_CRITERIA.NATIONS([nationID])
def _getRequestParameters(self, nation, type, filter): checkExtra = False extra = [] requestCriteria = super(Shop, self)._getRequestParameters(nation, type, filter) inventoryVehicles = g_itemsCache.items.getVehicles(requestCriteria | REQ_CRITERIA.INVENTORY).values() requestCriteria = requestCriteria | ~REQ_CRITERIA.HIDDEN if type == self._MODULE: typeSize = int(filter.pop(0)) requestType = filter[0:typeSize] requestTypeIds = map(lambda x: ITEM_TYPE_INDICES[x], requestType) filter = filter[typeSize:] fitsType = filter.pop(0) compact = filter.pop(0) if not compact: LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return checkExtra = True extra = filter[:] itemTypeID = tuple(requestTypeIds) if fitsType == 'myVehicle': vehicle = g_itemsCache.items.getItemByCD(int(compact)) requestCriteria |= REQ_CRITERIA.VEHICLE.SUITABLE([vehicle], requestTypeIds) elif fitsType != 'otherVehicles': requestCriteria |= REQ_CRITERIA.VEHICLE.SUITABLE(inventoryVehicles, requestTypeIds) elif type == self._SHELL: filterSize = int(filter.pop(0)) requestType = filter[0:filterSize] filter = filter[filterSize:] fitsType = filter.pop(0) compact = filter.pop(0) if not compact: LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return itemTypeID = GUI_ITEM_TYPE.SHELL requestCriteria |= REQ_CRITERIA.CUSTOM(lambda item: item.type in requestType) if fitsType == 'myVehicleGun': vehicle = g_itemsCache.items.getItemByCD(int(compact)) shellsList = map(lambda x: x.intCD, vehicle.gun.defaultAmmo) requestCriteria |= REQ_CRITERIA.IN_CD_LIST(shellsList) elif fitsType != 'otherGuns': shellsList = set() myGuns = g_itemsCache.items.getItems(GUI_ITEM_TYPE.GUN, REQ_CRITERIA.INVENTORY).values() for gun in myGuns: shellsList.update(map(lambda x: x.intCD, gun.defaultAmmo)) for vehicle in inventoryVehicles: shellsList.update(map(lambda x: x.intCD, vehicle.gun.defaultAmmo)) requestCriteria |= REQ_CRITERIA.IN_CD_LIST(shellsList) elif type == self._VEHICLE: requestCriteria |= ~REQ_CRITERIA.VEHICLE.IS_PREMIUM_IGR typeSize = int(filter.pop(0)) requestType = filter[0:typeSize] extra = filter[typeSize:] checkExtra = True if 'all' not in requestType: requestType = map(lambda x: x.lower(), requestType) requestCriteria |= REQ_CRITERIA.CUSTOM(lambda item: item.type.lower() in requestType) itemTypeID = GUI_ITEM_TYPE.VEHICLE else: fitsType = filter.pop(0) compact = filter.pop(0) if not compact: LOG_ERROR('compact value has invalid value: ', compact) Waiting.hide('updateShop') return extra = filter checkExtra = type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) itemTypeID = GUI_ITEM_TYPE_INDICES[type] if fitsType == 'myVehicle': vehicle = g_itemsCache.items.getItemByCD(int(compact)) requestCriteria |= REQ_CRITERIA.VEHICLE.SUITABLE([vehicle], [itemTypeID]) elif fitsType != 'otherVehicles': requestCriteria |= REQ_CRITERIA.VEHICLE.SUITABLE(inventoryVehicles, [itemTypeID]) return (itemTypeID, requestCriteria, inventoryVehicles, checkExtra, extra)
def updateVehicles(self, resetPos = False): Waiting.show('updateMyVehicles') filterCriteria = REQ_CRITERIA.INVENTORY if self.vehiclesFilter['nation'] != -1: filterCriteria |= REQ_CRITERIA.NATIONS([self.vehiclesFilter['nation']]) if self.vehiclesFilter['tankType'] != 'none': filterCriteria |= REQ_CRITERIA.VEHICLE.CLASSES([self.vehiclesFilter['tankType']]) if self.vehiclesFilter['ready']: filterCriteria |= REQ_CRITERIA.VEHICLE.FAVORITE items = g_itemsCache.items newVehs = items.getVehicles(REQ_CRITERIA.INVENTORY) filteredVehs = items.getVehicles(filterCriteria) vehsData = [] def sorting(v1, v2): if v1.isFavorite and not v2.isFavorite: return -1 if not v1.isFavorite and v2.isFavorite: return 1 return v1.__cmp__(v2) for vehicle in sorted(filteredVehs.itervalues(), sorting): try: vState, vStateLvl = vehicle.getState() v = {'id': vehicle.invID, 'inventoryId': vehicle.invID, 'label': vehicle.userName, 'image': vehicle.icon, 'nation': vehicle.nationID, 'level': vehicle.level, 'stat': vState, 'stateLevel': vStateLvl, 'doubleXPReceived': vehicle.dailyXPFactor, 'compactDescr': vehicle.intCD, 'favorite': vehicle.isFavorite, 'canSell': vehicle.canSell, 'clanLock': vehicle.clanLock, 'elite': vehicle.isElite, 'premium': vehicle.isPremium, 'tankType': vehicle.type, 'exp': vehicle.xp, 'current': 0, 'enabled': True} except Exception: LOG_ERROR("Exception while '%s' vehicle processing" % vehicle.descriptor.type.name) LOG_CURRENT_EXCEPTION() continue vehsData.append(v) self.as_vehiclesResponseS({'slotPrice': items.shop.getVehicleSlotsPrice(items.stats.vehicleSlots), 'availableSlotsForBuy': items.stats.vehicleSlots - len(newVehs), 'allTanksCount': len(newVehs), 'selectedTankID': g_currentVehicle.invID, 'slots': vehsData}) isVehTypeLock = sum((len(v) for v in items.stats.vehicleTypeLocks.itervalues())) isGlobalVehLock = sum((len(v) for v in items.stats.globalVehicleLocks.itervalues())) if self.__updateVehiclesTimerId is None and (isVehTypeLock or isGlobalVehLock): self.__updateVehiclesTimerId = BigWorld.callback(self.UPDATE_LOCKS_PERIOD, self.updateLockTimers) LOG_DEBUG('Lock timer updated') Waiting.hide('updateMyVehicles') return
def getInventoryVehicles(self): nodeCDs = map(lambda node: node['id'], self._getNodesToInvalidate()) LOG_DEBUG('getInventoryVehicles', nodeCDs) vehicles = self._items.getVehicles(REQ_CRITERIA.INVENTORY | REQ_CRITERIA.IN_CD_LIST(nodeCDs)) return dict(map(lambda item: (item.inventoryID, item), vehicles.itervalues()))