def calcExpected(self, newIdNum): v = vehiclesWG.getVehicleType(newIdNum) newTier = v.level newType = set(vehiclesWG.VEHICLE_CLASS_TAGS.intersection(v.tags)).pop() if newTier < 1 or newTier > 10: newTier = 10 tierExpected = {} tierExpectedCount = 0.0 typeExpected = {} typeExpectedCount = 0.0 for idNum in self.expectedValues: try: vt = vehiclesWG.getVehicleType(idNum) except: continue if vt.level == newTier: tierExpectedCount += 1 vType = set(vehiclesWG.VEHICLE_CLASS_TAGS.intersection(vt.tags)).pop() if vType == newType: typeExpectedCount += 1 for key in self.expectedValues[idNum]: tierExpected[key] = tierExpected.get(key, 0) + self.expectedValues[idNum].get(key, 0.0) if vType == newType: typeExpected[key] = typeExpected.get(key, 0) + self.expectedValues[idNum].get(key, 0.0) if typeExpectedCount > 0: for key in typeExpected: typeExpected[key] /= typeExpectedCount self.expectedValues[newIdNum] = typeExpected.copy() return for key in tierExpected: tierExpected[key] /= tierExpectedCount self.expectedValues[newIdNum] = tierExpected.copy()
def __vehiclesComparator(self, item, other): res = 0 iKiller = item.get('killerID', 0) cd = item.get('typeCompDescr') if cd is not None: iType = vehicles_core.getVehicleType(cd) iLevel = iType.level if iType else -1 iWeight = VEHICLE_BATTLE_TYPES_ORDER_INDICES.get(set(VEHICLE_CLASS_TAGS.intersection(iType.tags)).pop(), 10) if iType else 10 else: iLevel = -1 iWeight = 10 oKiller = other.get('killerID', 0) cd = other.get('typeCompDescr') if cd is not None: oType = vehicles_core.getVehicleType(other.get('typeCompDescr', None)) oLevel = oType.level if oType else -1 oWeight = VEHICLE_BATTLE_TYPES_ORDER_INDICES.get(set(VEHICLE_CLASS_TAGS.intersection(oType.tags)).pop(), 10) if oType else 10 else: oLevel = -1 oWeight = 10 if iKiller == 0 and oKiller == 0 or iKiller != 0 and oKiller != 0: res = cmp(oLevel, iLevel) or cmp(iWeight, oWeight) or cmp(item.get('vehicleName', ''), other.get('vehicleName', '')) elif not iKiller: res = -1 else: res = 1 return res
def __getDataExtra(blockType, blockName, fieldType, dossier, isTotal=False, isCompact=False): extra = '' if blockType == 'common': if fieldType != 'battlesCount' and dossier['a15x15'][ 'battlesCount'] != 0: extra = '(%d%%)' % round( float(dossier[blockName][fieldType]) / dossier['a15x15']['battlesCount'] * 100) if isTotal: if fieldType == 'maxFrags' and dossier['max15x15']['maxFrags'] != 0: extra = getVehicleType( dossier['max15x15']['maxFragsVehicle'] ).userString if not isCompact else getVehicleType( dossier['max15x15']['maxFragsVehicle']).shortUserString if fieldType == 'maxXP' and dossier['max15x15']['maxXP'] != 0: extra = getVehicleType( dossier['max15x15']['maxXPVehicle'] ).userString if not isCompact else getVehicleType( dossier['max15x15']['maxXPVehicle']).shortUserString return extra
def __getDataExtra(blockType, blockName, fieldType, dossier): extra = '' if blockType == 'common': if fieldType != 'battlesCount' and dossier['a15x15']['battlesCount'] != 0: extra = '(%d%%)' % round(float(dossier[blockName][fieldType]) / dossier['a15x15']['battlesCount'] * 100) if fieldType == 'maxFrags' and dossier['max15x15']['maxFrags'] != 0: extra = getVehicleType(dossier['max15x15']['maxFragsVehicle']).shortUserString if fieldType == 'maxXP' and dossier['max15x15']['maxXP'] != 0: extra = getVehicleType(dossier['max15x15']['maxXPVehicle']).shortUserString return extra
def __getDataExtra(blockType, fieldType, dossier, isTotal = False, isCompact = False): extra = '' if blockType == 'common': if fieldType != 'battlesCount' and dossier['a15x15']['battlesCount'] != 0: extra = '(%d%%)' % round(float(dossier[fieldType]) / dossier['a15x15']['battlesCount'] * 100) if isTotal: if fieldType == 'maxFrags' and dossier['max15x15']['maxFrags'] != 0: extra = getVehicleType(dossier['max15x15']['maxFragsVehicle']).userString if not isCompact else getVehicleType(dossier['max15x15']['maxFragsVehicle']).shortUserString if fieldType == 'maxXP' and dossier['max15x15']['maxXP'] != 0: extra = getVehicleType(dossier['max15x15']['maxXPVehicle']).userString if not isCompact else getVehicleType(dossier['max15x15']['maxXPVehicle']).shortUserString return extra
def getSelectedSkills(self, vehicleCD): selected = self.__itemsCache.items.epicMetaGame.selectedSkills(vehicleCD) numSlots = self.getNumAbilitySlots(vehicles.getVehicleType(vehicleCD)) while len(selected) < numSlots: selected.append(-1) return selected
def __showStylePreview(self, styleID): styledVehicleCD = None minLvl, _ = self.__rankedController.getSuitableVehicleLevels() if g_currentVehicle.isPresent() and g_currentVehicle.item.level >= minLvl: styledVehicleCD = g_currentVehicle.item.intCD else: accDossier = self.__itemsCache.items.getAccountDossier() vehicles = accDossier.getRankedStats().getVehicles() if not vehicles: vehicles = accDossier.getRandomStats().getVehicles() if vehicles: sortedVehicles = sorted(vehicles.items(), key=lambda vStat: vStat[1].battlesCount, reverse=True) for vehicleCD, _ in sortedVehicles: vehicleType = getVehicleType(vehicleCD) if vehicleType.level >= minLvl: styledVehicleCD = vehicleCD break if not styledVehicleCD: vehiclesPool = AccountSettings.getSettings(RANKED_STYLED_VEHICLES_POOL) if not vehiclesPool: vehiclesPool = list(_DEFAULT_STYLED_VEHICLES) vehicleName = vehiclesPool.pop(0) styledVehicleCD = VehicleDescriptor(typeName=vehicleName).type.compactDescr vehiclesPool.append(vehicleName) AccountSettings.setSettings(RANKED_STYLED_VEHICLES_POOL, vehiclesPool) styleDescr = self.__styleDescriptions.get(styleID, '') style = first(self.__itemsCache.items.getStyles(REQ_CRITERIA.CUSTOM(lambda item: item.id == styleID)).values()) showStylePreview(styledVehicleCD, style, styleDescr, self._backToLeaguesCallback) return
def updateRespawnVehicles(self, vehsList): self.__vehicles = [] for v in vehsList: descr = vehicles.getVehicleType(v['compDescr']) self.__vehicles.append(_Vehicle(descr.compactDescr, descr, v['settings'])) self.onRespawnVehiclesUpdated(self.__vehicles)
def updateMessage(self): if not self.configIsValid: self.message = 'stat_config.json is not valid' return (self.values, self.gradient, self.palette) = self.calcWN8(self.battles) bg = self.config.get('bgIcon', '') self.bgIcon = self.formatString(bg, self.values, self.gradient, self.palette) msg = '\n'.join(self.config.get('template','')) msg = self.formatString(msg, self.values, self.gradient, self.palette) self.messageGeneral = msg msg = self.config.get('byTankTitle','') tankStat = {} for battle in self.battles: idNum = battle['idNum'] if tankStat.has_key(idNum): tankStat[idNum].append(battle) else: tankStat[idNum] = [battle] for idNum in sorted(tankStat.keys(), key = lambda idNum: len(tankStat[idNum]), reverse = True): row = self.config.get('byTankRow','') (values, gradient, palette) = self.calcWN8(tankStat[idNum]) vt = vehiclesWG.getVehicleType(idNum) row = row.replace('{{vehicle}}', vt.shortUserString) name = vt.name.replace(':', '-') row = row.replace('{{vehicle-name}}', name) row = self.formatString(row, values, gradient, palette) msg += '\n' + row self.messageByTank = msg
def eff(self, params): if isinstance(params, dict): id = params.get('id', 0) if 'id' in params else params.get( LONG_TAGS['id'], 0) allBAT = params.get('b', 0) if 'b' in params else params.get( LONG_TAGS['b'], 0) allDMG = params.get('dmg', 0) if 'dmg' in params else params.get( LONG_TAGS['dmg'], 0) allFRG = params.get('frg', 0) if 'frg' in params else params.get( LONG_TAGS['frg'], 0) allSPO = params.get('spo', 0) if 'spo' in params else params.get( LONG_TAGS['spo'], 0) allCAP = params.get('cap', 0) if 'cap' in params else params.get( LONG_TAGS['cap'], 0) allDEF = params.get('def', 0) if 'def' in params else params.get( LONG_TAGS['def'], 0) if id and allBAT: vehicle = vehicles.getVehicleType(int(id)) if vehicle: avgTIER = vehicle.level avgDMG = float(allDMG) / allBAT avgFRG = float(allFRG) / allBAT avgSPO = float(allSPO) / allBAT avgCAP = float(allCAP) / allBAT avgDEF = float(allDEF) / allBAT return 10 * (0.23 + 2.0 * avgTIER / 100.0) / ( avgTIER + 2.0 ) * avgDMG + 250 * avgFRG + 150 * avgSPO + 150 * log( avgCAP + 1, 1.732) + 150 * avgDEF
def new_brf_format(self, message, *args): result = old_brf_format(self, message, *args) arenaUniqueID = message.data.get('arenaUniqueID', 0) stat.queue.put(arenaUniqueID) if stat.config.get('enableBattleEndedMessage', True) and hasattr(BigWorld.player(), 'arena'): if BigWorld.player().arena.arenaUniqueID != arenaUniqueID: isWinner = message.data.get('isWinner', 0) battleEndedMessage = '' if isWinner < 0: battleEndedMessage = stat.config.get('battleEndedMessageDefeat', '') elif isWinner > 0: battleEndedMessage = stat.config.get('battleEndedMessageWin', '') else: battleEndedMessage = stat.config.get('battleEndedMessageDraw', '') battleEndedMessage = battleEndedMessage.encode('utf-8') vehicleCompDesc = message.data.get('vehTypeCompDescr', None) vt = vehiclesWG.getVehicleType(vehicleCompDesc) battleEndedMessage = battleEndedMessage.replace('{{vehicle}}', vt.userString) name = vt.name.replace(':', '-') battleEndedMessage = battleEndedMessage.replace('{{vehicle-name}}', name) arenaTypeID = message.data.get('arenaTypeID', 0) arenaType = ArenaType.g_cache[arenaTypeID] arenaName = i18n.makeString(arenaType.name) battleEndedMessage = battleEndedMessage.replace('{{map}}', arenaName) battleEndedMessage = battleEndedMessage.replace('{{map-name}}', arenaType.geometryName) MessengerEntry.g_instance.gui.addClientMessage(battleEndedMessage) return result
def getGunCompatibles(self, itemDescr, _=None): avgParams = dict( self.__getParamFromCache(itemDescr['compactDescr'], 'avgParams', default={})) allVehiclesNames = self.__getComponentVehiclesNames( itemDescr['compactDescr']) clipVehiclesCD_List = self.__getParamFromCache( itemDescr['compactDescr'], CLIP_VEHICLES_PROP_NAME, default=tuple()) normalVehicles = [] clipVehiclesNames = [] for clipV_CD in clipVehiclesCD_List: userFriendlyVehicleName = getVehicleType(clipV_CD).userString clipVehiclesNames.append(userFriendlyVehicleName) if userFriendlyVehicleName in allVehiclesNames: allVehiclesNames.remove(userFriendlyVehicleName) return { 'vehicles': allVehiclesNames, SHELLS_PROP_NAME: avgParams.get(SHELLS_PROP_NAME, tuple()), 'turrets': self.__getParamFromCache(itemDescr['compactDescr'], 'turrets', default=tuple()), CLIP_VEHICLES_PROP_NAME: clipVehiclesNames, CLIP_VEHICLES_CD_PROP_NAME: clipVehiclesCD_List }
def getDossierVehicleList(dossier, isOnlyTotal=False): battlesCount = float(dossier['a15x15']['battlesCount']) winsCount = float(dossier['a15x15']['wins']) data = [ 'ALL', '#menu:profile/list/totalName', None, 0, -1, __getData('battlesCount', dossier), '%d%%' % round(100 * winsCount / battlesCount) if battlesCount != 0 else '', 0 ] if not isOnlyTotal: vehList = dossier['a15x15Cut'].items() vehList.sort(cmp=__dossierComparator) for vehTypeCompactDesr, battles in vehList: try: vehType = getVehicleType(vehTypeCompactDesr) data.append(vehTypeCompactDesr) data.append(vehType.userString) data.append(_ICONS_MASK % vehType.name.replace(':', '-')) data.append(vehType.level) data.append(vehType.id[0]) data.append(battles[0]) data.append('%d%%' % round(100 * float(battles[1]) / battles[0]) if battles[0] != 0 else '') data.append(battles[2]) except Exception: LOG_ERROR('Get vehicle info error vehTypeCompactDesr: %s' % str(vehTypeCompactDesr)) LOG_CURRENT_EXCEPTION() return data
def __onDropVehicleCamouflage(self, resultID, kind): if resultID < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return else: item = self.currentItemsByKind.get(kind) hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, item.get('id'), self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SUCCESS) if g_tankActiveCamouflage.has_key(g_currentVehicle.item.intCD): del g_tankActiveCamouflage[g_currentVehicle.item.intCD] newID = None newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: camouflages = g_currentVehicle.item.descriptor.camouflages camo = camouflages[kind] if camo[0] is not None: newID = camo[0] newLifeCycle = (camo[1], camo[2]) item['id'] = newID item['lifeCycle'] = newLifeCycle if CAMOUFLAGE_KINDS.get(self._itemsDP.currentGroup) == kind: self._itemsDP.currentItemID = newID self.onCustomizationDropSuccess(message) return
def getDossierVehicleList(dossier, isOnlyTotal = False): battlesCount = float(dossier['a15x15']['battlesCount']) winsCount = float(dossier['a15x15']['wins']) data = ['ALL', '#menu:profile/list/totalName', None, 0, -1, __getData('battlesCount', dossier), '%d%%' % round(100 * winsCount / battlesCount) if battlesCount != 0 else '', 0] if not isOnlyTotal: vehList = dossier['a15x15Cut'].items() vehList.sort(cmp=__dossierComparator) for vehTypeCompactDesr, battles in vehList: try: vehType = getVehicleType(vehTypeCompactDesr) data.append(vehTypeCompactDesr) data.append(vehType.userString) data.append(_ICONS_MASK % vehType.name.replace(':', '-')) data.append(vehType.level) data.append(vehType.id[0]) data.append(battles[0]) data.append('%d%%' % round(100 * float(battles[1]) / battles[0]) if battles[0] != 0 else '') data.append(battles[2]) except Exception: LOG_ERROR('Get vehicle info error vehTypeCompactDesr: %s' % str(vehTypeCompactDesr)) LOG_CURRENT_EXCEPTION() return data
def __setVehicleData(self, vehicleDescr = None): if vehicleDescr is not None: vehicleType = vehicleDescr.type if getArenaGuiType() == ARENA_GUI_TYPE.HISTORICAL and getattr(vehicleType, 'historicalModelOf', None): vehicleType = getVehicleType(vehicleType.historicalModelOf) self.compactDescr = vehicleType.compactDescr tags = vehicleType.tags self.classTag = _getClassTag(tags) self.isObserver = _isObserver(tags) self.shortName = vehicleType.shortUserString self.name = Vehicle.getUserName(vehicleType=vehicleType, textPrefix=True) self.shortNameWithPrefix = Vehicle.getShortUserName(vehicleType=vehicleType, textPrefix=True) self.guiName = getShortUserName(vehicleType) self.nationID = vehicleType.id[0] self.level = vehicleType.level vName = vehicleType.name self.iconPath = settings.makeContourIconSFPath(vName) if not fo_precache.add(settings.makeContourIconResPath(vName)): self.iconPath = settings.UNKNOWN_CONTOUR_ICON_SF_PATH else: self.compactDescr = 0 self.classTag = None self.isObserver = False self.shortName = settings.UNKNOWN_VEHICLE_NAME self.name = settings.UNKNOWN_VEHICLE_NAME self.guiName = settings.UNKNOWN_VEHICLE_NAME self.shortNameWithPrefix = settings.UNKNOWN_VEHICLE_NAME self.nationID = nations.NONE_INDEX self.level = settings.UNKNOWN_VEHICLE_LEVEL self.iconPath = settings.UNKNOWN_CONTOUR_ICON_SF_PATH self.shortNameWithPrefix = settings.UNKNOWN_VEHICLE_NAME return
def __onDropVehicleInscription(self, resultID): if resultID < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return else: newID = None newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: inscriptions = g_currentVehicle.item.descriptor.playerInscriptions inscr = inscriptions[self.getRealPosition()] if inscr[0] is not None: newID = inscr[0] newLifeCycle = (inscr[1], inscr[2]) hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.INSCRIPTION_TYPE, self._currentItemID, self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_INSCRIPTION_DROP_SUCCESS) self._currentItemID = newID self._currentLifeCycle = newLifeCycle self._itemsDP.currentItemID = newID self.updateVehicleCustomization(newID) self.onCustomizationDropSuccess(message) return
def _vehicleHeaderCreator(vehicleCDStr): vehicleCD = int(vehicleCDStr) vehicle = getVehicleType(vehicleCD) title = vehicle.shortUserString iconPath = 'premium' if bool('premium' in vehicle.tags) else 'simple' txtLevel = int2roman(vehicle.level) return (title, iconPath, txtLevel)
def checkVehicleLevel(self, vehTypeCompDescr): vehType = vehicles.getVehicleType(vehTypeCompDescr) level = vehType.level if level < self.SLOT_TYPE.DEFAULT_LEVELS[ 0] or level > self.SLOT_TYPE.DEFAULT_LEVELS[1]: return False return True
def __onDropVehicleCamouflage(self, resultID, kind): if resultID < 0: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return item = self.currentItemsByKind.get(kind) hangarItem = CustomizationHelper.getItemFromHangar(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, item.get('id'), self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString(SYSTEM_MESSAGES.CUSTOMIZATION_CAMOUFLAGE_DROP_SUCCESS) if g_tankActiveCamouflage.has_key(g_currentVehicle.item.intCD): del g_tankActiveCamouflage[g_currentVehicle.item.intCD] newID = None newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: camouflages = g_currentVehicle.item.descriptor.camouflages camo = camouflages[kind] if camo[0] is not None: newID = camo[0] newLifeCycle = (camo[1], camo[2]) item['id'] = newID item['lifeCycle'] = newLifeCycle if CAMOUFLAGE_KINDS.get(self._itemsDP.currentGroup) == kind: self._itemsDP.currentItemID = newID self.onCustomizationDropSuccess(message)
def __onDropVehicleEmblem(self, resultID): if resultID < 0: message = i18n.makeString( SYSTEM_MESSAGES.CUSTOMIZATION_EMBLEM_DROP_SERVER_ERROR) self.onCustomizationDropFailed(message) return else: newID = self.defaultPlayerEmblemID newLifeCycle = None if gui.game_control.g_instance.igr.getRoomType() != IGR_TYPE.NONE: emblems = g_currentVehicle.item.descriptor.playerEmblems emblem = emblems[self.getRealPosition()] if emblem[0] is not None: newID = emblem[0] newLifeCycle = (emblem[1], emblem[2]) hangarItem = CustomizationHelper.getItemFromHangar( CUSTOMIZATION_ITEM_TYPE.EMBLEM_TYPE, self._currentItemID, self._nationID) if hangarItem: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = i18n.makeString( SYSTEM_MESSAGES.CUSTOMIZATION_EMBLEM_STORED_SUCCESS, vehicle=vehicle.userString) else: message = i18n.makeString( SYSTEM_MESSAGES.CUSTOMIZATION_EMBLEM_DROP_SUCCESS) self._currentItemID = newID self._currentLifeCycle = newLifeCycle self._itemsDP.currentItemID = newID self.updateVehicleCustomization(newID) self.onCustomizationDropSuccess(message) self.onCurrentItemChange(self._name) return
def XTE(self, params): if isinstance(params, dict): typesBAT = {} typesUNP = {} LEVELS = range(1,11) for tag in vehicles.VEHICLE_CLASS_TAGS: typesBAT[tag] = {} typesUNP[tag] = {} for level in LEVELS: typesBAT[tag][level] = typesUNP[tag][level] = 0 for id, stat in params.items(): allBAT = stat.get('b', 0) if 'b' in stat else stat.get(LONG_TAGS['b'], 0) allDMG = stat.get('dmg', 0) if 'dmg' in stat else stat.get(LONG_TAGS['dmg'], 0) allFRG = stat.get('frg', 0) if 'frg' in stat else stat.get(LONG_TAGS['frg'], 0) if allBAT >= 10 and allDMG and allFRG: if 'id' not in stat: stat['id'] = int(id) xte = self.xte(stat) vehicle = vehicles.getVehicleType(int(id)) if vehicle and xte: tag = getVehicleClassTag(vehicle.tags) typesBAT[tag][vehicle.level] += allBAT typesUNP[tag][vehicle.level] += float(allBAT) / (100 - self.specificRating(xte, 'sup')) tags = finalUNP = 0 for tag in typesBAT: levels = levelsUNP = 0 for level in typesBAT[tag]: if typesBAT[tag][level]: levelsUNP += typesUNP[tag][level] * level / typesBAT[tag][level] levels += level if levels: finalUNP += levelsUNP / levels tags += 1 return self.globalRating(100 - tags / finalUNP, 'sup', True) if finalUNP else 0.0
def checkVehicleLevel(self, vehTypeCompDescr): vehClass = vehicles.getVehicleClass(vehTypeCompDescr) vehClassIdx = VEHICLE_CLASS_INDICES[vehClass] vehLevel = vehicles.getVehicleType(vehTypeCompDescr).level if not self.limits.checkVehicleLevel(vehClassIdx, vehLevel): return False return False if not self.SLOT_TYPE.DEFAULT_LEVELS[ 0] <= vehLevel <= self.SLOT_TYPE.DEFAULT_LEVELS[1] else True
def getVehiclesData(self): result = [] for vCD in self.__vehiclesCompDescrs: vType = vehicles.getVehicleType(vCD) classTag = tuple(vehicles.VEHICLE_CLASS_TAGS & vType.tags)[0] result.append(self.VehicleData(vType.userString, vType.id[0], vType.level, classTag)._asdict()) return result
def _processVehiclesList(self, vehIntCDs): vehStrList = [] for intCD in vehIntCDs: vehicle = vehicles.getVehicleType(int(intCD)) if vehicle and VEHICLE_TAGS.SECRET not in vehicle.tags: vehStrList.append(vehicle.shortUserString) return vehStrList
def isValidFragment(maybeFragment, defaultUnlocks=()): if type(maybeFragment) in (int, long): if maybeFragment & 15 == 1 and defaultUnlocks: vehType = vehicles.getVehicleType(maybeFragment) if not vehType.isCollectorVehicle: return maybeFragment not in defaultUnlocks else: return maybeFragment & 15 in BlueprintTypes.ALL return False
def checkVehicleLevel(self, vehTypeCompDescr): vehClass = vehicles.getVehicleClass(vehTypeCompDescr) vehClassIdx = VEHICLE_CLASS_INDICES[vehClass] vehLevel = vehicles.getVehicleType(vehTypeCompDescr).level if not self.limits.checkVehicleLevel(vehClassIdx, vehLevel): return False if not self.SLOT_TYPE.DEFAULT_LEVELS[0] <= vehLevel <= self.SLOT_TYPE.DEFAULT_LEVELS[1]: return False return True
def _showMessage(self, scope, msg, itemCD, msgType = SystemMessages.SM_TYPE.Error, **kwargs): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) if itemTypeID == _VEHICLE: key = scope('vehicle', msg) kwargs['userString'] = vehicles.getVehicleType(itemCD).userString else: key = scope('item', msg) kwargs.update({'typeString': getTypeInfoByIndex(itemTypeID)['userString'], 'userString': vehicles.getDictDescr(itemCD)['userString']}) SystemMessages.pushMessage(i18n.makeString(key, **kwargs), type=msgType)
def getVehiclesData(self): result = [] for vCD in self.__vehiclesCompDescrs: vType = vehicles.getVehicleType(vCD) classTag = tuple(vehicles.VEHICLE_CLASS_TAGS & vType.tags)[0] result.append( self.VehicleData(vType.userString, vType.id[0], vType.level, classTag)._asdict()) return result
def __getDataExtra(blockType, blockName, fieldType, dossier, isTotal=False, isCompact=False): extra = "" if blockType == "common": if fieldType != "battlesCount" and dossier["a15x15"]["battlesCount"] != 0: extra = "(%d%%)" % round(float(dossier[blockName][fieldType]) / dossier["a15x15"]["battlesCount"] * 100) if isTotal: if fieldType == "maxFrags" and dossier["max15x15"]["maxFrags"] != 0: extra = ( getVehicleType(dossier["max15x15"]["maxFragsVehicle"]).userString if not isCompact else getVehicleType(dossier["max15x15"]["maxFragsVehicle"]).shortUserString ) if fieldType == "maxXP" and dossier["max15x15"]["maxXP"] != 0: extra = ( getVehicleType(dossier["max15x15"]["maxXPVehicle"]).userString if not isCompact else getVehicleType(dossier["max15x15"]["maxXPVehicle"]).shortUserString ) return extra
def _getBuyConfirmMeta(self, itemCD, price, conflictedEqs): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) conflictedEqs = self._getConflictedEqsMeta(conflictedEqs).getMessage() ctx = {'credits': BigWorld.wg_getIntegralFormat(price[0]), 'typeString': getTypeInfoByIndex(itemTypeID)['userString'], 'conflictedEqs': conflictedEqs if conflictedEqs else ''} if itemTypeID == _VEHICLE: ctx['userString'] = vehicles.getVehicleType(itemCD).userString else: ctx['userString'] = vehicles.getDictDescr(itemCD)['userString'] return HtmlMessageDialogMeta('html_templates:lobby/dialogs', 'confirmBuyAndInstall', ctx=ctx)
def updateRespawnVehicles(self, vehsList): self.__vehicles = [] def comparator(x, y): xNationID, _ = vehicles.parseVehicleCompactDescr(x['compDescr']) yNationID, _ = vehicles.parseVehicleCompactDescr(y['compDescr']) return nationCompareByIndex(xNationID, yNationID) for v in sorted(vehsList, comparator): descr = vehicles.getVehicleType(v['compDescr']) self.__vehicles.append(_Vehicle(descr.compactDescr, descr, v['vehAmmo']))
def getBattlesStats(self): vehsByType = dict(((t, 0) for t in vehicles.VEHICLE_CLASS_TAGS)) vehsByNation = dict(((idx, 0) for idx, n in enumerate(nations.NAMES))) vehsByLevel = dict(((k, 0) for k in xrange(1, constants.MAX_VEHICLE_LEVEL + 1))) for vehTypeCompDescr, vehCut in self.getVehicles().iteritems(): vehType = vehicles.getVehicleType(vehTypeCompDescr) vehsByNation[vehType.id[0]] += vehCut.battlesCount vehsByLevel[vehType.level] += vehCut.battlesCount vehsByType[set(vehType.tags & vehicles.VEHICLE_CLASS_TAGS).pop()] += vehCut.battlesCount return (vehsByType, vehsByNation, vehsByLevel)
def isTeamValid(accountsInfo, limits): minLevel, maxLevel = limits['level'] tagsLimits = limits['tags'] count = 0 totalLevel = 0 observerCount = 0 vehs = {} for accInfo in accountsInfo.itervalues(): if not accInfo['state'] & PREBATTLE_ACCOUNT_STATE.READY: continue if 'vehTypeCompDescr' not in accInfo or 'vehLevel' not in accInfo: vehDescr = vehicles.VehicleDescr( compactDescr=accInfo['vehCompDescr']) vehLevel = vehDescr.level vehTypeCompDescr = vehDescr.type.compactDescr else: vehLevel = accInfo['vehLevel'] vehTypeCompDescr = accInfo['vehTypeCompDescr'] if not minLevel <= vehLevel <= maxLevel: return (False, 'limits/level') vehTags = vehicles.getVehicleType(vehTypeCompDescr).tags if tagsLimits is not None: isValid, tagSet = tagsLimits for tag in tagSet: if isValid and tag not in vehTags: return (False, 'limits/tags') if not isValid and tag in vehTags: return (False, 'limits/tags') count += 1 observerCount += int('observer' in vehTags) totalLevel += vehLevel vehs[vehTypeCompDescr] = vehs.get(vehTypeCompDescr, 0) + 1 if count < limits['minCount']: return (False, 'limit/minCount') else: if observerCount > 0 and count == observerCount: if not IS_DEVELOPMENT: return (False, 'limit/observerVehicles') LOG_WARNING('Ignoring limit for observers in development mode.') minTotalLevel, maxTotalLevel = limits['totalLevel'] if not minTotalLevel <= totalLevel <= maxTotalLevel: return (False, 'limit/totalLevel') vehicleLimits = limits['vehicles'] if vehicleLimits is not None: for vehTypeCompDescr, (minCount, maxCount) in vehicleLimits.iteritems(): count = vehs.get(vehTypeCompDescr, 0) if not minCount <= count <= maxCount: return (False, 'limits/vehicles') return (True, '')
def _showMessage4Vehicle(self, scope, msg, itemCD, msgType=SystemMessages.SM_TYPE.Error, **kwargs): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) raise itemTypeID == _VEHICLE or AssertionError key = scope('vehicle', msg) kwargs['userString'] = vehicles.getVehicleType(itemCD).userString SystemMessages.pushMessage(i18n.makeString(key, **kwargs), type=msgType)
def _getUnlockConfirmMeta(self, itemCD, costCtx): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) ctx = {'xpCost': BigWorld.wg_getIntegralFormat(costCtx['xpCost']), 'freeXP': BigWorld.wg_getIntegralFormat(costCtx['freeXP']), 'typeString': getTypeInfoByIndex(itemTypeID)['userString']} if itemTypeID == _VEHICLE: key = 'confirmUnlockVehicle' ctx['userString'] = vehicles.getVehicleType(itemCD).userString else: key = 'confirmUnlockItem' ctx['userString'] = vehicles.getDictDescr(itemCD)['userString'] return HtmlMessageLocalDialogMeta('html_templates:lobby/dialogs', key, ctx=ctx)
def avgTIER(self, params): if isinstance(params, dict): avgLevel = battles = 0 for id, value in params.items(): allBAT = value.get('b', 0) if 'b' in value else value.get(LONG_TAGS['b'], 0) vehicle = vehicles.getVehicleType(int(id)) if vehicle: battles += allBAT avgLevel += vehicle.level * allBAT if battles: avgLevel = round(float(avgLevel) / battles, 5) return avgLevel
def getDossierVehicleBlocks(dossier, vehTypeId): vehType = getVehicleType(int(vehTypeId)) data = [makeString('#menu:profile/list/descr', vehType.userString), len(VEHICLE_BLOCKS)] for blockType, fields in VEHICLE_BLOCKS: data.append(blockType) data.append(len(fields)) for fieldType in fields: data.append(fieldType) data.append(__getData(fieldType, dossier)) data.append(__getDataExtra(blockType, fieldType, dossier)) return data
def getC11nProgressionDataForVehicle(self, vehicleIntCD): if not self.__c11nProgressionData: self.updateC11nProgressionData() result = {} vehicleType = vehicles.getVehicleType(vehicleIntCD) for itemIntCD, progressionData in self.__c11nProgressionForVehicle.get(UNBOUND_VEH_KEY, {}).iteritems(): itemDescriptor = vehicles.getItemByCompactDescr(itemIntCD) if not itemDescriptor.filter or itemDescriptor.filter.matchVehicleType(vehicleType): result[itemIntCD] = progressionData result.update(self.__c11nProgressionForVehicle.get(vehicleIntCD, {})) return result
def __init__(self, vehTypeCD, enableException=True): super(VehicleBlueprintFragment, self).__init__(vehTypeCD) vehicleLevel = vehicles.getVehicleType(vehTypeCD).level availableLevels = g_cache.levels if enableException and vehicleLevel not in availableLevels: raise BlueprintsException( 'Invalid vehicle level for having blueprints') self.total, self.progressPerFragment, self.require, self.decays = availableLevels.get( vehicleLevel, (0, 0, (0, 0), (0, 0))) LOG_DEBUG_DEV( '[BPF] VehicleFragment: total={}, progress={}, require={}'.format( self.total, self.progressPerFragment, self.require))
def checkVehicle(self, vehTypeCompDescr): if self.vehTypeCompDescr is not None: return self.vehTypeCompDescr == vehTypeCompDescr else: vehType = vehicles.getVehicleType(vehTypeCompDescr) if not self.nationMask & 1 << vehType.id[0]: return False level = vehType.level if not (self.levels[0] <= level and level <= self.levels[1]): return False classTag = vehicles.getVehicleClass(vehTypeCompDescr) classIndex = VEHICLE_CLASS_INDICES.get(classTag, _BAD_CLASS_INDEX) return False if not self.vehClassMask & 1 << classIndex else True
def isTeamValid(accountsInfo, limits): minLevel, maxLevel = limits['level'] tagsLimits = limits['tags'] count = 0 totalLevel = 0 observerCount = 0 vehs = {} for accInfo in accountsInfo.itervalues(): if not accInfo['state'] & PREBATTLE_ACCOUNT_STATE.READY: continue if 'vehTypeCompDescr' not in accInfo or 'vehLevel' not in accInfo: vehDescr = vehicles.VehicleDescr(compactDescr=accInfo['vehCompDescr']) vehLevel = vehDescr.level vehTypeCompDescr = vehDescr.type.compactDescr else: vehLevel = accInfo['vehLevel'] vehTypeCompDescr = accInfo['vehTypeCompDescr'] if not minLevel <= vehLevel <= maxLevel: return (False, 'limits/level') vehTags = vehicles.getVehicleType(vehTypeCompDescr).tags if tagsLimits is not None: isValid, tagSet = tagsLimits for tag in tagSet: if isValid and tag not in vehTags: return (False, 'limits/tags') if not isValid and tag in vehTags: return (False, 'limits/tags') count += 1 observerCount += int('observer' in vehTags) totalLevel += vehLevel vehs[vehTypeCompDescr] = vehs.get(vehTypeCompDescr, 0) + 1 if count < limits['minCount']: return (False, 'limit/minCount') else: if observerCount > 0 and count == observerCount: if not IS_DEVELOPMENT: return (False, 'limit/observerVehicles') LOG_WARNING('Ignoring limit for observers in development mode.') minTotalLevel, maxTotalLevel = limits['totalLevel'] if not minTotalLevel <= totalLevel <= maxTotalLevel: return (False, 'limit/totalLevel') vehicleLimits = limits['vehicles'] if vehicleLimits is not None: for vehTypeCompDescr, (minCount, maxCount) in vehicleLimits.iteritems(): count = vehs.get(vehTypeCompDescr, 0) if not minCount <= count <= maxCount: return (False, 'limits/vehicles') return (True, '')
def _setVehicle(self, accountDBID, vehTypeCompDescr, vehInvID): classTag = vehicles.getVehicleClass(vehTypeCompDescr) vehType = vehicles.getVehicleType(vehTypeCompDescr) vehClassIdx = VEHICLE_CLASS_INDICES.get(classTag, _BAD_CLASS_INDEX) self._vehicles[accountDBID] = {'vehTypeCompDescr': vehTypeCompDescr, 'vehInvID': vehInvID, 'nationIdx': vehType.id[0], 'inNationIdx': vehType.id[1], 'vehLevel': vehType.level, 'vehClassIdx': vehClassIdx} self.storeOp(UNIT_OP.SET_VEHICLE, accountDBID, vehTypeCompDescr, vehInvID) self._storeNotification(accountDBID, UNIT_NOTIFY_CMD.SET_VEHICLE, [vehInvID]) self._dirty = 1 return True
def getDossierVehicleBlocks(dossier, vehTypeId): vehType = getVehicleType(int(vehTypeId)) data = [ makeString('#menu:profile/list/descr', vehType.userString), len(VEHICLE_BLOCKS) ] for blockType, fields in VEHICLE_BLOCKS: data.append(blockType) data.append(len(fields)) for fieldType in fields: data.append(fieldType) data.append(__getData(fieldType, dossier)) data.append(__getDataExtra(blockType, fieldType, dossier)) return data
def setInvVehicles(self, data): vCDs = data.get(INV_ITEM_VCDESC_KEY, {}) vTypeName = ITEM_TYPE_NAMES[_VEHICLE] result = set() for invID, vStrCD in vCDs.iteritems(): if vStrCD is None or not len(vStrCD): vIntCD = self._data.removeInvItem(invID=invID) else: vType = vehicles.getVehicleType(vStrCD) vIntCD = vehicles.makeIntCompactDescrByID(vTypeName, vType.id[0], vType.id[1]) self._data.setInvItem(vIntCD, custom_items._makeInventoryVehicle(invID, vStrCD, data)) if vIntCD > 0: result.add(vIntCD) return (result, False)
def _getBuyConfirmMeta(self, itemCD, price, conflictedEqs): itemTypeID, nationID, itemID = vehicles.parseIntCompactDescr(itemCD) conflictedEqs = self._getConflictedEqsMeta(conflictedEqs).getMessage() ctx = { 'credits': BigWorld.wg_getIntegralFormat(price[0]), 'typeString': getTypeInfoByIndex(itemTypeID)['userString'], 'conflictedEqs': conflictedEqs if conflictedEqs else '' } if itemTypeID == _VEHICLE: ctx['userString'] = vehicles.getVehicleType(itemCD).userString else: ctx['userString'] = vehicles.getDictDescr(itemCD)['userString'] return HtmlMessageDialogMeta('html_templates:lobby/dialogs', 'confirmBuyAndInstall', ctx=ctx)
def __onCustomizationDrop(self, resultID, cItemID, cType): if resultID < 0: message = _ms(_DROP_MESSAGE[cType]['error']) else: if self.__aData.available[cType][cItemID].isInDossier: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = _ms(_DROP_MESSAGE[cType]['storedSuccess'], vehicle=vehicle.userString) else: message = _ms(_DROP_MESSAGE[cType]['removedSuccess']) if g_tankActiveCamouflage.has_key(g_currentVehicle.item.intCD): del g_tankActiveCamouflage[g_currentVehicle.item.intCD] SystemMessages.pushMessage(message) self.__synchronizeDossierIfRequired() self.purchaseProcessed()
def checkVehicle(self, vehTypeCompDescr): if self.mask == 0: return True if not self._checkVehicleType(vehTypeCompDescr): return False vehType = vehicles.getVehicleType(vehTypeCompDescr) if not self._checkVehicleNation(vehType.id[0]): return False vehClass = vehicles.getVehicleClass(vehTypeCompDescr) vehClassIdx = VEHICLE_CLASS_INDICES[vehClass] if not self._checkVehicleClass(vehClassIdx): return False vehLevel = vehType.level return False if not self.checkVehicleLevel(vehClassIdx, vehLevel) else True
def checkVehicle(self, vehTypeCompDescr): if self.vehTypeCompDescr is not None: return self.vehTypeCompDescr == vehTypeCompDescr vehType = vehicles.getVehicleType(vehTypeCompDescr) if not self.nationMask & 1 << vehType.id[0]: return False level = vehType.level if not (self.levels[0] <= level and level <= self.levels[1]): return False classTag = vehicles.getVehicleClass(vehTypeCompDescr) classIndex = VEHICLE_CLASS_INDICES.get(classTag, _BAD_CLASS_INDEX) if not self.vehClassMask & 1 << classIndex: return False else: return True
def __makeVehiclesList(vTypeCompDescrs): vehiclesList = [] for vehTypeCompDescr in vTypeCompDescrs: try: vType = getVehicleType(vehTypeCompDescr) classTag = tuple(VEHICLE_CLASS_TAGS & vType.tags)[0] vehiclesList.append({'name': vType.userString, 'nation': vType.id[0], 'level': vType.level, 'type': classTag, 'icon': '../maps/icons/vehicle/small/%s.png' % vType.name.replace(':', '-')}) except Exception: LOG_CURRENT_EXCEPTION() continue return vehiclesList
def _setVehicleList(self, accountDBID, vehShortList): vehs = [] vehInvIDs = [] for vehInvID, vehTypeCompDescr in vehShortList: classTag = vehicles.getVehicleClass(vehTypeCompDescr) vehType = vehicles.getVehicleType(vehTypeCompDescr) vehClassIdx = VEHICLE_CLASS_INDICES.get(classTag, _BAD_CLASS_INDEX) vehTuple = UnitVehicle(vehInvID, vehTypeCompDescr, vehType.level, vehClassIdx) vehs.append(vehTuple) vehInvIDs.append(vehInvID) self._vehicles[accountDBID] = vehs self.storeOp(UNIT_OP.SET_VEHICLE_LIST, accountDBID, vehShortList) self._storeNotification(accountDBID, UNIT_NOTIFY_CMD.SET_VEHICLE_LIST, [vehInvIDs]) self._dirty = 1 return True
def subscriptionRentDelayed(self, cmd): if cmd.vehCD: BigWorld.player().renewableSubscription.setRentPending(cmd.vehCD) vehName = getUserName(getVehicleType(cmd.vehCD)) SystemMessages.pushMessage( '', messageData={ 'header': backport.text(R.strings.messenger.serviceChannelMessages. wotPlus.tankRental.isPending.title()), 'text': backport.text(R.strings.messenger.serviceChannelMessages. wotPlus.tankRental.isPending.text(), vehicle=vehName) }, type=SystemMessages.SM_TYPE.MessageHeader)
def __onCustomizationDrop(self, resultID, cItemID, cType): if resultID < 0: message = _ms(_DROP_MESSAGE[cType]['error']) sysMessageType = SystemMessages.SM_TYPE.Error else: sysMessageType = SystemMessages.SM_TYPE.Information if cItemID in self.__displayedElements[cType] and self.__displayedElements[cType][cItemID].isInDossier: intCD = g_currentVehicle.item.intCD vehicle = vehicles.getVehicleType(int(intCD)) message = _ms(_DROP_MESSAGE[cType]['storedSuccess'], vehicle=vehicle.userString) else: message = _ms(_DROP_MESSAGE[cType]['removedSuccess']) if g_tankActiveCamouflage.has_key(g_currentVehicle.item.intCD): del g_tankActiveCamouflage[g_currentVehicle.item.intCD] SystemMessages.pushMessage(message, type=sysMessageType) self.__synchronizeDossierIfRequired()
def checkVehicle(self, vehTypeCompDescr): if self.mask == 0: return True if not self._checkVehicleType(vehTypeCompDescr): return False vehType = vehicles.getVehicleType(vehTypeCompDescr) if not self._checkVehicleNation(vehType.id[0]): return False vehClass = vehicles.getVehicleClass(vehTypeCompDescr) vehClassIdx = VEHICLE_CLASS_INDICES[vehClass] if not self._checkVehicleClass(vehClassIdx): return False vehLevel = vehType.level if not self.checkVehicleLevel(vehClassIdx, vehLevel): return False return True# decompiled 0 files: 0 okay, 1 failed, 0 verify failed
def getGunCompatibles(self, itemDescr, _ = None): avgParams = dict(self.__getParamFromCache(itemDescr['compactDescr'], 'avgParams', default={})) allVehiclesNames = self.__getComponentVehiclesNames(itemDescr['compactDescr']) clipVehiclesCD_List = self.__getParamFromCache(itemDescr['compactDescr'], CLIP_VEHICLES_PROP_NAME, default=tuple()) normalVehicles = [] clipVehiclesNames = [] for clipV_CD in clipVehiclesCD_List: userFriendlyVehicleName = getVehicleType(clipV_CD).userString clipVehiclesNames.append(userFriendlyVehicleName) if userFriendlyVehicleName in allVehiclesNames: allVehiclesNames.remove(userFriendlyVehicleName) return {'vehicles': allVehiclesNames, SHELLS_PROP_NAME: avgParams.get(SHELLS_PROP_NAME, tuple()), 'turrets': self.__getParamFromCache(itemDescr['compactDescr'], 'turrets', default=tuple()), CLIP_VEHICLES_PROP_NAME: clipVehiclesNames, CLIP_VEHICLES_CD_PROP_NAME: clipVehiclesCD_List}