Esempio n. 1
0
 def __addAircraftNode(self, aircraftName, upgrade, nodesID, isParent, parentPlaneID = None):
     aircraftID = self.__db.getAircraftIDbyName(aircraftName)
     airplaneData = self.__db.getAircraftData(aircraftID)
     dataMap = self.__lobbyCarouselHelper.inventory.getAircraftClientDataMap(aircraftID, self.__db.getAircraftName(parentPlaneID) if parentPlaneID else None)
     aircraftNode = NodeData()
     aircraftNode.upgrade = upgrade
     aircraftNode.vo = NodeVO()
     aircraftNode.vo.id = nodesID
     aircraftNode.vo.dbID = aircraftID
     aircraftNode.vo.isBought = dataMap['isBought']
     aircraftNode.vo.isResearched = dataMap['isResearched']
     aircraftNode.vo.buyCost = CostVO(dataMap['priceCredits'], dataMap['priceGold'])
     aircraftNode.vo.iconPath = airplaneData.airplane.treeIconPath
     aircraftNode.vo.level = airplaneData.airplane.level
     aircraftNode.vo.name = localizeAirplaneMid(airplaneData.airplane.name)
     aircraftNode.vo.isAircraft = True
     aircraftNode.vo.aircraftID = aircraftID
     if not isParent and dataMap['parent']:
         selectedAircraftName = self.__db.getAircraftName(self.__selectedAircraft.planeID)
         aircraftNode.upgradeVariant = findIf(upgrade.variant, lambda v: v.aircraftName == selectedAircraftName)
         parentNode = findIf(self.__nodes.itervalues(), lambda n: not n.isEmptyWeapon and n.upgrade.name == aircraftNode.upgradeVariant.parentUpgrade[0].name)
         aircraftNode.vo.parentID = parentNode.vo.id if parentNode else -1
     aircraftNode.vo.researchExp = dataMap['reqiuredExperiencePlane']
     aircraftNode.vo.aircraftGainedExp = dataMap['gotExperience']
     aircraftNode.vo.isAircraftAvailable = self.__lobbyCarouselHelper.inventory.isPlaneResearchAvailableOpened(aircraftID)
     isPremium = dataMap['isPremium']
     aircraftNode.vo.isAircraftElite = dataMap['isElite']
     planeStatus = isPremium * PLANE_CLASS.PREMIUM or aircraftNode.vo.isAircraftElite * PLANE_CLASS.ELITE or PLANE_CLASS.REGULAR
     aircraftNode.vo.aircraftTypeIconPath = PLANE_TYPE_ICO_PATH.icon(airplaneData.airplane.planeType, planeStatus)
     aircraftNode.vo.planeBranchNum = airplaneData.airplane.branch
     self.__updatePlaneRequiredResearches(aircraftNode.vo, aircraftID, parentPlaneID)
     self.__nodes[aircraftNode.vo.id] = aircraftNode
     return
    def __setInstalledWeapons(self):
        """
        Use internal self.__installedWeapons to set
        """
        for slot in self.__weaponSlotsMap.itervalues():
            for conf in slot:
                conf.isInstalled = (
                    conf.weaponSlotID,
                    conf.configurationID) in self.__installedWeapons

        if self.__upgradesList is not None:
            for upgradeMap in self.__upgradesList:
                if upgradeMap['isInstalled']:
                    for slotID, configurationsList in upgradeMap[
                            'slotList'].items():
                        for configurationID in configurationsList:
                            configuration = self.getWeaponConfigurations(
                                slotID, configurationID)
                            if configuration is not None:
                                if configuration.weaponNameID == 'empty':
                                    configuration.isInstallAvailable = True
                                else:
                                    conf = findIf(
                                        self.__weaponSlotsMap[slotID],
                                        lambda conf: conf.weaponNameID ==
                                        configuration.weaponNameID)
                                    count = configuration.haveCount + conf.installedCount if conf else configuration.haveCount
                                    configuration.isInstallAvailable = configuration.neededCount <= count

        return
 def removeCarouselAirplane(self, aircraftID):
     airplane = findIf(self.__airplanesList, lambda airplane: airplane.planeID == aircraftID)
     if airplane is None:
         return
     else:
         self.__airplanesList.remove(airplane)
         self.inventory.removeAircraftFromBoughtList(aircraftID)
         return
