def getDescr(self, respawnCompactDescr): if respawnCompactDescr is not None: descr = vehicles.VehicleDescr(respawnCompactDescr) self.health = descr.maxHealth return descr else: return vehicles.VehicleDescr(compactDescr=_stripVehCompDescrIfRoaming(self.publicInfo.compDescr))
def prerequisites(self, respawnCompactDescr=None): if self.respawnCompactDescr is not None: respawnCompactDescr = self.respawnCompactDescr self.isCrewActive = True self.respawnCompactDescr = None if respawnCompactDescr is None and self.typeDescriptor is not None: return () else: prereqs = [] if respawnCompactDescr is not None: descr = vehicles.VehicleDescr(respawnCompactDescr) self.health = descr.maxHealth else: descr = vehicles.VehicleDescr( compactDescr=_stripVehCompDescrIfRoaming( self.publicInfo.compDescr)) self.typeDescriptor = descr prereqs += descr.prerequisites( self.physicsMode == VEHICLE_PHYSICS_MODE.DETAILED) for hitTester in descr.getHitTesters(): if hitTester.bspModelName is not None and not hitTester.isBspModelLoaded( ): prereqs.append(hitTester.bspModelName) self.assembler = vehicle_assembler.createAssembler(self) self.appearance = self.assembler.appearance prereqs += self.assembler.prerequisites() return prereqs
def getDescr(self, respawnCompactDescr): if respawnCompactDescr is not None: descr = vehicles.VehicleDescr(respawnCompactDescr) if 'battle_royale' in descr.type.tags: pass else: self.health = self.publicInfo.maxHealth return descr else: return vehicles.VehicleDescr( compactDescr=_stripVehCompDescrIfRoaming( self.publicInfo.compDescr))
def __init__(self, strCompactDescr = None, inventoryID = -1, typeCompDescr = None, proxy = None): if strCompactDescr is not None: vehDescr = vehicles.VehicleDescr(compactDescr=strCompactDescr) else: raise typeCompDescr is not None or AssertionError _, nID, innID = vehicles.parseIntCompactDescr(typeCompDescr) vehDescr = vehicles.VehicleDescr(typeID=(nID, innID)) self.__descriptor = vehDescr HasStrCD.__init__(self, strCompactDescr) FittingItem.__init__(self, vehDescr.type.compactDescr, proxy) self.inventoryID = inventoryID self.xp = 0 self.dailyXPFactor = -1 self.isElite = False self.clanLock = 0 self.isUnique = self.isHidden invData = dict() if proxy is not None: invDataTmp = proxy.inventory.getItems(vehicles._VEHICLE, inventoryID) if invDataTmp is not None: invData = invDataTmp self.xp = proxy.stats.vehiclesXPs.get(self.intCD, self.xp) self.dailyXPFactor = proxy.shop.dailyXPFactor if self.intCD not in proxy.stats.multipliedVehicles else self.dailyXPFactor self.isElite = len(vehDescr.type.unlocksDescrs) == 0 or self.intCD in proxy.stats.eliteVehicles clanDamageLock = proxy.stats.vehicleTypeLocks.get(self.intCD, {}).get(CLAN_LOCK, 0) clanNewbieLock = proxy.stats.globalVehicleLocks.get(CLAN_LOCK, 0) self.clanLock = clanDamageLock or clanNewbieLock self.inventoryCount = 1 if len(invData.keys()) else 0 self.settings = invData.get('settings', 0) self.lock = invData.get('lock', 0) self.repairCost, self.health = invData.get('repair', (0, 0)) self.gun = VehicleGun(vehDescr.gun['compactDescr'], proxy, vehDescr.gun) self.turret = VehicleTurret(vehDescr.turret['compactDescr'], proxy, vehDescr.turret) self.engine = VehicleEngine(vehDescr.engine['compactDescr'], proxy, vehDescr.engine) self.chassis = VehicleChassis(vehDescr.chassis['compactDescr'], proxy, vehDescr.chassis) self.radio = VehicleRadio(vehDescr.radio['compactDescr'], proxy, vehDescr.radio) self.fuelTank = VehicleFuelTank(vehDescr.fuelTank['compactDescr'], proxy, vehDescr.fuelTank) self.sellPrice = self._calcSellPrice(proxy) self.optDevices = self._parserOptDevs(vehDescr.optionalDevices, proxy) gunAmmoLayout = [] for shell in self.gun.defaultAmmo: gunAmmoLayout += (shell.intCD, shell.defaultCount) self.shells = self._parseShells(invData.get('shells', list()), invData.get('shellsLayout', dict()).get(self.shellsLayoutIdx, gunAmmoLayout), proxy) self.eqs = self._parseEqs(invData.get('eqs') or [0, 0, 0], proxy) self.eqsLayout = self._parseEqs(invData.get('eqsLayout') or [0, 0, 0], proxy) defaultCrew = [None] * len(vehDescr.type.crewRoles) crewList = invData.get('crew', defaultCrew) self.bonuses = self._calcCrewBonuses(crewList, proxy) self.crewIndices = dict([ (invID, idx) for idx, invID in enumerate(crewList) ]) self.crew = self._buildCrew(crewList, proxy) return
def exhibit(tankNames = None, pivotPoint = None, shift = Vector3(0, 0, 10), assembler = assembleCompoundModel2): if pivotPoint is None: p = Vector3(BigWorld.camera().position) d = BigWorld.camera().direction spaceID = BigWorld.player().spaceID if BigWorld.player() is not None else BigWorld.camera().spaceID collRes = BigWorld.wg_collideSegment(spaceID, p, p + d * 1000, 18, 8) if collRes is None: pivotPoint = Vector3(0, 0, 0) else: strikePos = collRes[0] pivotPoint = strikePos if tankNames is None: tankNames = [ vehicles.g_cache.vehicle(0, x).name for x in xrange(EXAMPLE_COUNT) ] totalTanks = len(tankNames) shift_new = Vector3(d) shift_new.y = 0.0 up = Vector3(0.0, 1.0, 0.0) right = up * shift_new shift_new.normalise() right.normalise() offset = 6.0 shift_new = shift_new * offset right = right * offset for idx, tankName in enumerate(tankNames): desc = vehicles.VehicleDescr(typeName=tankName) if idx < totalTanks / 2: creationPosition = pivotPoint + shift_new * idx else: creationPosition = pivotPoint + shift_new * (idx - totalTanks / 2) + right assembler(getModelNames(desc), creationPosition, desc) return
def __vehicleInfoAsDict(self, info): getVehicleType = lambda cd: None if cd is None else vehicles.VehicleDescr( compactDescr=cd) infoAsDict = { 'vehicleType': getVehicleType(info[1]), 'name': info[2], 'team': info[3], 'isAlive': info[4], 'isAvatarReady': info[5], 'isTeamKiller': info[6], 'accountDBID': info[7], 'clanAbbrev': info[8], 'clanDBID': info[9], 'prebattleID': info[10], 'isPrebattleCreator': bool(info[11]), 'forbidInBattleInvitations': bool(info[12]), 'events': info[13], 'igrType': info[14], 'personalMissionIDs': info[15], 'personalMissionInfo': info[16], 'crewGroup': info[17], 'ranked': info[18], 'outfitCD': info[19] } return (info[0], infoAsDict)
def __getVehiclePriceFromCache(self, vehCompDescr, default = (0, 0)): typeCompDescr = vehicles.getVehicleTypeCompactDescr(vehCompDescr) price = self.__getPriceFromCache(typeCompDescr, None) if price is None: return default else: vehDescr = vehicles.VehicleDescr(compactDescr=vehCompDescr) devices = vehDescr.getDevices() for defCompDescr, instCompDescr in izip(devices[0], devices[1]): if defCompDescr == instCompDescr: continue compPrice = self.__getPriceFromCache(defCompDescr, None) if compPrice is None: return default price = _subtractPrices(price, compPrice) compPrice = self.__getPriceFromCache(instCompDescr, None) if compPrice is None: return default price = _summPrices(price, compPrice) for optDevCompDescr in devices[2]: compPrice = self.__getPriceFromCache(optDevCompDescr, None) if compPrice is None: return default price = _summPrices(price, compPrice) return price
def load(self): vehilesList = vehicles.g_list.getList for nationID in nations.INDICES.itervalues(): self._local[nationID] = [ vehicles.VehicleDescr(typeID=(nationID, cd)) for cd in vehilesList(nationID).iterkeys() ]
def __init__(self, strCompactDescr, inventoryID=-1, vehicle=None, dismissedAt=None, proxy=None): GUIItem.__init__(self, proxy) HasStrCD.__init__(self, strCompactDescr) self.__descriptor = None self._invID = inventoryID self._nationID = self.descriptor.nationID self._itemTypeID = GUI_ITEM_TYPE.TANKMAN self._itemTypeName = ITEM_TYPE_NAMES[self.itemTypeID] self._combinedRoles = (self.descriptor.role,) self._dismissedAt = dismissedAt self._isDismissed = self.dismissedAt is not None self._areClassesCompatible = False self._vehicleNativeDescr = vehicles.VehicleDescr(typeID=(self.nationID, self.descriptor.vehicleTypeID)) self._vehicleInvID = -1 self._vehicleDescr = None self._vehicleBonuses = dict() self._vehicleSlotIdx = -1 if vehicle is not None: self._vehicleInvID = vehicle.invID self._vehicleDescr = vehicle.descriptor self._vehicleBonuses = dict(vehicle.bonuses) self._vehicleSlotIdx = vehicle.crewIndices.get(inventoryID, -1) crewRoles = self.vehicleDescr.type.crewRoles if -1 < self.vehicleSlotIdx < len(crewRoles): self._combinedRoles = crewRoles[self.vehicleSlotIdx] self._areClassesCompatible = bool(VEHICLE_CLASS_TAGS & self.vehicleDescr.type.tags & self.vehicleNativeDescr.type.tags) self._skills = self._buildSkills(proxy) self._skillsMap = self._buildSkillsMap() self.__cmp__ = TankmenComparator() return
def __makeFakeDescriptor(self): vehType = vehicles.VehicleDescr(typeID=(0, 0)).type skills = self._getSkillsForDescr() freeSkills = self._getFreeSkillsForDescr() tmanDescr = tankmen.TankmanDescr(tankmen.generateCompactDescr(tankmen.generatePassport(vehType.id[0], False), vehType.id[1], vehType.crewRoles[0][0], self._roleLevel, skills=skills, freeSkills=freeSkills, lastSkillLevel=self._lastSkillLevel)) tmanDescr.addXP(self._freeXP) return tmanDescr
def __makeVehicle(self, vehInvID): if vehInvID not in self.__vehsCDsByID: return else: typeCompDescr = self.__vehsCDsByID[vehInvID] cache = self.__itemsCache[GUI_ITEM_TYPE.VEHICLE] if typeCompDescr in cache: return cache[typeCompDescr] itemsInvData = self.getCacheValue(GUI_ITEM_TYPE.VEHICLE, {}) def value(key, default=None): return itemsInvData.get(key, {}).get(vehInvID, default) compactDescr = value('compDescr') if compactDescr is None: return try: item = cache[typeCompDescr] = self.VEH_DATA( value('compDescr'), vehicles.VehicleDescr(compactDescr=compactDescr), vehInvID, value('repair', 0), value('crew', []), value('lock', 0), value('settings', 0), value('shells', []), value('shellsLayout', []), value('eqs', []), value('eqsLayout', [])) except Exception: LOG_DEBUG('Error while building vehicle from inventory', vehInvID, typeCompDescr) return return item
def _getActiveOutfit(self, vDesc): tankInfo = self.__tankInfo if tankInfo is None: if vDesc: vehicleCD = vDesc.makeCompactDescr() return self.customizationService.getEmptyOutfitWithNationalEmblems( vehicleCD=vehicleCD) return self.itemsFactory.createOutfit() else: vehCompDescr = tankInfo.vehCompDescr if tankInfo.vehOutfitCD: if vDesc is None: vDesc = vehicles.VehicleDescr(vehCompDescr) outfitComp = camouflages.getOutfitComponent( outfitCD=tankInfo.vehOutfitCD, vehicleDescriptor=vDesc, seasonType=tankInfo.seasonType) outfit = self.itemsFactory.createOutfit(component=outfitComp, vehicleCD=vehCompDescr) forceHistorical = self.settingsCore.getSetting( GAME.CUSTOMIZATION_DISPLAY_TYPE ) < outfit.customizationDisplayType() if forceHistorical: outfit = None else: outfit = None if outfit is None: outfit = self.customizationService.getEmptyOutfitWithNationalEmblems( vehicleCD=vehCompDescr) return outfit
def __validateInventoryOutfit(self): c11nData = self.itemsCache.items.inventory.getCacheValue( GUI_ITEM_TYPE.CUSTOMIZATION, {}) for vehIntCD, outfitsData in c11nData.get( constants.CustomizationInvData.OUTFITS, {}).iteritems(): vehicleData = self.itemsCache.items.inventory.getItemData(vehIntCD) if vehicleData is not None: vehicleCD = vehicleData.compDescr else: _, nationID, vehicleTypeID = vehicles.parseIntCompactDescr( vehIntCD) vehicleDesc = vehicles.VehicleDescr(typeID=(nationID, vehicleTypeID)) vehicleCD = vehicleDesc.makeCompactDescr() for outfitCD in outfitsData.itervalues(): try: self.itemsFactory.createOutfit(strCompactDescr=outfitCD, vehicleCD=vehicleCD) except Exception as e: raise ValidateException( e.message, ValidationCodes.OUTFIT_MISMATCH, _packItemData(GUI_ITEM_TYPE.CUSTOMIZATION, (vehIntCD, outfitCD))) return
def __readBonus_vehicle(bonus, _name, section): vehCompDescr = None if section.has_key('vehCompDescr'): vehCompDescr = section['vehCompDescr'].asString.decode('base64') vehTypeCompDescr = vehicles.VehicleDescr(vehCompDescr).type.compactDescr else: nationID, innationID = vehicles.g_list.getIDsByName(section.asString) vehTypeCompDescr = vehicles.makeIntCompactDescrByID('vehicle', nationID, innationID) extra = {} if section.has_key('tankmen'): __readBonus_tankmen(extra, vehTypeCompDescr, section['tankmen']) else: if section.has_key('noCrew'): extra['noCrew'] = True if section.has_key('crewLvl'): extra['crewLvl'] = section['crewLvl'].asInt if section.has_key('crewFreeXP'): extra['crewFreeXP'] = section['crewFreeXP'].asInt if section.has_key('rent'): __readBonus_rent(extra, None, section['rent']) if section.has_key('customCompensation'): credits = section['customCompensation'].readInt('credits', 0) gold = section['customCompensation'].readInt('gold', 0) extra['customCompensation'] = (credits, gold) bonus.setdefault('vehicles', {})[vehCompDescr if vehCompDescr else vehTypeCompDescr] = extra return
def __init__(self, strCompactDescr, inventoryID=-1, vehicle=None, proxy=None): GUIItem.__init__(self, proxy) HasStrCD.__init__(self, strCompactDescr) self.__descriptor = None self.invID = inventoryID self.nationID = self.descriptor.nationID self.itemTypeID = vehicles._TANKMAN self.itemTypeName = ITEM_TYPE_NAMES[self.itemTypeID] self.combinedRoles = (self.descriptor.role, ) self.vehicleNativeDescr = vehicles.VehicleDescr( typeID=(self.nationID, self.descriptor.vehicleTypeID)) self.vehicleInvID = -1 self.vehicleDescr = None self.vehicleBonuses = dict() self.vehicleSlotIdx = -1 if vehicle is not None: self.vehicleInvID = vehicle.invID self.vehicleDescr = vehicle.descriptor self.vehicleBonuses = dict(vehicle.bonuses) self.vehicleSlotIdx = vehicle.crewIndices.get(inventoryID, -1) crewRoles = self.vehicleDescr.type.crewRoles if -1 < self.vehicleSlotIdx < len(crewRoles): self.combinedRoles = crewRoles[self.vehicleSlotIdx] self.skills = self._buildSkills(proxy) self.skillsMap = self._buildSkillsMap() if proxy is not None: pass self.__cmp__ = TankmenComparator()
def onVehiclesUpdate(self, vehiclesDescr): if vehiclesDescr is not None and g_currentVehicle.isPresent(): vCompDescr = vehiclesDescr.get(g_currentVehicle.invID) if vCompDescr is not None: self.toggle(isOn=self.isOn( vehicles.VehicleDescr(compactDescr=vCompDescr))) return
def __getDescriptorOfCurrentVehicle(): igrRoomType = g_instance.igr.getRoomType() igrLayout = g_itemsCache.items.inventory.getIgrCustomizationsLayout() veh = g_currentVehicle.item defaultVehCompDescr = veh.descriptor.makeCompactDescr() igrVehCompDescr = getIGRCustomizedVehCompDescr(igrLayout, veh.invID, igrRoomType, defaultVehCompDescr) igrDescr = vehicles.VehicleDescr(igrVehCompDescr) return igrDescr
def recreateVehicle(self, typeDescriptor=None, state=ModelStates.UNDAMAGED, callback=None): if self.__heroTankName: self.typeDescriptor = vehicles.VehicleDescr( typeName=self.__heroTankName) super(HeroTank, self).recreateVehicle(typeDescriptor, state, callback)
def debugReloadHero(heroName): if not IS_DEVELOPMENT: return for e in BigWorld.entities.values(): if isinstance(e, HeroTank): heroDescriptor = vehicles.VehicleDescr(typeName=heroName) e.recreateVehicle(heroDescriptor) return
def __getItemsDescriptors(self, itemType, idx): iterator = CACHE_ITERATORS[itemType](idx) if itemType == ITEM_TYPES.vehicle: return [vehicles.VehicleDescr(typeID=(idx, cd)) for cd in iterator] return [ vehicles.getItemByCompactDescr(data.compactDescr) for data in iterator ]
def getUpdatedDescriptor(vehDescr): igrRoomType = g_instance.igr.getRoomType() igrLayout = g_itemsCache.items.inventory.getIgrCustomizationsLayout() igrVehCompDescr = getIGRCustomizedVehCompDescr(igrLayout, g_currentVehicle.item.invID, igrRoomType, vehDescr.makeCompactDescr()) return vehicles.VehicleDescr(igrVehCompDescr)
def descriptor(self): if self.__descriptor is None: if self.itemTypeName == _VEHICLE_TYPE_NAME: self.__descriptor = vehicles.VehicleDescr( typeID=(self.nationID, self.compTypeID)) else: self.__descriptor = vehicles.getDictDescr(self.compactDescr) return self.__descriptor
def __makeFakeTankmanDescr(startRoleLevel, freeXpValue, typeID): vehType = vehicles.VehicleDescr(typeID=typeID).type tmanDescr = tankmen.TankmanDescr( tankmen.generateCompactDescr( tankmen.generatePassport(vehType.id[0], False), vehType.id[1], vehType.crewRoles[0][0], startRoleLevel)) tmanDescr.addXP(freeXpValue) return tmanDescr
def __getVehicleForScenario(self, scenario): configuration = self.mapsTrainingController.getConfig() mapId = ArenaType.g_geometryNamesToIDs[self.__selectedMap] for vehCompDescr in configuration['vehicles'][mapId]: vehDescr = vehicles.VehicleDescr( typeID=vehicles.parseIntCompactDescr(vehCompDescr)[1:]) vehicleData = self.itemsCache.items.getStockVehicle(vehCompDescr) if scenario.vehicleType == vehicleData.type: return (vehDescr.name, vehicleData.userName)
def __getVehicleDescr(self, vehicleCD=None, vehicleName=None): if vehicleCD is not None: itemTypeId, nationId, innationId = parseIntCompactDescr(vehicleCD) elif vehicleName is not None: nationId, innationId = vehicles.g_list.getIDsByName(vehicleName) else: _logger.error('Do not specified correct vehicle int cd or vehicle name!') return return vehicles.VehicleDescr(typeID=(nationId, innationId))
def overrideVehicleDescr(self, respawnCompactDescr): if BattleReplayPatch.needToOverrideVehicleInReplay(): descr = vehicles.VehicleDescr(typeName=BattleReplayPatch.vehicleName) return descr elif BattleReplayPatch.vehicleDescrSource is not None: return BattleReplayPatch.vehicleDescrSource(self, respawnCompactDescr) else: return 0 return
def reload(self): wasStarted = self.isStarted if self.isStarted: self.stopVisual() vehicles.reload() self.typeDescriptor = vehicles.VehicleDescr(compactDescr=self.publicInfo.compDescr) if wasStarted: self.appearance = VehicleAppearance.VehicleAppearance() self.appearance.prerequisites(self) self.startVisual()
def debugDisplayTankModel(self, tankTypeName): if tankTypeName: vDescriptor = vehicles.VehicleDescr(typeName=tankTypeName) tankInfo = PlatoonTankInfo(True, vDescriptor.makeCompactDescr(), '', SeasonType.SUMMER, 0, 0, vDescriptor.type.userString) else: tankInfo = PlatoonTankInfo(True, '', '', SeasonType.SUMMER, 0, 0, '') self._updatePlatoonTank({self.slotIndex: tankInfo})
def updateVehiclesStats(self, updated, arenaDP): getVehicleInfo = arenaDP.getVehicleInfo for _, vStatsVO in updated: vInfoVO = getVehicleInfo(vStatsVO.vehicleID) if isSpawnedBot( vInfoVO.vehicleType.tags ) and vStatsVO.spottedStatus == VehicleSpottedStatus.SPOTTED: vehicleDescr = vehicles.VehicleDescr( compactDescr=vInfoVO.vehicleType.strCompactDescr) if vehicleDescr.type.name == self.__KAMIKAZE_VEH_NAME: BREvents.playSound(BREvents.KAMIKAZE_DETECTED)
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, '')