def __validateCustomization(self): for intCD, dossier in self.itemsCache.items.getVehicleDossiersIterator( ): _, nationID, _ = parseIntCompactDescr(intCD) customization = vehicles.g_cache.customization(nationID) camouflages = customization['camouflages'] inscriptions = customization['inscriptions'] emblems = vehicles.g_cache.playerEmblems()[1] for camoID in list(dossier['camouflages']): if camoID not in camouflages: raise ValidateException( 'Invalid camounflage for vehicle %s' % intCD, self.CODES.DOSSIER_CAMOUFLAGES_ERROR, ('camouflage', camoID)) for insID in list(dossier['inscriptions']): if insID not in inscriptions: raise ValidateException( 'Invalid insription for vehicle %s' % intCD, self.CODES.DOSSIER_INSCRIPTIONS_ERROR, ('inscription', insID)) for emblemID in list(dossier['emblems']): if emblemID not in emblems: raise ValidateException( 'Invalid emblem for vehicle %s' % intCD, self.CODES.DOSSIER_EMBLEMS_ERROR, ('emblem', emblemID))
def splitIntDescr(intDescr): itemType, customizationType, id = items.parseIntCompactDescr(intDescr) if itemType != 12 or customizationType not in CustomizationType.RANGE: raise SoftException( 'intDescr is not correct customization item int descriptor', intDescr) return (customizationType, id)
def __getLeaguesData(self): leaguesRewardsData = self.__rankedController.getLeagueRewards() result = [] formatter = getRankedAwardsFormatter() def findAndPreformatBonus(awards, bonusName): bonus = findFirst(lambda x: x.getName() == bonusName, awards) if bonus is not None: bonus = first(formatter.getPreformattedBonuses([bonus])) return bonus for data in leaguesRewardsData: leagueID = data['league'] awards = data['awards'] badgeBonus = findAndPreformatBonus(awards, 'dossier') styleBonus = findAndPreformatBonus(awards, 'customizations') if leagueID and styleBonus and badgeBonus: isCurrent = self.__rankedController.getWebSeasonProvider( ).seasonInfo.league == leagueID styleCD = styleBonus.specialArgs[0] style = self.__itemsCache.items.getItemByCD(styleCD) _, _, styleID = parseIntCompactDescr(styleCD) self.__styleDescriptions[styleID] = backport.text( R.strings.ranked_battles.rewardsView.tabs.leagues. description.dyn('league%s' % leagueID)()) badgeID = badgeBonus.specialArgs[0] result.append( rewards_vos.getLeagueRewardVO(leagueID, styleBonus, styleID, style.userName, badgeID, isCurrent)) _logger.error('Invalid awards or leagueID in quests') return result
def __getCustomizationsData(self, intCD): _, cType, idx = parseIntCompactDescr(intCD) customizationInvData = self.getCacheValue(GUI_ITEM_TYPE.CUSTOMIZATION, {}) itemsInvData = customizationInvData.get(CustomizationInvData.ITEMS, {}) typeInvData = itemsInvData.get(cType, {}) return typeInvData.get(idx, {})
def getC11nItemAppliedVehicles(self, itemCD): _, itemType, itemId = parseIntCompactDescr(itemCD) path = (GUI_ITEM_TYPE.CUSTOMIZATION, CustomizationInvData.DRESSED, itemType, itemId) vehs = self.getCacheValueByPath(path, defaultValue={}) return vehs.keys()
def _getItemByCompactDescr(compactDescr): itemTypeID, nationID, compTypeID = parseIntCompactDescr(compactDescr) items = None if itemTypeID == ITEM_TYPES.crewSkin: items = g_cache.crewSkins().skins elif itemTypeID == ITEM_TYPES.crewBook: items = g_cache.crewBooks().books return items[compTypeID]
def __getVehicleDescr(self, vehicleCD=None, vehicleName=None): if vehicleCD is not None: itemTypeId, nationId, innationId = parseIntCompactDescr(vehicleCD) elif vehicleName is not None: nationId, innationId = vehicles.g_list.getIDsByName(vehicleName) else: _logger.error('Do not specified correct vehicle int cd or vehicle name!') return return vehicles.VehicleDescr(typeID=(nationId, innationId))
def getC11nItemAppliedOnVehicleCount(self, itemCD, vehicleIntCD): _, itemType, itemId = parseIntCompactDescr(itemCD) path = (GUI_ITEM_TYPE.CUSTOMIZATION, CustomizationInvData.DRESSED, itemType, itemId, vehicleIntCD) count = self.getCacheValueByPath(path, defaultValue=0) return count
def buildItem(self, *args, **kwargs): intCD = args[0] itemTypeID, _, _ = parseIntCompactDescr(intCD) if itemTypeID == GUI_ITEM_TYPE.VEHICLE: vehicle = self.getVehicle() return (vehicle, vehicle) module = self.__getProgressionCtrl().getModule(intCD) currentModule = self.__getProgressionCtrl( ).getInstalledOnVehicleAnalogByIntCD(intCD) return (module, currentModule)
def __getModuleInfoPanel(self, intCD): itemTypeID, _, _ = parseIntCompactDescr(intCD) if itemTypeID != GUI_ITEM_TYPE.VEHICLE: module = self.__getModuleItem(intCD) if module is not None: return {'header': getTreeModuleHeader(module), 'parameters': getShortListParameters(module, self.__getProgressionVehicle(), self.__getInstalledOnVehicleAnalogByIntCD(intCD)), 'module': {'icon': getTreeModuleIcon(module), 'available': True}} return
def itemsFilter(items): filtered = {} for itemCD, count in items.items(): itemTypeID, _, _ = parseIntCompactDescr(itemCD) if any( (condition(itemTypeID, itemCD) for condition in conditions)): filtered[itemCD] = count del items[itemCD] return filtered
def sellAll(self): itemSellSpecs = [] for item in self._dataProvider.collection: if item['selected']: intCD = item['id'] count = item['count'] typeIdx, _, _ = parseIntCompactDescr(intCD) itemSellSpecs.append(ItemSellSpec(typeIdx, intCD, count)) ItemsActionsFactory.doAction(ItemsActionsFactory.SELL_MULTIPLE, itemSellSpecs)
def removeItemFromEditableStyle(outfit, baseOutfit, slotId): slotType = slotId.slotType if slotType in EDITABLE_STYLE_APPLY_TO_ALL_AREAS_TYPES: __removeItemFromEditableStyleAllAreas(outfit, baseOutfit, slotType) if slotType == GUI_ITEM_TYPE.CAMOUFLAGE: slotData = getSlotDataFromSlot(outfit, slotId) parsedData = parseIntCompactDescr(compactDescr=slotData.intCD) for _, uSlotId in getUnsuitableDependentData(outfit, parsedData[2], outfit.style.dependencies): __doItemRemoveFromEditableStyleOutfit(outfit, baseOutfit, uSlotId, True) else: __removeItemFromEditableStyleOutfit(outfit, baseOutfit, slotId)
def checkSlotCompatibility(self, compDescr=None, descr=None): if compDescr is None and descr is None: raise SoftException( "One of 'compDescr' or 'descr' arguments must be specified.") if compDescr is None: compDescr = descr.compactDescr itemTypeID, nationID, itemID = parseIntCompactDescr(compDescr) return ( False, 'Item type of slot ({}) does not match type of item ({})'.format( self.itemType, itemTypeID) ) if itemTypeID != self.itemType else self._checkSlotCompatibility( (itemTypeID, nationID, itemID), descr)
def openBarracks(self, cmd): location = intCD = cmd.location if isinstance(location, int): nationID, location = parseIntCompactDescr(location)[1:] tankType = first( self.__itemsCache.items.getVehicles( _makeCriteria(intCD)).values()).type role = cmd.role or _ALL else: nationID, location = None, _LOCATION.get(location) tankType = cmd.tank_type role = cmd.role shared_events.showBarracks(location, nationID, tankType, role) return
def updateC11nProgressionDataForItem(self, itemIntCD): if not self.__c11nProgressionData: self.updateC11nProgressionData() return if itemIntCD in self.__c11nProgressionData: del self.__c11nProgressionData[itemIntCD] customizationInvData = self.getCacheValue(GUI_ITEM_TYPE.CUSTOMIZATION, {}) itemsInvData = customizationInvData.get(CustomizationInvData.PROGRESSION, {}) _, cType, idx = parseIntCompactDescr(itemIntCD) if cType in itemsInvData: typeInvData = itemsInvData[cType] if idx in typeInvData: itemData = typeInvData[idx] self.__updateC11nProgressionDataForItem(itemIntCD, itemData)
def __init__(self, intCompactDescr, proxy=None): super(CrewSkin, self).__init__(intCompactDescr, proxy) self.__freeCount = 0 self.__tankmenIDs = set() _, _, self.__id = parseIntCompactDescr(intCompactDescr) if proxy is not None and proxy.inventory.isSynced(): self.__freeCount = proxy.inventory.getItems( GUI_ITEM_TYPE.CREW_SKINS, self.__id) allTankmen = proxy.getTankmen() self.__tankmenIDs = { invID for invID, tankman in allTankmen.iteritems() if tankman.skinID != NO_CREW_SKIN_ID and tankman.skinID == self.__id } return
def _isValidTankmanLocation(_, data, itemsCache=None): loc = data.get('location') if loc in _LOCATION: return True if isinstance(loc, int): intCD = loc itemTypeID = first(parseIntCompactDescr(intCD)) if itemTypeID != ITEM_TYPES.vehicle: raise WebCommandException( 'intCD: %d is not valid value for "location",vehicle with this descriptor are not exists', intCD) vehicles = itemsCache.items.getVehicles(_makeCriteria(intCD)) if not vehicles: raise WebCommandException( 'intCD: %d is not valid value for "location",vehicle with this descriptor are not in the inventory', intCD) return True raise WebCommandException('"%s" is not valid value for "location"', loc)
def parseCompactDescr(compDescr): itemTypeId, _, idxWithinItemType = parseIntCompactDescr(compDescr) return (itemTypeId, idxWithinItemType)
def getTankName(vehCompactDesc): itemTypeID, nationId, vehId = parseIntCompactDescr(vehCompactDesc) tank = g_cache.vehicle(nationId, vehId) return tank.name
def getVehicleLevel(vehTypeCompDescr): _, nationID, innationID = parseIntCompactDescr(vehTypeCompDescr) return vehicles.g_list.getList(nationID)[innationID].level
def splitIntDescr(intDescr): """Split int item descriptor to (customizationType, itemId) tuple.""" itemType, customizationType, id = items.parseIntCompactDescr(intDescr) if itemType != 12 or customizationType not in CustomizationType.RANGE: raise ValueError('intDescr is not correct customization item int descriptor', intDescr) return (customizationType, id)
def __doesVehicleExist(self, vehIntCD): itemTypeID, _, _ = parseIntCompactDescr(vehIntCD) return True if itemTypeID == GUI_ITEM_TYPE.VEHICLE else False
def getC11nSerialNumber(self, itemCD): _, itemType, itemID = parseIntCompactDescr(itemCD) path = (GUI_ITEM_TYPE.CUSTOMIZATION, CustomizationInvData.SERIAL_NUMBERS, itemType, itemID, 'serial_number') return self.getCacheValueByPath(path)