Esempio n. 4
0
def checkTokenItems(token, pdata):
    from HelperFunctions import findIf
    from consts import PLANE_KEYS
    if token not in tokenToPack:
        return False
    _, planeID, crewMemberID, _ = tokenToPack[token]
    if planeID == 0 and crewMemberID == 0:
        return False
    inventory = pdata['inventory']
    crewExists = crewMemberID in inventory['barrack']
    planeExists = findIf(inventory['planes'],
                         lambda p: p[PLANE_KEYS.PLANE] == planeID,
                         default=False)
    return crewExists or planeExists
Esempio n. 5
0
 def __onUpdatedEliteAfterResPlane(self, planeID):
     updateNodes = self.__updateNodesResearches()
     node = findIf(self.__nodes.itervalues(), lambda n: n.vo.isAircraft and n.vo.aircraftID == planeID)
     if node:
         node.vo.aircraftGainedExp = self.__lobbyCarouselHelper.inventory.getAircraftExp(node.vo.aircraftID)
         node.vo.isResearched = True
         self.__lobby.call_1('moduleTree.updateNodes', [node.vo])
     if self.__selectedAircraft.planeID == planeID:
         self.__selectedAircraft.isResearched = True
         self.__selectedAircraft.vo.isResearched = True
     else:
         self.__updateAircraftInfoVO()
     self._updateElitePlanes(False)
     self.__lobby.call_1('moduleTree.updateNodes', updateNodes)
     self.__lobby.call_1('moduleTree.updateAircraftInfo', self.__selectedAircraft.vo)
Esempio n. 6
0
    def __updateNodeRequiredResearches(self, node):
        node.vo.requiredResearches = []
        node.vo.requiredExp = 0
        if node.vo.isResearched:
            return
        else:
            requiredResearchesNames = set()
            for parent in self.__lobbyCarouselHelper.inventory.calculateRequiredUpgradesForUpgrade(node.upgrade, node.upgradeVariant):
                if parent != node.upgrade.name:
                    parentNode = findIf(self.__nodes.itervalues(), lambda n: not n.isEmptyWeapon and n.upgrade.name == parent)
                    if parentNode:
                        node.vo.requiredResearches.append(ResearchVO(parentNode.vo.name, parentNode.groupName, parentNode.upgradeVariant.parentUpgrade[0].experience))
                        requiredResearchesNames.add(parentNode.upgrade.name)

            node.vo.requiredExp = node.vo.researchExp + self.__lobbyCarouselHelper.inventory.calculateRequiredResourcesForUpgradePresset(self.__selectedAircraft.planeID, requiredResearchesNames, None)['exp']
            return
        def sortModules(module):
            if 'level' not in module:
                return (0, 0, 0)
            elif 'type' not in module:
                return (module['level'], 0, 0)
            upgrade = dbInstance.upgrades.get(module['name'], None)
            if module['type'] == UPGRADE_TYPE.PLANER or module['type'] == UPGRADE_TYPE.TURRET:
                return (module['level'], 0, upgrade.id)
            elif module['type'] == UPGRADE_TYPE.ENGINE:
                upgradeVariantIndex = findSuitableIndex(upgrade.variant, lambda v: v.aircraftName == planeName)
                if upgradeVariantIndex is None:
                    return (module['level'], 0, upgrade.id)
                partName = findIf(upgrade.variant[upgradeVariantIndex].logicalPart, lambda p: p.type == module['type']).name
                value = 0
                for eng in filter(lambda m: m.name == partName, settings.airplane.flightModel.engine):
                    value = eng.power if hasattr(eng, 'power') else eng.thrust
                    break

                return (module['level'], value, upgrade.id)
            else:
                return (module['level'], 0, 0)
 def __getUpgrade(self, weaponName):
     if self.__upgradesList is not None:
         return findIf(self.__upgradesList,
                       lambda upgradeMap: upgradeMap['name'] == weaponName)
     else:
         return
Esempio n. 9
0
 def __updateWeaponAvailableCount(self, node):
     node.vo.availableCount = self.__lobbyCarouselHelper.inventory.getUpgradeCount(node.upgrade.name)
     conf = findIf(self.__selectedAircraft.weapons.getWeaponSlotConfigs(node.vo.slotID), lambda wc: wc.weaponNameID == node.upgrade.name and wc.isInstalled)
     if conf and self.__selectedAircraft.isBought:
         node.vo.availableCount += self.__lobbyCarouselHelper.inventory.getInstalledWeaponCount(self.__selectedAircraft.planeID, conf.weaponSlotID, conf.configurationID)
