def __fillConfiguration(self, slotSettings, configurationsSettings, configurationID): slotID = slotSettings.id if not self.__isConfigurationIDValid(configurationsSettings, configurationID): LOG_ERROR("ConfigurationID isn't valid. slotID, configurationID", slotID, configurationID) return else: weapons = configurationsSettings[configurationID].weapons configuration = LobbyAirplaneWeapons.__Configuration() configuration.isDefault = ( slotID, configurationID ) in _airplanesConfigurations_db.getDefaultAirplaneConfiguration( self.__aircraftID).weaponSlots configuration.weaponSlotID = slotID configuration.configurationID = configurationID if len(weapons) == 0: configuration.weaponNameID = EMPTY_WEAPON_NAME_ID configuration.weaponName = localizeLobby('WEAPON_NAME_EMPTY') self.__weaponSlotsMap[slotID].append(configuration) else: it = iter(weapons) weapon = it.next() configuration.weaponNameID = weapon.name configuration.weaponName = localizeComponents('WEAPON_NAME_' + weapon.name) configuration.neededCount = len(weapons) configuration.weaponGroup = weapon.weaponGroup weaponUpgradeMap = self.__getUpgrade(weapon.name) if weaponUpgradeMap is not None: configuration.haveCount = weaponUpgradeMap['boughtCount'] configuration.installedCount = weaponUpgradeMap[ 'installedCount'] configuration.parentName = weaponUpgradeMap['parent'] upgrade = db.DBLogic.g_instance.upgrades.get(weapon.name, None) if upgrade is not None: configuration.level = upgrade.level weaponType = upgrade.type configuration.weaponType = weaponType if weaponType == UPGRADE_TYPE.GUN: gunData = db.DBLogic.g_instance.getGunData(weapon.name) if gunData is None: LOG_ERROR( 'Weapon has not weapon settings. Weapon name', weapon.name) else: configuration.description = localizeLobby( gunData.gunProfileName.upper() + '_DESCRIPTION') else: configuration.description = localizeComponents( UPGRADE_TYPE.DESCRIPTION_MAP[weaponType]) configuration.icoPath = get48ModuleIconPath( getattr(upgrade, 'iconPath', ICON_MODULE_DEFAULT_PATH)) self.__weaponSlotsMap[slotID].append(configuration) return
def __call__(self, account, ob, **kw): adaptedOB = super(IBombDescriptionAdapter, self).__call__(account, ob, weaponType=UPGRADE_TYPE.BOMB, **kw) adaptedOB['caliber'] = localizeComponents('WEAPON_NAME_' + adaptedOB['caliber']) return adaptedOB
def __init__(self, slotID, data): self.slotID = slotID self.weaponType = data['weaponType'] self.storeCount = data['storeCount'] self.maxCount = data['maxCount'] self.curCount = data['curCount'] self.title = localizeComponents('WEAPON_NAME_' + data['weaponID']) shellDBGroupID, shellDescription = db.DBLogic.g_instance.getShellComponentsGroupIDAndDescription( data['weaponID']) self.price = data['price'] self.icoPath = shellDescription.hudIcoPath
def __buildPreset(self, name, modules, weapons, rolesList): preset = LobbyAirplanePresets.__PresetVO() preset.name = name preset.title = localizeComponents( 'PRESET_NAME_%s' % name) if name == CUSTOM_PRESET_NAME else localizePresets( 'PRESET_NAME_%s' % name) preset.modulesList = modules preset.weaponsList = weapons preset.isAvailable = name in self.__availablePresetList preset.rolesList = rolesList return preset
def __call__(self, account, ob, **kw): adaptedOb = super(IPlanePresetAdapter, self).__call__(account, ob, **kw) if ob is not None: globalID = ob['globalID'] dbInstance = db.DBLogic.g_instance name = dbInstance.getPresetNameByGlobalID(globalID) weapons = dbInstance.getUpgradesNamesByGlobalID(globalID) weapons = [x for x in weapons if x not in ob['preset'].modules] adaptedOb['name'] = localizeComponents( 'PRESET_NAME_%s' % name) if name == CUSTOM_PRESET_NAME else localizePresets( 'PRESET_NAME_%s' % name) adaptedOb['modulesList'] = [ dbInstance.getUpgradeByName(module).id for module in ob['preset'].modules ] adaptedOb['weaponSlotsList'] = ob['preset'].weaponSlots adaptedOb['weaponsList'] = [ dbInstance.getUpgradeByName(weapon).id for weapon in weapons ] return adaptedOb
def __call__(self, account, ob, **kw): if ob is None: return else: cmpUpgrade = None cmpUpgradeID = None weaponConfig = None slotID = None upgrade = None upgradeID = None plane = None _, typeList = splitIDTypeList(kw['idTypeList']) if isinstance(ob, list): for idx in xrange(0, len(typeList)): if typeList[idx] == 'plane': plane = ob[idx] elif typeList[idx] == 'upgrade': if upgradeID is None: upgrade = ob[idx] upgradeID = kw['idTypeList'][idx][0] else: cmpUpgrade = ob[idx] cmpUpgradeID = kw['idTypeList'][idx][0] elif typeList[idx] == 'weaponConfig': weaponConfig = ob[idx] elif typeList[idx] == 'weaponslot': slotID = ob[idx].id else: upgrade = ob adaptedOb = super(IModuleDescriptionAdapter, self).__call__(account, ob, **kw) if upgrade is not None: outName, specs, planesSet, shortDescription = getUpgradeSpecs( upgrade, plane.id if plane is not None else None, cmpUpgrade, slotID, weaponConfig) elif weaponConfig is None or slotID is None or cmpUpgradeID is None or cmpUpgrade.type not in UPGRADE_TYPE.WEAPON: return adaptedOb adaptedOb['configComparison'] = [] adaptedOb['requiredModules'] = [] dbInstance = db.DBLogic.g_instance cmpGlobalID = 0 if cmpUpgradeID is not None: import BWPersonality lch = BWPersonality.g_lobbyCarouselHelper lobbyAirplane = lch.getCarouselAirplane( plane.id) or getLobbyAirplane(plane.id) upgradeName = upgrade.name if upgrade is not None else None cmpName = cmpUpgrade.name if cmpUpgrade is not None else None if lobbyAirplane is not None: upgrades = [ x['name'] for x in lobbyAirplane.modules.getInstalled() ] weaponList = lobbyAirplane.weapons.getInstalledWeaponsList( ) if not upgrades: planeConfig = airplanesConfigurations[ airplanesDefaultConfigurations[plane.id]] upgrades = planeConfig.modules weaponList = planeConfig.weaponSlots cmpGlobalID, newUpgrades, newWeaponList = adjustPlaneConfig( lobbyAirplane.planeID, upgrades, weaponList, upgradeName, cmpName, slotID, weaponConfig) oldGlobalID = db.DBLogic.createGlobalID( lobbyAirplane.planeID, upgrades, weaponList) requiredModules = getDiffModules(oldGlobalID, cmpGlobalID, upgradeName, (slotID, weaponConfig)) for upgradeName in requiredModules: reqUpgrade = dbInstance.getUpgradeByName(upgradeName) name, _, _, _ = getUpgradeSpecs( reqUpgrade, plane.id if plane is not None else None, None, slotID, weaponConfig) adaptedOb['requiredModules'].append(name) cmpLobbyAirplane = lobbyAirplane.previewPreset( newUpgrades, [{ 'slot': x[0], 'configuration': x[1] } for x in newWeaponList]) comparisonSpecs = cmpLobbyAirplane.getGroupedDescriptionFields( True, lobbyAirplane, cmpGlobalID, False) for el in comparisonSpecs: for i, j in el.__dict__.iteritems(): if i != 'main': continue specObj = None if j is not None: specObj = j.__dict__ if specObj and specObj['comparisonValue']: adaptedOb['configComparison'].append(specObj) if not adaptedOb['configComparison']: adaptedOb['configComparison'] = None if upgrade is not None: gunData = dbInstance.getGunData(upgrade.name) if gunData is None: moduleType = localizeComponents( MODULE_GROUP_NAME.get( getattr(upgrade, 'moduleGroup', None), MODULE_GROUP_NAME[upgrade.type])) else: profileName = gunData.gunProfileName.upper() if profileName == 'MACHINEGUN_SMALL': profileName = 'MACHINE_GUN_LOW' else: profileName = profileName.replace( 'MACHINEGUN_SMALL', 'MACHINE_GUN') profileName = profileName.replace('CANNON_HIGH_VULCAN', 'CANNON_HIGH') moduleType = localizeLobby( '{0}_DESCRIPTION'.format(profileName)) adaptedOb['name'] = '{0} {1}'.format(moduleType, outName) adaptedOb['type'] = upgrade.type adaptedOb['description'] = shortDescription if hasattr(upgrade, 'level'): adaptedOb['level'] = upgrade.level else: adaptedOb['level'] = 0 adaptedOb['specsList'] = [spec.__dict__ for spec in specs] adaptedOb['airplanesList'] = map( lambda x: localizeAirplane(dbInstance.getAircraftName(x)), filter(lambda x: x in planesSet, dbInstance.getShopPlaneList())) adaptedOb['suitablePlaneIDs'] = list(planesSet) adaptedOb['icoPath'] = get48ModuleIconPath( getattr(upgrade, 'iconPath', ICON_MODULE_DEFAULT_PATH)) isArmoredTargetEffective = EFFECTIVE_AGAINST_ARMORED_OBJECTS.NORMAL if upgrade.type in [UPGRADE_TYPE.BOMB, UPGRADE_TYPE.ROCKET]: isArmoredTargetEffective = EFFECTIVE_AGAINST_ARMORED_OBJECTS.IS_EFFECTIVE if upgrade.type == UPGRADE_TYPE.GUN: isArmoredTargetEffective = EFFECTIVE_AGAINST_ARMORED_OBJECTS.NOT_EFFECTIVE if gunData.caliber < MIN_CALIBER else EFFECTIVE_AGAINST_ARMORED_OBJECTS.LOW_EFFECTIVE adaptedOb['armoredTargetEffective'] = isArmoredTargetEffective adaptedOb['buyAvailable'] = getattr(upgrade, 'buyAvailable', True) if upgrade.type == UPGRADE_TYPE.GUN: compData = gunData elif upgrade.type in UPGRADE_TYPE.SHELL: compData = dbInstance.getComponentByName( UPGRADE_TYPE_TO_COMPONENT_TYPE[upgrade.type], upgrade.name) elif upgrade.type == UPGRADE_TYPE.TURRET: turret = dbInstance.getTurretData(upgrade.name) compData = dbInstance.getGunData(turret.hangarSimilarGun) else: compData = None if compData is not None and hasattr(compData, 'tag'): adaptedOb['propsList'] = [[localizeLobby(x.name), x.type] for x in compData.tag] else: adaptedOb['propsList'] = [] adaptedOb['cmpGlobalID'] = cmpGlobalID else: adaptedOb['name'] = '' adaptedOb['type'] = -1 adaptedOb['description'] = '' adaptedOb['level'] = 0 adaptedOb['specsList'] = [] adaptedOb['airplanesList'] = [] adaptedOb['suitablePlaneIDs'] = [] adaptedOb['icoPath'] = '' adaptedOb['armoredTargetEffective'] = False adaptedOb['buyAvailable'] = False adaptedOb['cmpGlobalID'] = 0 return adaptedOb
def __getUpgradeGroupName(self, aircraftID, upgrade): if upgrade.type in UPGRADE_TYPE.MODULES: return localizeComponents(UPGRADE_TYPE.DESCRIPTION_MAP[upgrade.type]) if upgrade.type in UPGRADE_TYPE.WEAPON: return localizeLobby('AMMO_SLOT_' + self.__db.getSlotsWeaponUpgrade(aircraftID, upgrade)[0].name)
def __fillNodes(self, selectedAircraftID): inventory = self.__lobbyCarouselHelper.inventory self.__originPlane = self.__lobbyCarouselHelper.getCarouselAirplane(selectedAircraftID) if self.__originPlane is None: self.__originPlane = getLobbyAirplane(selectedAircraftID) if self.__originPlane is None: LOG_ERROR('Aircraft %d not found' % selectedAircraftID) return else: LOG_DEBUG('__onInitialized selectedAircraftID = {0}'.format(selectedAircraftID)) self.__selectedAircraft = copy.deepcopy(self.__originPlane) self.__selectedAircraft.presets.fillPresets() self.__selectedAircraft.experience = self.__lobbyCarouselHelper.inventory.getAircraftExp(selectedAircraftID) if (self.__selectedAircraft.isPremium or self.__selectedAircraft.isBought) and not self.__selectedAircraft.isResearched: self.__lobbyCarouselHelper.inventory.openAircraft(self.__selectedAircraft.planeID) self.__selectedAircraft.isResearched = True self.__nodes.clear() aircraftData = self.__db.getAircraftData(selectedAircraftID) groupedModules = {} groupsVOs = {} selectedAircraftName = self.__db.getAircraftName(self.__selectedAircraft.planeID) nodesCounter = 0 for component in self.__selectedAircraft.modules.getSortedModules(): upgrade = self.__db.upgrades.get(component['name']) if upgrade.type == UPGRADE_TYPE.AIRCRAFT: aircraftChildData = self.__db.getAircraftData(self.__db.getAircraftIDbyName(upgrade.name)) if aircraftChildData.airplane.options.hidePlaneResearch: continue moduleNode = NodeData() moduleNode.isDefault = component['isDefault'] moduleNode.upgrade = upgrade moduleNode.upgradeVariant = findIf(moduleNode.upgrade.variant, lambda item: item.aircraftName == selectedAircraftName) moduleNode.vo = NodeVO() moduleNode.vo.upgradeName = moduleNode.upgrade.name moduleNode.vo.dbID = moduleNode.upgrade.id moduleNode.vo.name = localizeUpgrade(moduleNode.upgrade) moduleNode.vo.isInstalled = component['isInstalled'] and self.__selectedAircraft.isBought moduleNode.vo.id = nodesCounter nodesCounter += 1 moduleNode.vo.iconPath = get48ModuleIconPath(getattr(moduleNode.upgrade, 'iconPath', ICON_MODULE_DEFAULT_PATH)) moduleNode.vo.isBought = inventory.isUpgradeBought(moduleNode.upgrade.name) or moduleNode.vo.isInstalled moduleNode.vo.requiredCount = 1 moduleNode.vo.availableCount = max(0, inventory.getUpgradeCount(moduleNode.upgrade.name)) groupType = getattr(moduleNode.upgrade, 'moduleGroup', moduleNode.upgrade.type) try: moduleNode.groupIndex = aircraftData.airplane.options.moduleGroupsOrder.group.index(groupType) except: moduleNode.groupIndex = DEFAULT_MODULE_GROUPS_ORDER_BY_TYPE[groupType] moduleNode.groupName = localizeComponents(MODULE_GROUP_NAME[groupType]) moduleNode.vo.level = moduleNode.upgrade.level groupedModules.setdefault(moduleNode.groupIndex, []).append(moduleNode) self.__nodes[moduleNode.vo.id] = moduleNode for weapon in self.__selectedAircraft.weapons.getSortedWeaponsList(): moduleNode = NodeData() moduleNode.isDefault = weapon.isDefault moduleNode.vo = NodeVO() moduleNode.vo.weaponConfig = weapon.configurationID moduleNode.vo.slotID = weapon.weaponSlotID moduleNode.vo.id = nodesCounter moduleNode.vo.isInstalled = weapon.isInstalled and self.__selectedAircraft.isBought nodesCounter += 1 if weapon.weaponNameID == EMPTY_WEAPON_NAME_ID: moduleNode.isEmptyWeapon = True moduleNode.vo.dbID = -1 moduleNode.vo.iconPath = get48ModuleIconPath(EMPTY_WEAPON_SLOT_ICON_PATH) moduleNode.vo.isResearched = self.__selectedAircraft.isResearched moduleNode.vo.researchExp = 0 moduleNode.vo.buyCost = CostVO(0, 0) moduleNode.vo.isEmpty = True moduleNode.vo.incompatibleModules = [] moduleNode.vo.name = localizeLobby('WEAPON_NAME_EMPTY') else: moduleNode.upgrade = self.__db.upgrades.get(weapon.weaponNameID, None) if moduleNode.upgrade is None: LOG_ERROR('WeaponNameID = "{0}" cannot be found in db'.format(weapon.weaponNameID)) continue moduleNode.vo.dbID = moduleNode.upgrade.id moduleNode.upgradeVariant = findIf(moduleNode.upgrade.variant, lambda item: item.aircraftName == selectedAircraftName) if moduleNode.upgradeVariant is None: LOG_ERROR('WeaponNameID = "{0}" does not contains variant for aircraft = {1}'.format(weapon.weaponNameID, selectedAircraftName)) continue moduleNode.vo.upgradeName = moduleNode.upgrade.name moduleNode.vo.name = localizeUpgrade(moduleNode.upgrade) moduleNode.vo.iconPath = get48ModuleIconPath(getattr(moduleNode.upgrade, 'iconPath', ICON_MODULE_DEFAULT_PATH)) moduleNode.vo.requiredCount = weapon.neededCount moduleNode.vo.level = moduleNode.upgrade.level self.__updateWeaponAvailableCount(moduleNode) moduleNode.vo.weaponType = moduleNode.upgrade.type if moduleNode.upgrade.type == UPGRADE_TYPE.GUN: gun = db.DBLogic.g_instance.getComponentByName(COMPONENT_TYPE.GUNS, moduleNode.upgrade.name) moduleNode.vo.weaponGroup = gun.id moduleNode.vo.isWeapon = True groupType = 'slot_%s' % str(weapon.weaponSlotID) try: moduleNode.groupIndex = aircraftData.airplane.options.moduleGroupsOrder.group.index(groupType) except: moduleNode.groupIndex = DEFAULT_MODULE_GROUPS_ORDER_BY_TYPE[groupType] moduleNode.groupName = self.__selectedAircraft.weapons.getSlotsInfoMap()[weapon.weaponSlotID]['description'] groupedModules.setdefault(moduleNode.groupIndex, []).append(moduleNode) self.__nodes[moduleNode.vo.id] = moduleNode aircraftConfigurations = [ _airplanesConfigurations_db.getAirplaneConfiguration(globalID) for globalID in _airplanesConfigurations_db.airplanesConfigurationsList[selectedAircraftID] ] for cSlotId, val in groupedModules.iteritems(): for cIndex, cModule in enumerate(val): if not groupsVOs.has_key(cModule.groupIndex): groupsVOs[cModule.groupIndex] = GroupVO(cModule.groupIndex, cModule.groupName) groupsVOs[cModule.groupIndex].nodes.append(cModule.vo.id) incompatibleModules = self.__nodes.keys() for aircraftConfig in aircraftConfigurations: if not incompatibleModules: break if cModule.vo.isWeapon and (cModule.vo.slotID, cModule.vo.weaponConfig) in aircraftConfig.weaponSlots or not cModule.vo.isWeapon and cModule.upgrade.name in aircraftConfig.modules: for node in self.__nodes.itervalues(): if node.vo.id in incompatibleModules: if node.vo.isWeapon and (node.vo.slotID, node.vo.weaponConfig) in aircraftConfig.weaponSlots or not node.vo.isWeapon and node.upgrade.name in aircraftConfig.modules: incompatibleModules.remove(node.vo.id) cModule.vo.incompatibleModules = incompatibleModules cModule.vo.isBought = self.__isBought(cModule) parentNode = None if not cModule.isEmptyWeapon: cModule.vo.buyCost = CostVO(cModule.upgrade.credits, cModule.upgrade.gold) if cModule.upgradeVariant.parentUpgrade: parentUpgrade = cModule.upgradeVariant.parentUpgrade[0] if hasattr(parentUpgrade, 'weaponConfig'): parentNode = findIf(self.__nodes.itervalues(), lambda n: not n.isEmptyWeapon and n.vo.isWeapon and n.upgrade.name == parentUpgrade.name and parentUpgrade.weaponConfig.slotID == n.vo.slotID and parentUpgrade.weaponConfig.slotConfigID == n.vo.weaponConfig) else: parentNode = findIf(self.__nodes.itervalues(), lambda n: not n.isEmptyWeapon and n.upgrade.name == parentUpgrade.name) if parentNode: cModule.vo.parentID = parentNode.vo.id cModule.vo.researchExp = cModule.upgradeVariant.parentUpgrade[0].experience if not cModule.isDefault: self.__updateNodeRequiredResearches(cModule) self.__updateResearchStatus(cModule) if cModule.vo.isWeapon: if not cModule.isDefault: requiredNodes = [ n for n in self.__nodes.itervalues() if not n.vo.isWeapon and any((s for s in n.upgradeVariant.slot if s.id == cModule.vo.slotID and cModule.vo.weaponConfig in s.typeId)) ] if parentNode is None and len(requiredNodes) == 1 and len(groupedModules[requiredNodes[0].groupIndex]) != 1: cModule.vo.parentID = requiredNodes[0].vo.id elif cModule.vo.parentID == -1: for node in groupedModules[cModule.groupIndex]: if node.vo.id != cModule.vo.id and cModule.vo.level > node.vo.level and (not parentNode or parentNode.vo.level < node.vo.level) or node.isDefault: parentNode = node if parentNode: cModule.vo.parentID = parentNode.vo.id else: for slot in cModule.upgradeVariant.slot: if len(slot.typeId) == 1 and self.__db.getWeaponInfo(selectedAircraftID, slot.id, slot.typeId[0]) is None: node = findIf(self.__nodes.itervalues(), lambda n: n.isEmptyWeapon and not n.isDefault and n.vo.slotID == slot.id and n.vo.weaponConfig == slot.typeId[0]) if node is not None: node.vo.parentID = cModule.vo.id aircraftUpgrades, aircrafts = self.__db.getAircraftUpgrades(selectedAircraftID) if not aircraftData.airplane.options.hidePlaneResearch: for childUpgrade in aircrafts: self.__addAircraftNode(childUpgrade.name, childUpgrade, nodesCounter, False, selectedAircraftID) nodesCounter += 1 selectedAircraftUpgrade = self.__db.upgrades.get(selectedAircraftName, None) if selectedAircraftUpgrade is not None and not aircraftData.airplane.options.hidePlaneResearch: parentAircraftUpgrades = [ self.__db.upgrades.get(variant.aircraftName, None) for variant in selectedAircraftUpgrade.variant ] for parentAircraftUpgrade in parentAircraftUpgrades: if parentAircraftUpgrade: self.__addAircraftNode(parentAircraftUpgrade.name, parentAircraftUpgrade, nodesCounter, True) else: self.__addAircraftNode(selectedAircraftUpgrade.variant[0].aircraftName, None, nodesCounter, True) nodesCounter += 1 self.__updateAircraftInfoVO() selectedPresetName = self.__selectedAircraft.presets.getInstalled().name if self.__selectedAircraft.isBought else self.__db.getAircraftDefaultPreset(selectedAircraftID).name self.__lobby.call_1('moduleTree.setData', DataVO([ n.vo for n in self.__nodes.itervalues() ], groupsVOs.values(), [ PresetVO(preset.name, preset.title) for preset in self.__selectedAircraft.presets.getAll() ], selectedPresetName, self.__selectedAircraft.vo)) self.__previewSelectedModulesStats(-1) return
def __call__(self, account, o, **kw): ob = getObject(kw['idTypeList']) adaptedOB = super(IAmmoBeltDescriptionAdapter, self).__call__(account, ob, **kw) from db.DBLogic import g_instance as db_instance guns = db_instance.getBeltSuitableGuns(ob.id) planes = [] globalMaxDamage = maxFireChance = 0 globalMinDamage = minFireChance = 100000000 gunNames = [] gunUpgradeIds = [] for gun in guns: upgrade = db_instance.upgrades.get(gun.name, None) if upgrade is None: continue for upgradeVariant in upgrade.variant: planeID = db_instance.getAircraftIDbyName( upgradeVariant.aircraftName) planeData = db_instance.getAircraftData(planeID) availableAmmoTypes = AVAILABLE_BELTS_BY_PLANE_TYPE[ planeData.airplane.planeType] if ob.ammo[0] in availableAmmoTypes and planeID not in planes: planes.append(planeID) minDamage, maxDamage = db_instance.calculateBeltMinMaxDamage( gun, ob) globalMaxDamage = max(maxDamage, globalMaxDamage) globalMinDamage = min(minDamage, globalMinDamage) fireChance, _ = db_instance.calculateBeltSpec( gun, ob, AMMOBELT_SPECS.FIRE_CHANCE) maxFireChance = max(fireChance, maxFireChance) minFireChance = min(fireChance, minFireChance) gunNames.append(localizeComponents('WEAPON_NAME_' + gun.weapName)) gunUpgradeIds.append(upgrade.id) globalMinDamage = wowpRound(globalMinDamage, 2) globalMaxDamage = wowpRound(globalMaxDamage, 2) minFireChance = wowpRound(minFireChance, 3) maxFireChance = wowpRound(maxFireChance, 3) strDamage = str( globalMinDamage ) if globalMinDamage == globalMaxDamage else '{0}-{1}'.format( globalMinDamage, globalMaxDamage) if maxFireChance > 0: strFireChance = '{0}%'.format( minFireChance * 100) if minFireChance == maxFireChance else '{0}-{1}%'.format( minFireChance, maxFireChance) else: strFireChance = '' if guns: adaptedOB['caliber'] = wowpRound(guns[0].caliber, 2) else: adaptedOB['caliber'] = 0.0 LOG_DEBUG(' TEST LOBBY ', vars(ob)) adaptedOB['suitableGunIDs'] = gunUpgradeIds adaptedOB['hudIcoPath'] = get48ModuleIconPath(ob.lobbyIconPath) adaptedOB['suitablePlaneIDs'] = planes adaptedOB['name'] = localizeComponents('WEAPON_NAME_' + ob.ui_name) adaptedOB['beltType'] = ob.beltType adaptedOB['icoPathSmall'] = get24ModuleIconPath(ob.lobbyIconPath) adaptedOB['globalMaxDamage'] = globalMaxDamage adaptedOB['globalMinDamage'] = globalMinDamage adaptedOB['globalMaxFireChance'] = maxFireChance adaptedOB['globalMinFireChance'] = minFireChance adaptedOB['gunNames'] = ', '.join(set(gunNames)) adaptedOB['shortDescription'] = '{0} {1}'.format( localizeLobby('MODULES_CHARACTERISTICS_DPS'), strDamage) adaptedOB['description'] = '' if strFireChance: adaptedOB['description'] += '\n{0} {1}'.format( localizeLobby( 'LOBBY_MAINTENANCE_MODULE_PARAMETER_FIRE_CHANSE'), strFireChance) adaptedOB['tooltipDescription'] = localizeTooltips( _BELT_TYPE_DESCRIPTION[ ob.beltType]) if ob.beltType in _BELT_TYPE_DESCRIPTION else '' adaptedOB['buyAvailable'] = getattr(ob, 'buyAvailable', True) return adaptedOB
def getUpgradeSpecs(upgrade, forPlaneID = None, cmpUpgrade = None, weaponSlot = None, weaponConfig = None): """ :param upgrade: upgrade from upgrades_db :returns: a tuple of localized name and specs array of ModuleSpecsVO """ nameID = upgrade.name localizedName = '' suitablePlanes = set([]) specs = [] dbInstance = db.DBLogic.g_instance ms = MeasurementSystem() shortDescription = '' for upgradeVariant in upgrade.variant: planeID = dbInstance.getAircraftIDbyName(upgradeVariant.aircraftName) suitablePlanes.add(planeID) if planeID is None: LOG_ERROR('getUpgradeSpecs() cannot find planeID by aircraft name (%s), module name is %s, please, correct DB' % (upgradeVariant.aircraftName, nameID)) continue if forPlaneID is not None and planeID != forPlaneID: continue if upgrade.type == UPGRADE_TYPE.GUN: count = dbInstance.getGunsCount(planeID, nameID, weaponSlot, weaponConfig) localizedName = localizeComponents('WEAPON_NAME_' + nameID) gunData = dbInstance.getGunData(nameID) dps = _mkint(gunData.DPS) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_DPS, localizeLobby('MODULES_CHARACTERISTICS_DPS'), dps, '', planeID)) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_ROUNDS_PER_SECOND, localizeLobby('MODULES_CHARACTERISTICS_TEMPO_OF_FIRE'), _mkint(gunData.RPM), localizeLobby('MODULES_CHARACTERISTICS_RATE_OF_FIRE_UNITS'), planeID)) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_EFFECTIVE_DISTANCE, localizeLobby('MODULES_CHARACTERISTICS_EFFECTIVE_DIST'), _mkint(ms.getMeters(BULLET_FLY_DIST_CORRECTION * gunData.bulletFlyDist / consts.WORLD_SCALING)), ms.localizeMarket('MARKET_AIRPLANE_TURN_RADIUS'), planeID)) shortDescription = '{0}: {1}'.format(localizeTooltips('TOOLTIP_FIXED_DPS'), dps) elif upgrade.type == UPGRADE_TYPE.ENGINE: localizedName = localizeComponents('NAME_MODULE_' + nameID) settings = dbInstance.getAircraftData(planeID) part = findIf(upgradeVariant.logicalPart, lambda p: p.type == 'engine') if part is None: LOG_ERROR("Part of type 'engine' not found", upgrade.__dict__, [ x.__dict__ for x in upgradeVariant.logicalPart ]) partname = part.name engineParameters = filter(lambda m: m.name == partname, settings.airplane.flightModel.engine) if not engineParameters: LOG_ERROR("Can't find settings for engine", nameID, localizedName, partname) for eng in engineParameters: value, unit = (eng.power, localizeLobby('MARKET_AIRPLANE_ENGINE_CAPACITY_LS')) if hasattr(eng, 'power') else (eng.thrust / 10.0, ms.localizeMarket('MARKET_AIRPLANE_ENGINE_CAPACITY_KGS')) locID = 'MODULES_CHARACTERISTICS_ERROR_ENGINE' if hasattr(eng, 'power'): locID = 'MODULES_CHARACTERISTICS_POWER' elif hasattr(eng, 'thrust'): locID = 'MODULES_CHARACTERISTICS_THRIST' specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_POWER, localizeLobby(locID), _mkint(ms.getKgs(value)), unit, planeID)) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_MODULE_TYPE, localizeLobby('MODULES_CHARACTERISTICS_TYPE'), localizeLobby('MODULES_CHARACTERISTICS_%s' % upgrade.equipmentType), '', planeID)) if forPlaneID is None or planeID == forPlaneID: shortDescription = '{0}{2}: {1}'.format(localizeLobby(locID), _mkint(ms.getKgs(value)), unit) elif upgrade.type == UPGRADE_TYPE.PLANER: localizedName = localizeComponents('NAME_MODULE_' + nameID) settings = dbInstance.getAircraftData(planeID) part = findIf(upgradeVariant.logicalPart, lambda p: p.type == 'hull') if part is None: LOG_ERROR("Part of type 'hull' not found", upgrade.__dict__, [ x.__dict__ for x in upgradeVariant.logicalPart ]) partname = part.name hullParameters = filter(lambda h: h.name == partname, settings.airplane.flightModel.hull) if not hullParameters: LOG_ERROR("Can't find settings for hull", nameID, localizedName, partname) for h in hullParameters: mass = h.mass if hasattr(h, 'mass') else 0.0 hp = h.HP if hasattr(h, 'HP') else 0.0 specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_HEALTH, localizeLobby('MODULES_CHARACTERISTICS_DURABILITY'), hp, '', planeID)) shortDescription = '{0}: {1}'.format(localizeLobby('MODULES_CHARACTERISTICS_DURABILITY'), hp, '', planeID) elif upgrade.type == UPGRADE_TYPE.ROCKET or upgrade.type == UPGRADE_TYPE.BOMB: localizedName = localizeComponents('WEAPON_NAME_' + nameID) shellDBGroupID, shellDescription = dbInstance.getShellComponentsGroupIDAndDescription(nameID) if shellDescription: for spec in getShellDescription(shellDescription): spec.planeID = planeID specs.append(spec) else: LOG_ERROR("Can't find settings for shell", nameID, localizedName) shortDescription = '{0}: {1}'.format(localizeLobby('MODULES_CHARACTERISTICS_DAMAGE'), shellDescription.explosionDamage) elif upgrade.type == UPGRADE_TYPE.TURRET: turret = dbInstance.getTurretData(nameID) localizedName = localizeUpgrade(upgrade) gunData = dbInstance.getGunData(turret.hangarSimilarGun) dps = _mkint(turret.DPS * TURRET_DPS_TO_FIREPOWER_CFC) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_DPS, localizeLobby('MODULES_CHARACTERISTICS_DPS'), dps, '', planeID)) if gunData: specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_EFFECTIVE_DISTANCE, localizeLobby('MODULES_CHARACTERISTICS_EFFECTIVE_DIST'), _mkint(ms.getMeters(turret.targetLockShootDistance / consts.WORLD_SCALING)), ms.localizeMarket('MARKET_AIRPLANE_TURN_RADIUS'), planeID)) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_YAW_SECTOR, localizeLobby('MODULES_CHARACTERISTICS_TURRET_HORIZONTAL'), _mkint(math.degrees((turret.yawMax - turret.yawMin) / 2.0)), localizeLobby('MARKET_AIRPLANE_DEGREES'), planeID)) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_UP_SECTOR, localizeLobby('MODULES_CHARACTERISTICS_TURRET_UP'), _mkint(math.degrees(turret.pitchMax)), localizeLobby('MARKET_AIRPLANE_DEGREES'), planeID)) specs.append(ModuleSpecsVO(ModuleSpecsVO.TYPE_DOWN_SECTOR, localizeLobby('MODULES_CHARACTERISTICS_TURRET_DOWN'), _mkint(math.degrees(turret.pitchMin)), localizeLobby('MARKET_AIRPLANE_DEGREES'), planeID)) if turret.weaponCount > 1: dps = '{0}x {1}'.format(turret.weaponCount, dps) shortDescription = '{0}: {1}'.format(localizeTooltips('TOOLTIP_FIXED_DPS'), dps) if cmpUpgrade is None or cmpUpgrade.name == nameID: return (localizedName, specs, suitablePlanes, shortDescription) else: _, cmpSpecs, _, _ = getUpgradeSpecs(cmpUpgrade, forPlaneID) for mainSpec in specs: if not mainSpec.canCompare: continue cmpSpec = findIf(cmpSpecs, lambda x: x.specType == mainSpec.specType, None) if cmpSpec is not None and mainSpec.value != cmpSpec.value: mainSpec.setCmpValue(mainSpec.value - cmpSpec.value) return (localizedName, specs, suitablePlanes, shortDescription)
def getUpgradeGroupName(planeID, upgrade): if upgrade.type in UPGRADE_TYPE.MODULES: return localizeComponents(UPGRADE_TYPE.DESCRIPTION_MAP[upgrade.type]) if upgrade.type in UPGRADE_TYPE.WEAPON: return localizeLobby('AMMO_SLOT_' + db.DBLogic.g_instance.getSlotsWeaponUpgrade(planeID, upgrade)[0].name)
def __call__(self, account, ob, **kw): _, typeList = splitIDTypeList(kw['idTypeList']) weapon = None measurementSystem = None if isinstance(ob, list): for idx in xrange(0, len(typeList)): if typeList[idx] == 'measurementSystem': measurementSystem = MeasurementSystem(ob[idx]) else: weapon = ob[idx] else: weapon = ob adaptedOB = super(IWeaponDescriptionAdapter, self).__call__(account, weapon, **kw) if weapon is None: LOG_ERROR('IWeaponDescriptionAdapter: weapon not found', ob, kw) return adaptedOB else: adaptedOB['name'] = localizeComponents('WEAPON_NAME_%s' % weapon.name) weaponType = kw['weaponType'] if weaponType in UPGRADE_TYPE.SHELL: adaptedOB['iconPathSmall'] = weapon.iconPathSmall else: adaptedOB['iconPathSmall'] = '' dbInstance = db.DBLogic.g_instance adaptedOB['caliber'] = weapon.caliber upgrade = dbInstance.upgrades.get(weapon.name, None) if upgrade is not None: adaptedOB['iconPath'] = get48ModuleIconPath( getattr(upgrade, 'iconPath', ICON_MODULE_DEFAULT_PATH)) adaptedOB['iconPathSmall'] = get24ModuleIconPath( getattr(upgrade, 'iconPath', ICON_MODULE_DEFAULT_PATH)) adaptedOB['upgradeID'] = upgrade.id adaptedOB[ 'suitablePlaneIDs'] = dbInstance.getSuitablePlanesForUpgrade( upgrade) if adaptedOB['suitablePlaneIDs']: if dbInstance.isPlanePremium( adaptedOB['suitablePlaneIDs'][0]): adaptedOB['name'] = '{0} {1}'.format( adaptedOB['name'], localizeComponents('WEAPON_NAME_GOLDBELT')) if upgrade.type == UPGRADE_TYPE.ROCKET or upgrade.type == UPGRADE_TYPE.BOMB: adaptedOB['description'] = '\n'.join([ '{0} {1}{2} '.format(x.name, x.value, x.unit) for x in getShellDescription(weapon, measurementSystem) ]) adaptedOB['shortDescription'] = '{0} {1}'.format( localizeLobby( 'LOBBY_MAINTENANCE_MODULE_PARAMETER_DAMAGE'), weapon.explosionDamage) else: adaptedOB['description'] = '' adaptedOB['shortDescription'] = '' adaptedOB['buyAvailable'] = getattr(upgrade, 'buyAvailable', True) if upgrade.type == UPGRADE_TYPE.GUN: gunData = dbInstance.getGunData(upgrade.name) adaptedOB['maxDistance'] = round( measurementSystem.getMeters(gunData.bulletFlyDist / consts.WORLD_SCALING)) else: adaptedOB['maxDistance'] = 0 return adaptedOB