diff --git a/Loader/ItemBuilder.cs b/Loader/ItemBuilder.cs index 1c8c66e31..e85a1b9e6 100644 --- a/Loader/ItemBuilder.cs +++ b/Loader/ItemBuilder.cs @@ -111,7 +111,7 @@ List BuildPortList(EntityClassDefinition entity) if (entity?.Components?.SItemPortContainerComponentParams == null) return ports; - foreach (var port in entity.Components.SItemPortContainerComponentParams.Ports) + foreach (var port in entity.Components?.SItemPortContainerComponentParams.Ports) { var stdPort = new StandardisedItemPort { @@ -167,7 +167,7 @@ List BuildPortFlags(SItemPortDef port) StandardisedShield BuildShieldInfo(EntityClassDefinition item) { - var shield = item.Components.SCItemShieldGeneratorParams; + var shield = item.Components?.SCItemShieldGeneratorParams; if (shield == null) return null; return new StandardisedShield @@ -190,7 +190,7 @@ StandardisedShield BuildShieldInfo(EntityClassDefinition item) StandardisedQuantumDrive BuildQuantumDriveInfo(EntityClassDefinition item) { - var qdComponent = item.Components.SCItemQuantumDriveParams; + var qdComponent = item.Components?.SCItemQuantumDriveParams; if (qdComponent == null) return null; return new StandardisedQuantumDrive @@ -218,8 +218,8 @@ StandardisedQuantumDrive BuildQuantumDriveInfo(EntityClassDefinition item) StandardisedDurability BuildDurabilityInfo(EntityClassDefinition item) { - var degradation = item.Components.SDegradationParams; - var health = item.Components.SHealthComponentParams; + var degradation = item.Components?.SDegradationParams; + var health = item.Components?.SHealthComponentParams; if (degradation == null && health == null) return null; @@ -232,8 +232,8 @@ StandardisedDurability BuildDurabilityInfo(EntityClassDefinition item) StandardisedPowerPlant BuildPowerPlantInfo(EntityClassDefinition item) { - if (item.Components.SAttachableComponentParams?.AttachDef.Type != "PowerPlant") return null; - var powerPlant = item.Components.EntityComponentPowerConnection; + if (item.Components?.SAttachableComponentParams?.AttachDef.Type != "PowerPlant") return null; + var powerPlant = item.Components?.EntityComponentPowerConnection; if (powerPlant == null) return null; return new StandardisedPowerPlant @@ -244,7 +244,7 @@ StandardisedPowerPlant BuildPowerPlantInfo(EntityClassDefinition item) StandardisedCooler BuildCoolerInfo(EntityClassDefinition item) { - var cooler = item.Components.SCItemCoolerParams; + var cooler = item.Components?.SCItemCoolerParams; if (cooler == null) return null; return new StandardisedCooler @@ -255,7 +255,7 @@ StandardisedCooler BuildCoolerInfo(EntityClassDefinition item) StandardisedThruster BuildThrusterInfo(EntityClassDefinition item) { - var thruster = item.Components.SCItemThrusterParams; + var thruster = item.Components?.SCItemThrusterParams; if (thruster == null) return null; return new StandardisedThruster @@ -269,7 +269,7 @@ StandardisedThruster BuildThrusterInfo(EntityClassDefinition item) StandardisedCargoGrid BuildCargoGridInfo(EntityClassDefinition item) { - var cargo = item.Components.SCItemCargoGridParams; + var cargo = item.Components?.SCItemCargoGridParams; if (cargo == null) return null; return new StandardisedCargoGrid @@ -284,10 +284,10 @@ StandardisedCargoGrid BuildCargoGridInfo(EntityClassDefinition item) StandardisedFuelTank BuildQuantumFuelTankInfo(EntityClassDefinition item) { - var tank = item.Components.SCItemFuelTankParams; + var tank = item.Components?.SCItemFuelTankParams; if (tank == null) return null; - if (item.Components.SAttachableComponentParams.AttachDef.Type != "QuantumFuelTank") return null; + if (item.Components?.SAttachableComponentParams.AttachDef.Type != "QuantumFuelTank") return null; return new StandardisedFuelTank { @@ -297,10 +297,10 @@ StandardisedFuelTank BuildQuantumFuelTankInfo(EntityClassDefinition item) StandardisedFuelTank BuildHydrogenFuelTankInfo(EntityClassDefinition item) { - var tank = item.Components.SCItemFuelTankParams; + var tank = item.Components?.SCItemFuelTankParams; if (tank == null) return null; - if (item.Components.SAttachableComponentParams.AttachDef.Type != "FuelTank") return null; + if (item.Components?.SAttachableComponentParams.AttachDef.Type != "FuelTank") return null; return new StandardisedFuelTank { @@ -310,7 +310,7 @@ StandardisedFuelTank BuildHydrogenFuelTankInfo(EntityClassDefinition item) StandardisedFuelIntake BuildHydrogenFuelIntakeInfo(EntityClassDefinition item) { - var intake = item.Components.SCItemFuelIntakeParams; + var intake = item.Components?.SCItemFuelIntakeParams; if (intake == null) return null; return new StandardisedFuelIntake @@ -321,7 +321,7 @@ StandardisedFuelIntake BuildHydrogenFuelIntakeInfo(EntityClassDefinition item) StandardisedArmour BuildArmourInfo(EntityClassDefinition item) { - var armour = item.Components.SCItemVehicleArmorParams; + var armour = item.Components?.SCItemVehicleArmorParams; if (armour == null) return null; return new StandardisedArmour @@ -347,7 +347,7 @@ StandardisedArmour BuildArmourInfo(EntityClassDefinition item) StandardisedEmp BuildEmpInfo(EntityClassDefinition item) { - var emp = item.Components.SCItemEMPParams; + var emp = item.Components?.SCItemEMPParams; if (emp == null) return null; return new StandardisedEmp @@ -361,10 +361,10 @@ StandardisedEmp BuildEmpInfo(EntityClassDefinition item) StandardisedMissileRack BuildMissileRackInfo(EntityClassDefinition item) { - if (item.Components.SAttachableComponentParams?.AttachDef.Type != "MissileLauncher") return null; - if (item.Components.SAttachableComponentParams?.AttachDef.SubType != "MissileRack") return null; + if (item.Components?.SAttachableComponentParams?.AttachDef.Type != "MissileLauncher") return null; + if (item.Components?.SAttachableComponentParams?.AttachDef.SubType != "MissileRack") return null; - var rootPort = item.Components.SItemPortContainerComponentParams; + var rootPort = item.Components?.SItemPortContainerComponentParams; if (rootPort == null) return null; var rackPorts = rootPort.Ports; @@ -379,7 +379,7 @@ StandardisedMissileRack BuildMissileRackInfo(EntityClassDefinition item) StandardisedQig BuildQigInfo(EntityClassDefinition item) { - var qig = item.Components.SCItemQuantumInterdictionGeneratorParams; + var qig = item.Components?.SCItemQuantumInterdictionGeneratorParams; if (qig == null) return null; return new StandardisedQig @@ -391,7 +391,7 @@ StandardisedQig BuildQigInfo(EntityClassDefinition item) StandardisedIfcs BuildIfcsInfo(EntityClassDefinition item) { - var ifcs = item.Components.IFCSParams; + var ifcs = item.Components?.IFCSParams; if (ifcs == null) return null; return new StandardisedIfcs @@ -417,7 +417,7 @@ StandardisedIfcs BuildIfcsInfo(EntityClassDefinition item) StandardisedCoolerConnection BuildHeatConnectionInfo(EntityClassDefinition item) { - var heat = item.Components.EntityComponentHeatConnection; + var heat = item.Components?.EntityComponentHeatConnection; if (heat == null) return null; return new StandardisedCoolerConnection @@ -430,7 +430,7 @@ StandardisedCoolerConnection BuildHeatConnectionInfo(EntityClassDefinition item) StandardisedPowerConnection BuildPowerConnectionInfo(EntityClassDefinition item) { - var power = item.Components.EntityComponentPowerConnection; + var power = item.Components?.EntityComponentPowerConnection; if (power == null) return null; return new StandardisedPowerConnection @@ -442,7 +442,7 @@ StandardisedPowerConnection BuildPowerConnectionInfo(EntityClassDefinition item) StandardisedWeapon BuildWeaponInfo(EntityClassDefinition item) { - var weapon = item.Components.SCItemWeaponComponentParams; + var weapon = item.Components?.SCItemWeaponComponentParams; if (weapon == null) return null; var info = new StandardisedWeapon @@ -553,7 +553,7 @@ StandardisedAmmunition BuildAmmunitionInfo(EntityClassDefinition item) Size = ammo.size, ImpactDamage = ConvertDamage(impactDamage), DetonationDamage = ConvertDamage(detonationDamage), - Capacity = item.Components.SAmmoContainerComponentParams?.maxAmmoCount ?? item.Components.SAmmoContainerComponentParams?.maxRestockCount, + Capacity = item.Components?.SAmmoContainerComponentParams?.maxAmmoCount ?? item.Components?.SAmmoContainerComponentParams?.maxRestockCount, BulletImpulseFalloff = new StandardisedBulletImpulseFalloff{ MinDistance = projectiles?.impulseFalloffParams?.BulletImpulseFalloffParams?.minDistance, DropFalloff = projectiles?.impulseFalloffParams?.BulletImpulseFalloffParams?.dropFalloff, @@ -623,22 +623,22 @@ StandardisedDamage ConvertDamage(DamageInfo damage) AmmoParams GetAmmoParams(EntityClassDefinition item) { // If this a weapon that contains its own ammo, or if it is a magazine, then it will have an SCAmmoContainerComponentParams component. - var ammoRef = item.Components.SAmmoContainerComponentParams?.ammoParamsRecord; + var ammoRef = item.Components?.SAmmoContainerComponentParams?.ammoParamsRecord; if (ammoRef != null) return ammoSvc.GetByReference(ammoRef); // Otherwise if this is a weapon then SCItemWeaponComponentParams.ammoContainerRecord should be the reference of a magazine entity - var magRef = item.Components.SCItemWeaponComponentParams?.ammoContainerRecord; + var magRef = item.Components?.SCItemWeaponComponentParams?.ammoContainerRecord; if (magRef == null) return null; var mag = entitySvc.GetByReference(magRef); if (mag == null) return null; // And the magazine's SAmmoContainerComponentParams will tell us about the ammo - return ammoSvc.GetByReference(mag.Components.SAmmoContainerComponentParams.ammoParamsRecord); + return ammoSvc.GetByReference(mag.Components?.SAmmoContainerComponentParams.ammoParamsRecord); } StandardisedMissile BuildMissileInfo(EntityClassDefinition item) { - var missile = item.Components.SCItemMissileParams; + var missile = item.Components?.SCItemMissileParams; if (missile == null) return null; var info = new StandardisedMissile @@ -651,7 +651,7 @@ StandardisedMissile BuildMissileInfo(EntityClassDefinition item) StandardisedMissile BuildBombInfo(EntityClassDefinition item) { - var missile = item.Components.SCItemBombParams; + var missile = item.Components?.SCItemBombParams; if (missile == null) return null; var info = new StandardisedMissile @@ -664,7 +664,7 @@ StandardisedMissile BuildBombInfo(EntityClassDefinition item) StandardisedScanner BuildScannerInfo(EntityClassDefinition item) { - var scanner = item.Components.SSCItemScannerComponentParams; + var scanner = item.Components?.SSCItemScannerComponentParams; if (scanner == null) return null; var info = new StandardisedScanner @@ -677,7 +677,7 @@ StandardisedScanner BuildScannerInfo(EntityClassDefinition item) StandardisedRadar BuildRadarInfo(EntityClassDefinition item) { - var radar = item.Components.SCItemRadarComponentParams; + var radar = item.Components?.SCItemRadarComponentParams; if (radar == null) return null; var info = new StandardisedRadar @@ -694,11 +694,11 @@ StandardisedRadar BuildRadarInfo(EntityClassDefinition item) List BuildDetectionSignatures(EntityClassDefinition item) { var detections = new List(); - var signatureDetection = item.Components.SCItemRadarComponentParams.signatureDetection; + var signatureDetection = item.Components?.SCItemRadarComponentParams?.signatureDetection; if (signatureDetection == null) return null; - foreach (var detection in item.Components.SCItemRadarComponentParams.signatureDetection) + foreach (var detection in item.Components?.SCItemRadarComponentParams.signatureDetection) { detections.Add(new StandardisedSignatureDetection { @@ -713,7 +713,7 @@ List BuildDetectionSignatures(EntityClassDefinit StandardisedPing BuildPingInfo(EntityClassDefinition item) { - var ping = item.Components.SSCItemPingComponentParams; + var ping = item.Components?.SSCItemPingComponentParams; if (ping == null) return null; var info = new StandardisedPing @@ -727,7 +727,7 @@ StandardisedPing BuildPingInfo(EntityClassDefinition item) StandardisedWeaponRegenPool BuildWeaponRegenInfo(EntityClassDefinition item) { - var regen = item.Components.SCItemWeaponRegenPoolComponentParams; + var regen = item.Components?.SCItemWeaponRegenPoolComponentParams; if (regen == null) return null; var info = new StandardisedWeaponRegenPool @@ -742,7 +742,7 @@ StandardisedWeaponRegenPool BuildWeaponRegenInfo(EntityClassDefinition item) StandardisedInventoryContainer BuildPersonalInventoryInfo(EntityClassDefinition item) { - var inventoryRef = item.Components.SCItemInventoryContainerComponentParams?.containerParams; + var inventoryRef = item.Components?.SCItemInventoryContainerComponentParams?.containerParams; if (inventoryRef != null) return _inventoryContainerSvc.GetInventoryContainer(inventoryRef); return null; diff --git a/Loader/LoadoutLoader.cs b/Loader/LoadoutLoader.cs index 35638869e..af0f8b678 100644 --- a/Loader/LoadoutLoader.cs +++ b/Loader/LoadoutLoader.cs @@ -19,7 +19,7 @@ public List Load(EntityClassDefinition entity) { var loadout = new List(); - var loadoutParams = entity.Components.SEntityComponentDefaultLoadoutParams?.loadout; + var loadoutParams = entity.Components?.SEntityComponentDefaultLoadoutParams?.loadout; if (loadoutParams?.SItemPortLoadoutManualParams != null) loadout.AddRange(LoadManualLoadout(loadoutParams.SItemPortLoadoutManualParams)); if (loadoutParams?.SItemPortLoadoutXMLParams != null) loadout.AddRange(LoadXmlLoadout(loadoutParams.SItemPortLoadoutXMLParams)); diff --git a/Loader/ShipLoader.cs b/Loader/ShipLoader.cs index 41961a992..919020111 100644 --- a/Loader/ShipLoader.cs +++ b/Loader/ShipLoader.cs @@ -186,15 +186,15 @@ ShipIndexEntry CreateIndexEntry(EntityClassDefinition entity, Vehicle vehicle, S bool isGroundVehicle = entity.Components?.VehicleComponentParams.vehicleCareer == "@vehicle_focus_ground"; bool isGravlevVehicle = entity.Components?.VehicleComponentParams.isGravlevVehicle ?? false; bool isSpaceship = !(isGroundVehicle || isGravlevVehicle); - var manufacturer = manufacturerSvc.GetManufacturer(entity.Components.VehicleComponentParams.manufacturer, entity.ClassName); + var manufacturer = manufacturerSvc.GetManufacturer(entity.Components?.VehicleComponentParams.manufacturer, entity.ClassName); var indexEntry = new ShipIndexEntry { className = entity.ClassName, - name = entity.Components.VehicleComponentParams.vehicleName, - career = entity.Components.VehicleComponentParams.vehicleCareer, - role = entity.Components.VehicleComponentParams.vehicleRole, - dogFightEnabled = Convert.ToBoolean(entity.Components.VehicleComponentParams.dogfightEnabled), + name = entity.Components?.VehicleComponentParams.vehicleName, + career = entity.Components?.VehicleComponentParams.vehicleCareer, + role = entity.Components?.VehicleComponentParams.vehicleRole, + dogFightEnabled = Convert.ToBoolean(entity.Components?.VehicleComponentParams.dogfightEnabled), size = shipSummary?.Size, isGroundVehicle = isGroundVehicle, isGravlevVehicle = isGravlevVehicle, @@ -512,25 +512,25 @@ StandardisedPortSummary BuildPortSummary(List parts) StandardisedShip BuildShipSummary(EntityClassDefinition entity, List parts, StandardisedPortSummary portSummary, Vehicle vehicle) { StandardisedInventoryContainer inventorySize = null; - if (entity.Components.VehicleComponentParams.inventoryContainerParams.Length > 0) + if (entity.Components?.VehicleComponentParams.inventoryContainerParams.Length > 0) { - inventorySize = inventoryContainerSvc.GetInventoryContainer(entity.Components.VehicleComponentParams + inventorySize = inventoryContainerSvc.GetInventoryContainer(entity.Components?.VehicleComponentParams .inventoryContainerParams); } var shipSummary = new StandardisedShip { ClassName = entity.ClassName, - Name = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleName, entity.ClassName), - Description = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleDescription), - Career = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleCareer), - Role = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleRole), - Manufacturer = manufacturerSvc.GetManufacturer(entity.Components.VehicleComponentParams.manufacturer, entity.ClassName), - Size = entity.Components.SAttachableComponentParams.AttachDef.Size, - Width = entity.Components.VehicleComponentParams.maxBoundingBoxSize.x, - Length = entity.Components.VehicleComponentParams.maxBoundingBoxSize.y, - Height = entity.Components.VehicleComponentParams.maxBoundingBoxSize.z, - Crew = entity.Components.VehicleComponentParams.crewSize, + Name = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleName, entity.ClassName), + Description = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleDescription), + Career = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleCareer), + Role = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleRole), + Manufacturer = manufacturerSvc.GetManufacturer(entity.Components?.VehicleComponentParams.manufacturer, entity.ClassName), + Size = entity.Components?.SAttachableComponentParams?.AttachDef?.Size ?? 0, + Width = entity.Components?.VehicleComponentParams?.maxBoundingBoxSize?.x ?? 0, + Length = entity.Components?.VehicleComponentParams?.maxBoundingBoxSize?.y ?? 0, + Height = entity.Components?.VehicleComponentParams?.maxBoundingBoxSize?.z ?? 0, + Crew = entity.Components?.VehicleComponentParams?.crewSize ?? 0, WeaponCrew = portSummary.MannedTurrets.Count + portSummary.RemoteTurrets.Count, OperationsCrew = Math.Max(portSummary.MiningTurrets.Count, portSummary.UtilityTurrets.Count), Mass = FindParts(parts, x => true).Sum((x) => x.Item1.Mass ?? 0),