Esempio n. 10
0
    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 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 adjustPlaneConfig(planeID, upgrades, weaponList, newUpgradeName, upgradeName, weaponSlot = None, newWeaponConfig = None):

    def retFunc(u, w):
        return (db.DBLogic.createGlobalID(planeID, u, w), u, w)

    oldUpgrade = db.DBLogic.g_instance.getUpgradeByName(upgradeName) if upgradeName else None
    if oldUpgrade is not None:
        isWeapon = oldUpgrade.type in UPGRADE_TYPE.WEAPON
    else:
        isWeapon = False
    if newUpgradeName is None and not isWeapon:
        return retFunc(upgrades, weaponList)
    upgrade = db.DBLogic.g_instance.getUpgradeByName(newUpgradeName) if newUpgradeName else None
    minConfig = None
    minConfigDistance = None
    if upgrade is not None:
        isWeapon = upgrade.type in UPGRADE_TYPE.WEAPON
    newUpgrades = upgrades[:]
    newWeaponList = None
    if upgradeName is None:
        if not isWeapon:
            for upgradeName in upgrades:
                replaceUpgrade = db.DBLogic.g_instance.getUpgradeByName(upgradeName)
                if replaceUpgrade is None:
                    continue
                if replaceUpgrade.type == upgrade.type:
                    break
                upgradeName = None

    if isWeapon:
        if weaponSlot is not None and newWeaponConfig is not None:
            newWeaponList = []
            for slotInfo in weaponList:
                if slotInfo[0] == weaponSlot:
                    newWeaponList.append((slotInfo[0], newWeaponConfig))
                else:
                    newWeaponList.append(slotInfo)

    else:
        if upgradeName in newUpgrades:
            newUpgrades.remove(upgradeName)
        newUpgrades.append(upgrade.name)
    newWeaponList = newWeaponList or weaponList
    upgrades = set(upgrades)
    weaponSet = set(weaponList)
    planeName = db.DBLogic.g_instance.getAircraftData(planeID).airplane.name
    for cmpGlobalID in airplanesConfigurationsList[planeID]:
        planeConfig = airplanesConfigurations[cmpGlobalID]
        if upgrades == set(planeConfig.modules) and weaponSet == set(planeConfig.weaponSlots):
            continue
        if isWeapon:
            if getSlotIdByWeaponName(planeID, newUpgradeName, planeConfig.weaponSlots) is None:
                continue
        elif newUpgradeName not in planeConfig.modules:
            continue
        distance = getConfigDistance(newUpgrades, planeConfig.modules, newWeaponList, planeConfig.weaponSlots)
        if distance == 0:
            return retFunc(newUpgrades, newWeaponList)
        if newUpgradeName:
            upgrade = db.DBLogic.g_instance.getUpgradeByName(newUpgradeName)
            upgradeVariant = findIf(upgrade.variant, lambda var: var.aircraftName == planeName)
            parentUpgradeName = upgradeVariant.parentUpgrade[0].name
            if parentUpgradeName:
                parentUpgrade = db.DBLogic.g_instance.getUpgradeByName(parentUpgradeName)
                if parentUpgrade:
                    if parentUpgrade.type not in UPGRADE_TYPE.WEAPON:
                        if parentUpgradeName not in planeConfig.modules and parentUpgrade.type != upgrade.type:
                            continue
                    elif getSlotIdByWeaponName(planeID, parentUpgradeName, planeConfig.weaponSlots) is None:
                        if weaponSlot is None or not isWeaponInSameSlot(planeConfig, parentUpgradeName, weaponSlot):
                            continue
        if minConfigDistance is None or distance < minConfigDistance:
            minConfigDistance = distance
            minConfig = planeConfig

    if minConfig is None:
        return retFunc(list(upgrades), weaponList)
    else:
        return retFunc(minConfig.modules, minConfig.weaponSlots)
Esempio n. 13
0
 def getShopAirplane(self, airplaneID):
     return findIf(self.__shopAirplaneList,
                   lambda airplane: airplane.planeID == airplaneID)
 def getCarouselAirplane(self, airplaneID):
     return findIf(self.__airplanesList, lambda airplane: airplane.planeID == airplaneID)