def artifactComparator(vehicle, item, slotIdx, compareWithEmptySlot=False): vehicleParams = params.VehicleParams(vehicle).getParamsDict() if item.itemTypeID == ITEM_TYPES.optionalDevice: removable, notRemovable = vehicle.descriptor.installOptionalDevice( item.intCD, slotIdx) withItemParams = params.VehicleParams(vehicle).getParamsDict( preload=True) removed = removable or notRemovable if removed: if compareWithEmptySlot: vehicle.descriptor.removeOptionalDevice(slotIdx) vehicleParams = params.VehicleParams(vehicle).getParamsDict( preload=True) vehicle.descriptor.installOptionalDevice(removed[0], slotIdx) else: vehicle.descriptor.removeOptionalDevice(slotIdx) else: consumables = vehicle.consumables.installed if item.itemTypeID == ITEM_TYPES.equipment else vehicle.battleBoosters.installed oldEq = consumables[slotIdx] if compareWithEmptySlot: consumables[slotIdx] = None vehicleParams = params.VehicleParams(vehicle).getParamsDict() consumables[slotIdx] = item withItemParams = params.VehicleParams(vehicle).getParamsDict() consumables[slotIdx] = oldEq return VehiclesComparator(withItemParams, vehicleParams)
def shellOnVehicleComparator(shell, vehicle): vDescriptor = vehicle.descriptor oldIdx = vDescriptor.activeGunShotIndex vehicleParams = params.VehicleParams(vehicle).getParamsDict() idx, _ = findFirst(lambda (i, s): s.shell.compactDescr == shell.intCD, enumerate(vDescriptor.gun.shots), (0, None)) vDescriptor.activeGunShotIndex = idx newParams = params.VehicleParams(vehicle).getParamsDict(preload=True) vDescriptor.activeGunShotIndex = oldIdx return VehiclesComparator(newParams, vehicleParams)
def idealCrewComparator(vehicle): vehicleParamsObject = params.VehicleParams(vehicle) vehicleParams = vehicleParamsObject.getParamsDict() bonuses = vehicleParamsObject.getBonuses(vehicle) penalties = vehicleParamsObject.getPenalties(vehicle) compatibleArtefacts = g_paramsCache.getCompatibleArtefacts(vehicle) idealCrewVehicle = copy.copy(vehicle) idealCrewVehicle.crew = vehicle.getPerfectCrew() perfectVehicleParams = params.VehicleParams(idealCrewVehicle).getParamsDict() return VehiclesComparator(vehicleParams, perfectVehicleParams, compatibleArtefacts, bonuses, penalties)
def artifactRemovedComparator(vehicle, item, slotIdx): vehicleParams = params.VehicleParams(vehicle).getParamsDict() if item.itemTypeID == ITEM_TYPES.optionalDevice: oldOptDevice = vehicle.optDevices[slotIdx] vehicle.descriptor.removeOptionalDevice(slotIdx) withItemParams = params.VehicleParams(vehicle).getParamsDict() vehicle.descriptor.installOptionalDevice(oldOptDevice.intCD, slotIdx) else: consumables = vehicle.equipment.regularConsumables if item.itemTypeID == ITEM_TYPES.equipment else vehicle.equipment.battleBoosterConsumables oldEq = consumables[slotIdx] consumables[slotIdx] = None withItemParams = params.VehicleParams(vehicle).getParamsDict() consumables[slotIdx] = oldEq return VehiclesComparator(withItemParams, vehicleParams)
def artifactComparator(vehicle, item, slotIdx): vehicleParams = params.VehicleParams(vehicle).getParamsDict() if item.itemTypeID == ITEM_TYPES.optionalDevice: removable, notRemovable = vehicle.descriptor.installOptionalDevice(item.intCD, slotIdx) withItemParams = params.VehicleParams(vehicle).getParamsDict() removed = removable or notRemovable if removed: vehicle.descriptor.installOptionalDevice(removed[0], slotIdx) else: vehicle.descriptor.removeOptionalDevice(slotIdx) else: oldEq = vehicle.eqs[slotIdx] vehicle.eqs[slotIdx] = item withItemParams = params.VehicleParams(vehicle).getParamsDict() vehicle.eqs[slotIdx] = oldEq return VehiclesComparator(withItemParams, vehicleParams)
def camouflageComparator(vehicle, camo, factory=None): currParams = params.VehicleParams(vehicle).getParamsDict() if camo: season = first(camo.seasons) outfit = vehicle.getOutfit(season) if not outfit: outfit = factory.createOutfit(isEnabled=True, isInstalled=True) vehicle.setCustomOutfit(season, outfit) slot = outfit.hull.slotFor(GUI_ITEM_TYPE.CAMOUFLAGE) oldCamo = slot.getItem() slot.set(camo) newParams = params.VehicleParams(vehicle).getParamsDict(preload=True) if oldCamo: slot.set(oldCamo) else: slot.clear() else: newParams = currParams.copy() return VehiclesComparator(newParams, currParams)
def camouflageComparator(vehicle, camouflage): """ :param vehicle: instance of gui.shared.gui_items.Vehicle.Vehicle :param camouflage: instance of gui.customization.elements.Camouflage :return: instance of VehiclesComparator """ vDescr = vehicle.descriptor currParams = params.VehicleParams(vehicle).getParamsDict() camouflageID = camouflage.getID() camouflageInfo = vehicles.g_cache.customization(vDescr.type.customizationNationID)['camouflages'].get(camouflageID) if camouflageInfo is not None: pos = camouflageInfo['kind'] oldCamouflageData = vDescr.camouflages[pos] vDescr.setCamouflage(pos, camouflageID, int(time.time()), 0) newParams = params.VehicleParams(vehicle).getParamsDict() vDescr.setCamouflage(pos, *oldCamouflageData) else: newParams = currParams.copy() return VehiclesComparator(newParams, currParams)
def camouflageComparator(vehicle, camo, factory=None): currParams = params.VehicleParams(vehicle).getParamsDict() if camo: season = first(camo.seasons) outfit = vehicle.getOutfit(season) if not outfit: outfit = factory.createOutfit(vehicleCD=vehicle.descriptor.makeCompactDescr()) vehicle.setCustomOutfit(season, outfit) slot = outfit.hull.slotFor(GUI_ITEM_TYPE.CAMOUFLAGE) oldCamoCD = slot.getItemCD() oldComponent = slot.getComponent() slot.set(camo.intCD) newParams = params.VehicleParams(vehicle).getParamsDict(preload=True) if oldCamoCD: slot.set(oldCamoCD, component=oldComponent) else: slot.clear() else: newParams = currParams.copy() return VehiclesComparator(newParams, currParams)
def itemOnVehicleComparator(vehicle, item): vehicleParams = params.VehicleParams(vehicle).getParamsDict() withItemParams = vehicleParams mayInstall, reason = vehicle.descriptor.mayInstallComponent(item.intCD) if item.itemTypeID == ITEM_TYPES.vehicleTurret: mayInstall, reason = vehicle.descriptor.mayInstallTurret(item.intCD, vehicle.gun.intCD) if not mayInstall: properGun = findFirst(lambda gun: vehicle.descriptor.mayInstallComponent(gun.compactDescr)[0], item.descriptor.guns) if properGun is not None: removedModules = vehicle.descriptor.installTurret(item.intCD, properGun.compactDescr) withItemParams = params.VehicleParams(vehicle).getParamsDict() vehicle.descriptor.installTurret(*removedModules) else: LOG_ERROR('not possible to install turret', item, reason) else: removedModules = vehicle.descriptor.installTurret(item.intCD, vehicle.gun.intCD) withItemParams = params.VehicleParams(vehicle).getParamsDict() vehicle.descriptor.installTurret(*removedModules) elif not mayInstall: if reason == 'not for current vehicle' and item.itemTypeID == ITEM_TYPES.vehicleGun: turret = g_paramsCache.getPrecachedParameters(item.intCD).getTurretsForVehicle(vehicle.intCD)[0] removedModules = vehicle.descriptor.installTurret(turret, vehicle.gun.intCD) vehicleParams = params.VehicleParams(vehicle).getParamsDict() vehicle.descriptor.installTurret(turret, item.intCD) withItemParams = params.VehicleParams(vehicle).getParamsDict() vehicle.descriptor.installTurret(*removedModules) else: LOG_WARNING('Module {} cannot be installed on vehicle {}'.format(item, vehicle)) return VehiclesComparator(withItemParams, vehicleParams) else: removedModule = vehicle.descriptor.installComponent(item.intCD) withItemParams = params.VehicleParams(vehicle).getParamsDict() vehicle.descriptor.installComponent(removedModule[0]) return VehiclesComparator(withItemParams, vehicleParams)
def camouflageComparator(vehicle, camo, factory=None): """ :param vehicle: instance of gui.shared.gui_items.Vehicle.Vehicle :param camo: instance of gui.shared.gui_items.customization.c11n_items.Camouflage :return: instance of VehiclesComparator """ currParams = params.VehicleParams(vehicle).getParamsDict() if camo: season = first(camo.seasons) outfit = vehicle.getOutfit(season) if not outfit: outfit = factory.createOutfit(isEnabled=True) vehicle.setCustomOutfit(season, outfit) slot = outfit.hull.slotFor(GUI_ITEM_TYPE.CAMOUFLAGE) oldCamo = slot.getItem() slot.set(camo) newParams = params.VehicleParams(vehicle).getParamsDict(preload=True) if oldCamo: slot.set(oldCamo) else: slot.clear() else: newParams = currParams.copy() return VehiclesComparator(newParams, currParams)
def _packBlocks(self, *args): self.__skillType = args[0] self.__showParams = args[1] items = [self.__packTitleBlock(), self.__packStatusBlock()] if self.__showParams: configuratorView = cmp_helpers.getCmpConfiguratorMainView() stockvehicle = configuratorView.getCurrentVehicle() stockParams = params_helper.getParameters(stockvehicle) currentParams = params.VehicleParams(stockvehicle).getParamsDict() vehicleWithSkill = configuratorView.getVehicleWithAppliedSkill( self.__skillType) if vehicleWithSkill is not None: updatedParams = params.VehicleParams( vehicleWithSkill).getParamsDict() comparator = VehiclesComparator(updatedParams, currentParams) paramBlocks = self.__packParamsBlock(stockParams, comparator) if paramBlocks: items.insert( 1, formatters.packBuildUpBlockData( paramBlocks, linkage=BLOCKS_TOOLTIP_TYPES. TOOLTIP_BUILDUP_BLOCK_WHITE_BG_LINKAGE)) return items
def vehicleParams(self, cmd): if not vehicles.g_list.isVehicleExistingByCD(cmd.vehicle_id): res = {'error': 'vehicle_id is invalid.'} else: stockVehicle = self.itemsCache.items.getStockVehicle( cmd.vehicle_id) vehicle = self.itemsCache.items.getItemByCD(cmd.vehicle_id) vehicleParams = params.VehicleParams(stockVehicle) res = { 'vehicle': { 'vehicle_id': vehicle.compactDescr, 'type_user_name': vehicle.typeUserName, 'user_name': vehicle.userName, 'nation': vehicle.nationName, 'type': vehicle.type, 'level': vehicle.level, 'is_premium': vehicle.isPremium, 'health': vehicleParams.maxHealth, 'hull_armor': vehicleParams.hullArmor, 'turret_armor': vehicleParams.turretArmor, 'avg_damage': self.__getAvgDamageShells(vehicle.descriptor), 'piercing_power': self.__getPiercingPowerShells(vehicle.descriptor), 'reload_time': vehicleParams.reloadTime, 'clip_fire_rate': vehicleParams.clipFireRate } } return res
def vehiclesComparator(comparableVehicle, vehicle): return VehiclesComparator( params.VehicleParams(comparableVehicle).getParamsDict(), params.VehicleParams(vehicle).getParamsDict(), suitableArtefacts=g_paramsCache.getCompatibleArtefacts( vehicle.descriptor))
def vehiclesComparator(comparableVehicle, vehicle): return VehiclesComparator( params.VehicleParams(comparableVehicle).getParamsDict(), params.VehicleParams(vehicle).getParamsDict())
def postProgressionVehiclesComparator(comparableVehicle, vehicle): vehicleParamsObject = params.VehicleParams(comparableVehicle) return VehiclesComparator(vehicleParamsObject.getParamsDict(), params.VehicleParams(_getIdealCrewVehicle(vehicle)).getParamsDict(), suitableArtefacts=g_paramsCache.getCompatibleArtefacts(comparableVehicle), bonuses=vehicleParamsObject.getBonuses(comparableVehicle, False), penalties=vehicleParamsObject.getPenalties(comparableVehicle) if vehicle.isInInventory else None)
def tankSetupVehiclesComparator(comparableVehicle, vehicle): vehicleParamsObject = params.VehicleParams(comparableVehicle) return VehiclesComparator(vehicleParamsObject.getParamsDict(), params.VehicleParams(_getIdealCrewVehicle(vehicle)).getParamsDict(), suitableArtefacts=g_paramsCache.getCompatibleArtefacts(vehicle), bonuses=vehicleParamsObject.getBonuses(vehicle), penalties=vehicleParamsObject.getPenalties(vehicle))
def previewVehiclesComparator(comparableVehicle, vehicle): return VehiclesComparator(params.VehicleParams(comparableVehicle).getParamsDict(), params.VehicleParams(vehicle).getParamsDict(), suitableArtefacts=g_paramsCache.getCompatibleArtefacts(comparableVehicle), bonuses=params.VehicleParams(comparableVehicle).getBonuses(comparableVehicle, False))