def updateAmmunition(self, ammunitionData, modelPlaneStrc, globalId, planeId): modelPlaneStrc.ammunitions.clean() for slotID, confID in getAirplaneConfiguration(globalId).weaponSlots: weaponInfo = self._db.getWeaponInfo(planeId, slotID, confID) if not weaponInfo: continue wType, wName, _ = weaponInfo if wType in (UPGRADE_TYPE.BOMB, UPGRADE_TYPE.ROCKET): component = self._db.getComponentByName( UPGRADE_TYPE_TO_COMPONENT_TYPE[wType], wName) ammunitionStrc = modelPlaneStrc.ammunitions.first( lambda a: a.id.get() == slotID) if not ammunitionStrc: modelPlaneStrc.ammunitions.append( id=slotID, iconPath=component.iconPathSmall, ammoName='WEAPON_NAME_' + component.caliber, isInstalled=True) for data_ in ammunitionData: id_ = data_.key ammunitonStrc = modelPlaneStrc.ammunitions.first( lambda a: a.id.get() == id_) if ammunitonStrc: ammunitonStrc.amount = data_.value
def __createControllers(self, avatarID, globalID, partStates, camouflage=None, decals=None, pilotUpgradeId=0): aircraftConfiguration = getAirplaneConfiguration(globalID) _db = db.DBLogic.g_instance settings = _db.getAircraftData(aircraftConfiguration.planeID) turretNames = list( _db.findUpgradeNamesByGlobalIDAndType(globalID, UPGRADE_TYPE.TURRET)) self.__setupPilot(settings, aircraftConfiguration, pilotUpgradeId) player = BigWorld.player() if player.id == avatarID: player.weaponsInfo = buildAndGetWeaponsInfo( settings.components.weapons2, aircraftConfiguration.weaponSlots) return DestructibleObjectFactory.createControllers( avatarID, settings, settings.airplane, aircraftConfiguration.partTypes, partStates, aircraftConfiguration.weaponSlots, callback=partial(self.__onAvatarModelLoaded, player.id == avatarID), camouflage=camouflage, decals=decals, turretsName=turretNames)
def getPartTypes(self, moduleNamesList = None): from BWPersonality import g_lobbyCarouselHelper inv = g_lobbyCarouselHelper.inventory if inv.isAircraftBought(self.__aircraftID): aircraftConfiguration = getAirplaneConfiguration(g_lobbyCarouselHelper.inventory.getInstalledUpgradesGlobalID(self.__aircraftID)) return aircraftConfiguration.partTypes return []
def __setInstalledModule(self, modules, weapons, oldInstalledIDs, newInstalledIDs, globalID): self.__selectedAircraft.modules.setInstalledModules(modules) upgradesList = self.__lobbyCarouselHelper.inventory.getAircraftUpgradesData(self.__selectedAircraft.planeID) self.__selectedAircraft.weapons.update(upgradesList) self.__selectedAircraft.weapons.setInstalledWeapons(weapons) self.__selectedAircraft.presets.fillPresets() self.__selectedAircraft.partTypes = _airplanesConfigurations_db.getAirplaneConfiguration(globalID).partTypes self.__originPlane = self.__selectedAircraft self.__selectedAircraft = copy.deepcopy(self.__originPlane) for nodeID in oldInstalledIDs: self.__nodes[nodeID].vo.isInstalled = False for nodeID in newInstalledIDs: node = self.__nodes[nodeID] node.vo.isInstalled = True node.vo.isBought = True if not node.vo.isWeapon: node.vo.availableCount = self.__lobbyCarouselHelper.inventory.getUpgradeCount(node.upgrade.name) for nodeID, node in self.__nodes.iteritems(): if not node.isEmptyWeapon and node.vo.isWeapon: self.__updateWeaponAvailableCount(node) self.__lobby.call_1('moduleTree.updateNodes', [ node.vo for node in self.__nodes.itervalues() ]) carouselSelectedPlane = self.__lobbyCarouselHelper.getCarouselAirplaneSelected() if carouselSelectedPlane is not None and carouselSelectedPlane.planeID == self.__selectedAircraft.planeID: self.__onModulesSynced(carouselSelectedPlane) return
def __installAircraftConfigurationResp(self, globalID, callback, operation, resultID, *args): if resultID != OPERATION_RETURN_CODE.SUCCESS: aircraftConfig = _airplanesConfigurations_db.getAirplaneConfiguration(globalID) planeID = aircraftConfig.planeID self.inventory.setFinishCallback(partial(self.__onRollBackPresset, planeID, callback, operation, resultID, *args)) self.inventory.syncInventoryData() self.inventory.syncAircraftsData([planeID]) else: callback(operation, resultID, *args)
def __call__(self, account, ob, **kw): adaptedOb = super(IPlaneWeaponsForConfigAdapter, self).__call__(account, ob, **kw) if ob is None: return adaptedOb else: planeConfig = getAirplaneConfiguration(kw['idTypeList'][0][0]) if not planeConfig: return adaptedOb adaptedOb['weaponSlots'] = dict(((x[0], [x[1]]) for x in planeConfig.weaponSlots)) return adaptedOb
def __setInstalledPreset(self, globalID): if self.__lobby is not None: self.__lobby.updateMoneyPanelRequest() aircraftConfig = _airplanesConfigurations_db.getAirplaneConfiguration(globalID) upgDict = self.inventory.getPresetRequiredUpgrades(aircraftConfig.planeID, aircraftConfig.modules, aircraftConfig.weaponSlots) self.inventory.addRequiredUpgrades(upgDict) self.inventory.installAircraftConfiguration(globalID) if self.__lobby.mode == HANGAR_MODE.RESEARCH or self.__lobby.mode == HANGAR_MODE.MODULES: self.onGetUpgradesList([], aircraftConfig.planeID, reload3DModel=False) self.__lobby.researchTreeHelper.onGetAircraftUpgrades(aircraftConfig.planeID) return
def findAircraftTurretsSettingsByGlobalID(db, globalID): """ @type db: db.DBLogic.db """ modules = getAirplaneConfiguration(globalID).modules aircraftData = db.getAircraftDataByGlobalID(globalID) for moduleName in modules: turretSettings = findAircraftTurretSettingsByTurretName(aircraftData, moduleName) if turretSettings is not None: yield turretSettings return
def _updateAvatarPlaneTypeRank(self, avatarID, *args, **kwargs): """Update rank for avatar in model. :param avatarID: Identifier of Avatar to update """ avatarInfo = self._clientArena.avatarInfos[avatarID] settings = avatarInfo.get('settings') if not settings: globalID = avatarInfo['airplaneInfo']['globalID'] import _airplanesConfigurations_db planeID = _airplanesConfigurations_db.getAirplaneConfiguration( globalID).planeID settings = self._db.getAircraftData(planeID) currentPlaneType = settings.airplane.planeType currentRankID = avatarInfo['planeTypeRank'][currentPlaneType] avatarModel = self._model.avatars.first( lambda e: e.id.get() == avatarID) if avatarModel: avatarModel.rankID = currentRankID
def _addAvatarFromInfo(self, avatarInfo, id): settings = avatarInfo.get('settings') if not settings: globalID = avatarInfo['airplaneInfo']['globalID'] import _airplanesConfigurations_db planeID = _airplanesConfigurations_db.getAirplaneConfiguration( globalID).planeID settings = self._db.getAircraftData(planeID) untypedName = avatarInfo.get('playerName', '') globalID = avatarInfo['airplaneInfo']['globalID'] currentPlaneType = settings.airplane.planeType currentRankID = avatarInfo['planeTypeRank'][currentPlaneType] if type(untypedName) is unicode: playerName = untypedName else: playerName = unicode(untypedName, 'utf-8') return self._model.avatars.append( id=id, clanName=unicode(avatarInfo.get('clanAbbrev', '')), playerName=playerName, planeGlobalID=globalID, isDefender=bool(avatarInfo.get('defendSector')), isBot=bool(avatarInfo.get('databaseID') == 0), planeType=settings.airplane.planeType, planeName=localizeAirplane(settings.airplane.name), planeLevel=settings.airplane.level, previewIconPath=settings.airplane.previewIconPath, teamIndex=getClientTeamIndex(avatarInfo['teamIndex'], self._playerAvatar.teamIndex), squadIndex=avatarInfo['squadID'], maxHealth=int(ceil(avatarInfo['maxHealth'])), points=avatarInfo['economics']['totalBattlePoints'], inWorld=False, state=getLogicState(avatarInfo), isLost=checkLost(avatarInfo), rankID=currentRankID)
def __onNewAvatarsInfo(self, argStr): newAvatarsList = translateDictThroughAnother( wgPickle.loads(wgPickle.FromServerToClient, argStr), NEW_AVATARS_INFO_KEYS_INVERT_DICT, True) LOG_INFO('__onNewAvatarsInfo', self.__ownerID, [avatarData['avatarID'] for avatarData in newAvatarsList]) LOG_INFO('INFO extUpgrades', [(avatarData['avatarID'], avatarData['extUpgrades']) for avatarData in newAvatarsList]) for avatarData in newAvatarsList: avatarID = avatarData['avatarID'] airplaneInfo = avatarData['airplaneInfo'] currentOwner = None avatarData['planeTypeRank'] = dict(avatarData['planeTypeRank']) avatarPrevInfo = self.avatarInfos.get(avatarID, None) if not avatarPrevInfo: self.avatarInfos[avatarID] = avatarData else: if 'airplaneInfo' in avatarPrevInfo and avatarPrevInfo[ 'airplaneInfo']['globalID'] != airplaneInfo['globalID']: self.onBeforePlaneChanged(avatarID) currentOwner = self.__destroyControllers(avatarPrevInfo) self.avatarInfos[avatarID].update(avatarData) extUpgrades = dict(avatarData['extUpgrades']) pilotUpgradeId = extUpgrades.get(LOGICAL_PART.PILOT, 1) controllersData = self.createControllers( avatarID, airplaneInfo['globalID'], camouflage=airplaneInfo['camouflage'], decals=airplaneInfo['decals'], pilotUpgradeId=pilotUpgradeId) if currentOwner: currentOwner.registerControllers(controllersData) self.onAvatarChangedPlane(currentOwner.id) if currentOwner == BigWorld.player(): self.onRecreateAvatar() avatarInfo = self.avatarInfos[avatarID] if avatarInfo['isNPC']: if avatarInfo['NPCType'] == ACNPCTypes.Bomber: avatarInfo['playerName'] = localizeLobby( avatarInfo['playerName']) elif avatarInfo['NPCType'] == ACNPCTypes.Defender: avatarInfo['playerName'] = localizeHUD( avatarInfo['playerName']) else: avatarInfo['playerName'] = getBotName( avatarData['playerName'], getAirplaneConfiguration(airplaneInfo['globalID']).planeID) avatarInfo['maxHealth'] = avatarData['maxHealth'] avatarInfo['equipment'] = avatarData['equipment'] if avatarID == BigWorld.player().id: LOG_TRACE('ClientArena: VOIP.initialize()') wasInit = bool(VOIP.api()) VOIP.initialize(avatarInfo['databaseID']) if not wasInit: VOIP.api().onEnterArenaScreen() self.__sortAvatars() for ids in self.__sortedAvatarsIDs.values(): for i, avatarID in enumerate(ids): self.avatarInfos[avatarID]['airplaneInfo']['decals'][4] = i + 1 self.avatarInfos[avatarID][ 'modelManipulator'].surface.setDecalsByIds( self.avatarInfos[avatarID]['airplaneInfo'] ['camouflage'], self.avatarInfos[avatarID]['airplaneInfo']['decals']) teamMembers = dict() for avatarID, info in self.avatarInfos.iteritems(): if info['teamIndex'] == BigWorld.player().teamIndex: teamMembers[info['databaseID']] = avatarID VOIP.api().unsubscribeMemberStateObserversByType( consts.VOIP.MEMBER_STATUS_OBSERVER_TYPES.ARENA_HUD) VOIP.api().subscribeMemberStateObserver( consts.VOIP.MEMBER_STATUS_OBSERVER_TYPES.ARENA_HUD, teamMembers) self.__avatarsDataReceived = True self.onNewAvatarsInfo(newAvatarsList) return
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 __get_bomb_hatch_close_offset(self): ac = getAirplaneConfiguration(self._owner.globalID) obj_db_data = db.DBLogic.g_instance.getAircraftData( ac.planeID).airplane return getattr(obj_db_data.visualSettings, 'bombHatchCloseOffset', 1)
def previewCrewSpecList(aircraftID): settings = db.DBLogic.g_instance.getAircraftData(aircraftID) globalID = airplanesDefaultConfigurations[aircraftID] config = getAirplaneConfiguration(globalID) return getCrewSpecialization(settings.airplane.partsSettings, config.partTypes)