diff --git a/Loader/EntityService.cs b/Loader/EntityService.cs index 724624b01..0ff52618b 100644 --- a/Loader/EntityService.cs +++ b/Loader/EntityService.cs @@ -13,9 +13,9 @@ public class EntityService { public string OutputFolder { get; set; } public string DataRoot { get; set; } + public Dictionary referenceToClassNameMap; Dictionary classNameToFilenameMap; - Dictionary referenceToClassNameMap; Dictionary classNameToTypeMap; Dictionary classNameToEntityMap; ClassParser entityParser = new ClassParser(); @@ -122,12 +122,13 @@ public EntityClassDefinition GetByFilename(string filename) var entity = LoadEntity(filename); if (entity == null) return null; - if (!classNameToFilenameMap.ContainsKey(entity.ClassName)) { - classNameToFilenameMap.Add(entity.ClassName, filename); - referenceToClassNameMap.Add(entity.__ref, entity.ClassName); - classNameToEntityMap.Add(entity.ClassName, entity); - classNameToTypeMap.Add(entity.ClassName, entity.Components.SAttachableComponentParams?.AttachDef.Type ?? ""); - } + if (!classNameToFilenameMap.ContainsKey(entity.ClassName)) + { + classNameToFilenameMap.Add(entity.ClassName, filename); + referenceToClassNameMap.Add(entity.__ref, entity.ClassName); + classNameToEntityMap.Add(entity.ClassName, entity); + classNameToTypeMap.Add(entity.ClassName, entity.Components?.SAttachableComponentParams?.AttachDef.Type ?? ""); + } return entity; } diff --git a/Loader/ItemBuilder.cs b/Loader/ItemBuilder.cs index d48780feb..3eb218a6c 100644 --- a/Loader/ItemBuilder.cs +++ b/Loader/ItemBuilder.cs @@ -92,7 +92,7 @@ List BuildTagList(EntityClassDefinition entity) { var tags = new List(); - var tagString = entity.Components.SAttachableComponentParams?.AttachDef.Tags; + var tagString = entity.Components?.SAttachableComponentParams?.AttachDef.Tags; if (tagString != null) { foreach (var tag in tagString.Split(" ")) @@ -109,7 +109,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 { @@ -165,7 +165,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 @@ -188,7 +188,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 @@ -216,8 +216,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; @@ -230,8 +230,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 @@ -242,7 +242,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 @@ -253,7 +253,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 @@ -267,7 +267,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 @@ -282,10 +282,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 { @@ -295,10 +295,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 { @@ -308,7 +308,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 @@ -319,7 +319,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 @@ -345,7 +345,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 @@ -359,10 +359,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; @@ -377,7 +377,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 @@ -389,7 +389,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 @@ -415,7 +415,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 @@ -428,7 +428,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 @@ -440,7 +440,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 @@ -551,7 +551,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, @@ -621,11 +621,11 @@ 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; @@ -636,7 +636,7 @@ AmmoParams GetAmmoParams(EntityClassDefinition item) StandardisedMissile BuildMissileInfo(EntityClassDefinition item) { - var missile = item.Components.SCItemMissileParams; + var missile = item.Components?.SCItemMissileParams; if (missile == null) return null; var info = new StandardisedMissile @@ -649,7 +649,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 @@ -662,7 +662,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 @@ -675,7 +675,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 @@ -692,11 +692,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 { @@ -711,7 +711,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 @@ -725,7 +725,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 @@ -740,7 +740,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/ItemInstaller.cs b/Loader/ItemInstaller.cs index 91922c977..265e7398b 100644 --- a/Loader/ItemInstaller.cs +++ b/Loader/ItemInstaller.cs @@ -56,12 +56,19 @@ public void InstallLoadout(StandardisedPart part, List public void InstallLoadout(SItemPortDef port, List loadout) { var loadoutEntry = FindLoadoutEntry(port.Name, loadout); - if (String.IsNullOrEmpty(loadoutEntry?.ClassName)) return; - var item = entitySvc.GetByClassName(loadoutEntry.ClassName); - if (item == null) return; + if (!String.IsNullOrEmpty(loadoutEntry?.ClassName)) + { + var item = entitySvc.GetByClassName(loadoutEntry.ClassName); + + if (item == null) return; - port.EquippedItemUuid = item.__ref; + port.EquippedItemUuid = item.__ref; + } + else if (!String.IsNullOrEmpty(loadoutEntry?.ClassReference)) + { + port.EquippedItemUuid = loadoutEntry?.ClassReference; + } } public void InstallLoadout(List ports, List loadout) @@ -75,22 +82,43 @@ public void InstallLoadout(List ports, List loadout) { var loadoutEntry = FindLoadoutEntry(port.PortName, loadout); - if (String.IsNullOrEmpty(loadoutEntry?.ClassName)) return; + if (!String.IsNullOrEmpty(loadoutEntry?.ClassName)) + { + port.Loadout = loadoutEntry.ClassName; + var item = entitySvc.GetByClassName(loadoutEntry.ClassName); - port.Loadout = loadoutEntry.ClassName; + if (item == null) return; - var item = entitySvc.GetByClassName(loadoutEntry.ClassName); - if (item == null) return; + var standardisedItem = itemBuilder.BuildItem(item); - var standardisedItem = itemBuilder.BuildItem(item); + port.InstalledItem = standardisedItem; - port.InstalledItem = standardisedItem; + // Update the loadout with anything this item brings with it + var newLoadout = loadoutLoader.Load(item); + loadoutEntry.Entries.AddRange(newLoadout); - // Update the loadout with anything this item brings with it - var newLoadout = loadoutLoader.Load(item); - loadoutEntry.Entries.AddRange(newLoadout); + InstallLoadout(standardisedItem.Ports, loadoutEntry.Entries); + } + else if (!String.IsNullOrEmpty(loadoutEntry?.ClassReference)) + { + var item = entitySvc.GetByReference(loadoutEntry.ClassReference); - InstallLoadout(standardisedItem.Ports, loadoutEntry.Entries); + if (item == null) return; + + if (!entitySvc.referenceToClassNameMap.ContainsKey(loadoutEntry.ClassReference)) return; + + port.Loadout = entitySvc.referenceToClassNameMap[loadoutEntry.ClassReference]; + + var standardisedItem = itemBuilder.BuildItem(item); + + port.InstalledItem = standardisedItem; + + // Update the loadout with anything this item brings with it + var newLoadout = loadoutLoader.Load(item); + loadoutEntry.Entries.AddRange(newLoadout); + + InstallLoadout(standardisedItem.Ports, loadoutEntry.Entries); + } } StandardisedLoadoutEntry FindLoadoutEntry(string portName, List loadout) diff --git a/Loader/ItemLoader.cs b/Loader/ItemLoader.cs index 9b2fc0a34..237e365d4 100644 --- a/Loader/ItemLoader.cs +++ b/Loader/ItemLoader.cs @@ -81,7 +81,7 @@ public List Load(string typeFilter = null) EntityClassDefinition magazine = null; if (!String.IsNullOrEmpty(entity.Components?.SCItemWeaponComponentParams?.ammoContainerRecord)) { - magazine = entitySvc.GetByReference(entity.Components.SCItemWeaponComponentParams.ammoContainerRecord); + magazine = entitySvc.GetByReference(entity.Components?.SCItemWeaponComponentParams.ammoContainerRecord); } // If it is an ammo container or if it has a magazine then load the ammo properties @@ -102,14 +102,14 @@ public List Load(string typeFilter = null) DamageResistance damageResistances = null; if (!String.IsNullOrEmpty(entity.Components?.SCItemSuitArmorParams?.damageResistance)) { - var damageMacro = damageResistanceMacros.Find(y => y.__ref == entity.Components.SCItemSuitArmorParams.damageResistance); + var damageMacro = damageResistanceMacros.Find(y => y.__ref == entity.Components?.SCItemSuitArmorParams.damageResistance); damageResistances = damageMacro?.damageResistance; } StandardisedInventoryContainer inventoryContainer = null; if (!String.IsNullOrEmpty(entity.Components?.SCItemInventoryContainerComponentParams?.containerParams)) { - inventoryContainer = _inventoryContainerSvc.GetInventoryContainer(entity.Components.SCItemInventoryContainerComponentParams.containerParams); + inventoryContainer = _inventoryContainerSvc.GetInventoryContainer(entity.Components?.SCItemInventoryContainerComponentParams.containerParams); } var stdItem = itemBuilder.BuildItem(entity); diff --git a/Loader/Json/StandardisedLoadoutEntry.cs b/Loader/Json/StandardisedLoadoutEntry.cs index d6e421e28..da941764e 100644 --- a/Loader/Json/StandardisedLoadoutEntry.cs +++ b/Loader/Json/StandardisedLoadoutEntry.cs @@ -6,6 +6,7 @@ public class StandardisedLoadoutEntry { public string PortName { get; set; } public string ClassName { get; set; } + public string ClassReference { get; set; } public List Entries { get; set; } public override string ToString() 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/ManualLoadoutLoader.cs b/Loader/ManualLoadoutLoader.cs index b7334b432..ef30930af 100644 --- a/Loader/ManualLoadoutLoader.cs +++ b/Loader/ManualLoadoutLoader.cs @@ -25,6 +25,7 @@ StandardisedLoadoutEntry BuildLoadout(SItemPortLoadoutEntryParams cigLoadoutEntr { PortName = cigLoadoutEntry.itemPortName, ClassName = cigLoadoutEntry.entityClassName, + ClassReference = cigLoadoutEntry.entityClassReference, Entries = new List() }; diff --git a/Loader/ShipLoader.cs b/Loader/ShipLoader.cs index 41961a992..7e7e7e402 100644 --- a/Loader/ShipLoader.cs +++ b/Loader/ShipLoader.cs @@ -156,7 +156,7 @@ public ShipLoader(ItemBuilder itemBuilder, ManufacturerService manufacturerSvc, (Vehicle, EntityClassDefinition, List, StandardisedShip, StandardisedPortSummary)? LoadShip(string entityFilename) { - Console.WriteLine(entityFilename); + Console.WriteLine(entityFilename); var entity = LoadEntity(entityFilename); var vehicle = LoadVehicle(entity); @@ -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, @@ -216,8 +216,9 @@ EntityClassDefinition LoadEntity(string entityFilename) Vehicle LoadVehicle(EntityClassDefinition entity) { var vehicleFilename = entity.Components?.VehicleComponentParams?.vehicleDefinition; - if (vehicleFilename == null) { - return null; + if (vehicleFilename == null) + { + return null; } vehicleFilename = Path.Combine(DataRoot, "Data", Path.Join(vehicleFilename.Split('/'))); @@ -512,25 +513,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), @@ -539,7 +540,7 @@ StandardisedShip BuildShipSummary(EntityClassDefinition entity, List !x.InstalledItem.CargoGrid.MiningOnly) .Sum(x => x.InstalledItem.CargoGrid.Capacity)), Inventory = inventorySize, - // Insurance = insuranceSvc.GetInsurance(entity.ClassName) + // Insurance = insuranceSvc.GetInsurance(entity.ClassName) }; if (shipSummary.ClassName.Contains("Carrack")) diff --git a/Loader/ShopLoader.cs b/Loader/ShopLoader.cs index fe53b58c9..6988f0328 100644 --- a/Loader/ShopLoader.cs +++ b/Loader/ShopLoader.cs @@ -152,15 +152,15 @@ List GetInventory(Node prices, ShopLayoutNode shopNode) if (entity?.Components.SAttachableComponentParams != null) { - item.displayName = localisationService.GetText(entity.Components.SAttachableComponentParams.AttachDef.Localization.Name); - item.tags = entity.Components.SAttachableComponentParams.AttachDef.Tags.Split(" "); - item.type = entity.Components.SAttachableComponentParams.AttachDef.Type; - item.subType = entity.Components.SAttachableComponentParams.AttachDef.SubType; + item.displayName = localisationService.GetText(entity.Components?.SAttachableComponentParams.AttachDef.Localization.Name); + item.tags = entity.Components?.SAttachableComponentParams.AttachDef.Tags.Split(" "); + item.type = entity.Components?.SAttachableComponentParams.AttachDef.Type; + item.subType = entity.Components?.SAttachableComponentParams.AttachDef.SubType; } if (entity?.Components.CommodityComponentParams != null) { - item.displayName = localisationService.GetText(entity.Components.CommodityComponentParams.name); + item.displayName = localisationService.GetText(entity.Components?.CommodityComponentParams.name); } items.Add(item); diff --git a/Loader/scdb.Xml/Entities/SItemPortLoadoutEntryParams.cs b/Loader/scdb.Xml/Entities/SItemPortLoadoutEntryParams.cs index 7b3ab397a..c4acc98f9 100644 --- a/Loader/scdb.Xml/Entities/SItemPortLoadoutEntryParams.cs +++ b/Loader/scdb.Xml/Entities/SItemPortLoadoutEntryParams.cs @@ -11,6 +11,9 @@ public class SItemPortLoadoutEntryParams [XmlAttribute] public string entityClassName; + [XmlAttribute] + public string entityClassReference; + public loadout loadout; } -} \ No newline at end of file +}