From a786da0e24e607193367e3924bbb6cace9a31c84 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 14 Jun 2026 07:27:23 +0100 Subject: [PATCH] Instantiate loadout items from typed rows --- .voidbot/state/aetheria.cc | Bin 71527 -> 72760 bytes Assets/Scripts/ServerShared/ItemManager.cs | 40 +++++++++- .../Scripts/ServerShared/LoadoutGenerator.cs | 71 +++++++----------- .../RuntimeItemProjectionEntry.cs | 5 ++ docs/aetheria-perfect-machine-map.md | 11 ++- 5 files changed, 78 insertions(+), 49 deletions(-) diff --git a/.voidbot/state/aetheria.cc b/.voidbot/state/aetheria.cc index 9e4caadc961c5834ed5448e7791f4e11777c7c88..4ccbc89cbc4050e58ae070bcb1cbd99353e4562f 100644 GIT binary patch delta 998 zcmZ`&Jxmlq6wbn_{5C3JNRXG%fVn%*lLMpzg%JFSKrke9v%8Pok-42?W)?gx5KA>t znV5@-B?1~_OejQyF&37ZSYoVfY^BmfO`P4kqqBSS=FPnC=e_SQ65HE}m+LhR*}lQ- znRGUroqb@n=npk__A~u)hSy%NtJIv0|@vM zl*<(*3MJq|NDFxk6u4BNqgYXQemlPW#9@TycYltRpP~zX$e2umLxjh{CPfpw+?l6= zS2;O6P=YgtA}%WshbkV$0z+v&@Q{ckkiZ3lHU>k3Mbp@Di(#1}7+09TL;}*`p-7(- zXdsS801L!sI9{RIt@kEc4@9LsdSRsXuta8nn+}36NyAQY{rS_8HYf;w)m#|bGQFWN zkS5x_rEh*|nLjy(YJ@0apissDuTiNa%y9vnxhTL!pDa>yjNr}@#%$uugDt4*pDd3|xaGX2$1$8hkJ^eOa%Jwk+S9@iBl%AsU2{WX8u>1~lr}A!Tk7 zR74jl&X%9YegctD_L(mQhGhiF<#A(yhOOXk=pam#*-nL~M;;?}Qc@KeMi@H4FS?Zp zh$aZr&&<5|TukAdT-C$pyY%`@cXF&cF#C!|BqR`lu|rO5h!I5ay#A4G*Ix(fw7oOb zdEtLnLHtC&-8t4}7t1Vwp+}q|j9nQYNk7L$>Y^Fl2*~}_;iHFor!)P7nOy00gVmXe zqQOiioylZo*A(&O!_DdnY*d7L>V!-=#PP9I-)Ie0*C|_?Y_!^|>((1DVCiMuC-Z{ zW!DeJNt3IciZ_Svo-4$7kP{|mVH5=b@>(+g diff --git a/Assets/Scripts/ServerShared/ItemManager.cs b/Assets/Scripts/ServerShared/ItemManager.cs index 187acbc18..761dde632 100644 --- a/Assets/Scripts/ServerShared/ItemManager.cs +++ b/Assets/Scripts/ServerShared/ItemManager.cs @@ -99,6 +99,11 @@ public class ItemManager return new RuntimeItemReference(item); } + public RuntimeItemReference CreateReference(Guid itemId) + { + return new RuntimeItemReference(itemId); + } + public ItemData GetData(ItemInstance item) { Hydrate(item); @@ -274,6 +279,27 @@ public class ItemManager return newCommodity; } + public EquippableItem CreateEquippableInstance(AetheriaRuntimeCatalogItem item, float quality) + { + var itemId = GetLegacyGuid(item); + if (itemId == Guid.Empty) + { + throw new NullReferenceException("Attempted to create equippable item instance using missing typed item data!"); + } + + return new EquippableItem + { + Data = CreateReference(itemId), + Quality = quality, + Durability = item.Durability > 0 ? (float)item.Durability : 1f + }; + } + + public EquippableItem CreateEquippableInstance(AetheriaRuntimeCatalogItem item) + { + return CreateEquippableInstance(item, SelectCraftedQuality()); + } + private float GetInitialDurability(EquippableItemData item) { var typedItem = GetRuntimeItem(item.ID); @@ -288,6 +314,11 @@ public class ItemManager return null; } + return CreateInstance(item, SelectCraftedQuality()); + } + + private float SelectCraftedQuality() + { var quality = Random.NextFloat(); var tier = GameplaySettings.Tiers[0]; foreach (var t in GameplaySettings.Tiers) @@ -296,7 +327,14 @@ public class ItemManager tier = t; } - return CreateInstance(item, tier.Quality); + return tier.Quality; + } + + private static Guid GetLegacyGuid(AetheriaRuntimeCatalogItem item) + { + return item != null && Guid.TryParse(item.LegacyId, out var itemId) + ? itemId + : Guid.Empty; } public (RarityTier tier, int upgrades) GetTier(CraftedItemInstance item) diff --git a/Assets/Scripts/ServerShared/LoadoutGenerator.cs b/Assets/Scripts/ServerShared/LoadoutGenerator.cs index 4dbdc018a..ff48572e0 100644 --- a/Assets/Scripts/ServerShared/LoadoutGenerator.cs +++ b/Assets/Scripts/ServerShared/LoadoutGenerator.cs @@ -49,13 +49,13 @@ public class LoadoutGenerator public RuntimeEntityBlueprint GenerateShipLoadout(Predicate hullFilter = null) { - var hullData = RandomHull(HullType.Ship, hullFilter); - if(hullData==null) + var hullRow = RandomHull(HullType.Ship, hullFilter); + if(hullRow==null) { ItemManager.Log("Unable to generate ship loadout: no compatible hull found!"); return null; } - var hull = ItemManager.CreateInstance(hullData) as EquippableItem; + var hull = ItemManager.CreateEquippableInstance(hullRow); if(hull==null) ItemManager.Log("WHAT???"); var entity = new Ship(ItemManager, null, hull, ItemManager.GameplaySettings.DefaultEntitySettings); @@ -66,13 +66,13 @@ public class LoadoutGenerator public RuntimeOrbitalEntityBlueprint GenerateTurretLoadout() { - var hullData = RandomHull(HullType.Turret); - if(hullData==null) + var hullRow = RandomHull(HullType.Turret); + if(hullRow==null) { ItemManager.Log("Unable to generate turret loadout: no compatible hull found!"); return null; } - var hull = ItemManager.CreateInstance(hullData) as EquippableItem; + var hull = ItemManager.CreateEquippableInstance(hullRow); var entity = new OrbitalEntity(ItemManager, null, hull, Guid.Empty, ItemManager.GameplaySettings.DefaultEntitySettings); entity.Faction = Faction; OutfitEntity(entity); @@ -81,24 +81,23 @@ public class LoadoutGenerator public RuntimeOrbitalEntityBlueprint GenerateStationLoadout() { - var hullData = RandomHull(HullType.Station); - if(hullData==null) + var hullRow = RandomHull(HullType.Station); + if(hullRow==null) { ItemManager.Log("Unable to generate station loadout: no compatible hull found!"); return null; } - var hull = ItemManager.CreateInstance(hullData) as EquippableItem; + var hull = ItemManager.CreateEquippableInstance(hullRow); var entity = new OrbitalEntity(ItemManager, null, hull, Guid.Empty, ItemManager.GameplaySettings.DefaultEntitySettings); entity.Faction = Faction; var emptyShape = entity.UnoccupiedSpace; var dockingBayRow = RandomCatalogItem(2, item => FitsWithin(item, emptyShape)); - var dockingBayData = ProjectRuntimeItem(dockingBayRow); - if (dockingBayData == null) throw new InvalidLoadoutException("No compatible docking bay found for station!"); + if (dockingBayRow == null) throw new InvalidLoadoutException("No compatible docking bay found for station!"); ToShape(dockingBayRow).FitsWithin(emptyShape, out var cargoRotation, out var cargoPosition); - var dockingBay = ItemManager.CreateInstance(dockingBayData) as EquippableItem; + var dockingBay = ItemManager.CreateEquippableInstance(dockingBayRow); dockingBay.Rotation = cargoRotation; if (!entity.TryEquip(dockingBay, cargoPosition)) { @@ -108,31 +107,29 @@ public class LoadoutGenerator OutfitEntity(entity); var cargo = entity.CargoBays.First(); - IEnumerable inventory = RandomCatalogItems(16, 1, + IEnumerable inventory = RandomCatalogItems(16, 1, item => item.Category != "CargoBayData" && item.Category != "DockingBayData" && (item.Category != "HullData" || item.HullType == nameof(HullType.Ship))); inventory = inventory - .Select(ProjectRuntimeItem) .Where(item => item != null); inventory = inventory - .OrderByDescending(item=>item.Shape.Coordinates.Length); + .OrderByDescending(item=>item.OccupiedCells); foreach (var item in inventory) { - var instance = ItemManager.CreateInstance(item); + var instance = ItemManager.CreateEquippableInstance(item); cargo.TryStore(instance); } - entity.CanTow = hullData.CanTow; + entity.CanTow = hullRow.HullCanTow; return RuntimeEntityBlueprintProjector.CaptureBlueprint(entity) as RuntimeOrbitalEntityBlueprint; } - public HullData RandomHull(HullType type, Predicate hullFilter = null) + public AetheriaRuntimeCatalogItem RandomHull(HullType type, Predicate hullFilter = null) { - var hullRow = RandomCatalogItem(0, item => + return RandomCatalogItem(0, item => string.Equals(item.HullType, type.ToString(), StringComparison.Ordinal) && (hullFilter?.Invoke(item) ?? true)); - return ProjectRuntimeItem(hullRow); } public AetheriaRuntimeCatalogItem[] RandomCatalogItems( @@ -192,18 +189,6 @@ public class LoadoutGenerator return string.Equals(item.Category, requestedType.Name, StringComparison.Ordinal); } - private T ProjectRuntimeItem(AetheriaRuntimeCatalogItem item) where T : EquippableItemData - { - if (item == null) - { - return null; - } - - return Guid.TryParse(item.LegacyId, out var legacyId) - ? ItemManager.GetRuntimeItemProjection(legacyId) - : null; - } - private float ManufacturerDistancePenalty(Guid manufacturer) { if (Galaxy == null || Zone == null || !Galaxy.ContainsFaction(manufacturer)) @@ -324,10 +309,9 @@ public class LoadoutGenerator ? nameof(TurretControllerData) : null; var controllerRow = RandomCatalogItem(hardpoint, 2, item => HasBehaviorKind(item, controllerBehaviorKind)); - var controllerData = ProjectRuntimeItem(controllerRow); - if (controllerData == null) + if (controllerRow == null) throw new InvalidLoadoutException("No compatible controller found for entity!"); - var controller = ItemManager.CreateInstance(controllerData) as EquippableItem; + var controller = ItemManager.CreateEquippableInstance(controllerRow); if (!entity.TryEquip(controller)) { throw new InvalidLoadoutException($"Failed to equip selected {hardpoint.Type}!"); @@ -343,15 +327,14 @@ public class LoadoutGenerator ? entity.Equipment.FirstOrDefault(item => item.EquippableItem.Data.ItemId == previousItemId) : null; itemRow ??= RandomCatalogItem(hardpoint, 2); - var itemData = ProjectRuntimeItem(itemRow); - if (itemData == null) ItemManager.Log($"No compatible item found for entity {hardpoint.Type} hardpoint!"); + if (itemRow == null) ItemManager.Log($"No compatible item found for entity {hardpoint.Type} hardpoint!"); else { //throw new InvalidLoadoutException($"No compatible item found for entity {hardpoint.Type} hardpoint!"); EquippableItem item; if(previousItem!=null) - item = ItemManager.CreateInstance(itemData, previousItem.EquippableItem.Quality) as EquippableItem; - else item = ItemManager.CreateInstance(itemData) as EquippableItem; + item = ItemManager.CreateEquippableInstance(itemRow, previousItem.EquippableItem.Quality); + else item = ItemManager.CreateEquippableInstance(itemRow); if (!entity.TryEquip(item)) { throw new InvalidLoadoutException($"Failed to equip selected {hardpoint.Type}!"); @@ -364,11 +347,10 @@ public class LoadoutGenerator var emptyShape = entity.UnoccupiedSpace; var cargoRow = RandomCatalogItem(3, item => item.Category != "DockingBayData" && FitsWithin(item, emptyShape)); - var cargoData = ProjectRuntimeItem(cargoRow); - if (cargoData == null) throw new InvalidLoadoutException("No compatible cargo bay found for entity!"); + if (cargoRow == null) throw new InvalidLoadoutException("No compatible cargo bay found for entity!"); ToShape(cargoRow).FitsWithin(emptyShape, out var cargoRotation, out var cargoPosition); - var cargo = ItemManager.CreateInstance(cargoData) as EquippableItem; + var cargo = ItemManager.CreateEquippableInstance(cargoRow); cargo.Rotation = cargoRotation; if (!entity.TryEquip(cargo, cargoPosition)) throw new InvalidLoadoutException("Failed to equip selected cargo bay!"); @@ -378,11 +360,10 @@ public class LoadoutGenerator var capacitorRow = RandomCatalogItem(2, item => item.BehaviorKinds.Contains(nameof(CapacitorData), StringComparer.Ordinal) && FitsWithin(item, emptyShape)); - var capacitorData = ProjectRuntimeItem(capacitorRow); - if (capacitorData == null) throw new InvalidLoadoutException("No compatible capacitor found for entity!"); + if (capacitorRow == null) throw new InvalidLoadoutException("No compatible capacitor found for entity!"); ToShape(capacitorRow).FitsWithin(emptyShape, out var capacitorRotation, out var capacitorPosition); - var capacitor = ItemManager.CreateInstance(capacitorData) as EquippableItem; + var capacitor = ItemManager.CreateEquippableInstance(capacitorRow); capacitor.Rotation = capacitorRotation; if (!entity.TryEquip(capacitor, capacitorPosition)) throw new InvalidLoadoutException("Failed to equip selected capacitor!"); diff --git a/Assets/Scripts/ServerShared/RuntimeProjection/RuntimeItemProjectionEntry.cs b/Assets/Scripts/ServerShared/RuntimeProjection/RuntimeItemProjectionEntry.cs index 61d1a0279..763076497 100644 --- a/Assets/Scripts/ServerShared/RuntimeProjection/RuntimeItemProjectionEntry.cs +++ b/Assets/Scripts/ServerShared/RuntimeProjection/RuntimeItemProjectionEntry.cs @@ -35,6 +35,11 @@ public class RuntimeItemReference { } + public RuntimeItemReference(Guid itemId) + { + ItemId = itemId; + } + public RuntimeItemReference(ItemData value) { SetProjection(value); diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 34c9aa421..0e329731e 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -199,9 +199,10 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted. names entities from the typed hull row and no longer keeps a `HullData` property just to preserve the old naming bridge. `LoadoutGenerator` candidate weighting, hardpoint/cargo/capacitor fit, selected-item reuse, and - hull conductivity setup now use typed runtime catalog rows; selected DTO - hydration is only the remaining item-instantiation bridge. Docking bay max - ship size is imported as typed item state and `EquippedDockingBay.MaxSize` + hull conductivity setup now use typed runtime catalog rows. Generated loadout + item birth also uses a typed-row instance primitive, so selected catalog rows + no longer hydrate `EquippableItemData` just to create equipment. Docking bay + max ship size is imported as typed item state and `EquippedDockingBay.MaxSize` derives from the typed runtime catalog row. `EquippedItem.InsetShape` now derives from typed hull/item shape rows. `EquippedItem` and `ConsumableItemEffect` behavior construction now read typed behavior payloads @@ -770,6 +771,10 @@ First Aetheria surfaces to publish: `TryUnequip` gear occupancy/mass deltas onto typed catalog rows for item shape, hull shape/interior, hardpoint masks, cargo/docking category, and mass/thermal mass. + - Done: move `LoadoutGenerator` selected item birth onto typed runtime item + rows via `ItemManager.CreateEquippableInstance`; generated hulls, cargo, + docking bays, controllers, capacitors, reused gear, and station inventory no + longer hydrate `EquippableItemData` projections merely to instantiate. - Done: import typed conductivity and hull physical facets, regenerate the checked-in `.cc` catalog, and move `Entity.MapEntity`, `Entity.UnoccupiedSpace`, grid-offset placement, and