Restore the stable legacy Unity project
This commit is contained in:
parent
56a156ee87
commit
7006a6b0dd
2070 changed files with 180490 additions and 169303 deletions
|
|
@ -1,23 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using Random = CultMath.Random;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
public class LoadoutGenerator
|
||||
{
|
||||
private enum RuntimeItemCandidateKind
|
||||
{
|
||||
Equipment,
|
||||
Gear,
|
||||
CargoBay,
|
||||
DockingBay,
|
||||
Hull
|
||||
}
|
||||
|
||||
public Random Random;
|
||||
public ItemManager ItemManager { get; }
|
||||
public AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; }
|
||||
public Galaxy Galaxy { get; }
|
||||
public GalaxyZone Zone { get; }
|
||||
public Faction Faction { get; }
|
||||
|
|
@ -26,7 +18,6 @@ public class LoadoutGenerator
|
|||
public LoadoutGenerator(
|
||||
ref Random random,
|
||||
ItemManager itemManager,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
Galaxy galaxy,
|
||||
GalaxyZone zone,
|
||||
Faction faction,
|
||||
|
|
@ -34,63 +25,75 @@ public class LoadoutGenerator
|
|||
{
|
||||
Random = random;
|
||||
ItemManager = itemManager;
|
||||
RuntimeCatalog = runtimeCatalog ?? throw new InvalidOperationException("Loadout generation requires the typed Aetheria runtime catalog.");
|
||||
Galaxy = galaxy;
|
||||
Zone = zone;
|
||||
Faction = faction;
|
||||
PriceExponent = priceExponent;
|
||||
}
|
||||
public EntityConstructionBlueprint GenerateShipLoadout(Predicate<AetheriaRuntimeCatalogItem> hullFilter = null)
|
||||
//
|
||||
// public LoadoutGenerator(
|
||||
// ref Random random,
|
||||
// ItemManager itemManager,
|
||||
// Faction faction,
|
||||
// float priceExponent)
|
||||
// {
|
||||
// Random = random;
|
||||
// ItemManager = itemManager;
|
||||
// Faction = faction;
|
||||
// PriceExponent = priceExponent;
|
||||
// }
|
||||
|
||||
public EntityPack GenerateShipLoadout(Predicate<HullData> hullFilter = null)
|
||||
{
|
||||
var hullRow = RandomHull(HullType.Ship, hullFilter);
|
||||
if(hullRow==null)
|
||||
var hullData = RandomHull(HullType.Ship, hullFilter);
|
||||
if(hullData==null)
|
||||
{
|
||||
ItemManager.Log("Unable to generate ship loadout: no compatible hull found!");
|
||||
return null;
|
||||
}
|
||||
var hull = ItemManager.CreateEquippableInstance(hullRow);
|
||||
var hull = ItemManager.CreateInstance(hullData) as EquippableItem;
|
||||
if(hull==null)
|
||||
ItemManager.Log("WHAT???");
|
||||
var entity = new Ship(ItemManager, null, hull, ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
entity.Faction = Faction;
|
||||
OutfitEntity(entity);
|
||||
return EntityConstructionBlueprintCapture.Capture(entity);
|
||||
return EntitySerializer.Pack(entity);
|
||||
}
|
||||
|
||||
public OrbitalEntityConstructionBlueprint GenerateTurretLoadout()
|
||||
public OrbitalEntityPack GenerateTurretLoadout()
|
||||
{
|
||||
var hullRow = RandomHull(HullType.Turret);
|
||||
if(hullRow==null)
|
||||
var hullData = RandomHull(HullType.Turret);
|
||||
if(hullData==null)
|
||||
{
|
||||
ItemManager.Log("Unable to generate turret loadout: no compatible hull found!");
|
||||
return null;
|
||||
}
|
||||
var hull = ItemManager.CreateEquippableInstance(hullRow);
|
||||
var entity = new OrbitalEntity(ItemManager, null, hull, "", ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
var hull = ItemManager.CreateInstance(hullData) as EquippableItem;
|
||||
var entity = new OrbitalEntity(ItemManager, null, hull, Guid.Empty, ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
entity.Faction = Faction;
|
||||
OutfitEntity(entity);
|
||||
return EntityConstructionBlueprintCapture.Capture(entity) as OrbitalEntityConstructionBlueprint;
|
||||
return EntitySerializer.Pack(entity) as OrbitalEntityPack;
|
||||
}
|
||||
|
||||
public OrbitalEntityConstructionBlueprint GenerateStationLoadout()
|
||||
public OrbitalEntityPack GenerateStationLoadout()
|
||||
{
|
||||
var hullRow = RandomHull(HullType.Station);
|
||||
if(hullRow==null)
|
||||
var hullData = RandomHull(HullType.Station);
|
||||
if(hullData==null)
|
||||
{
|
||||
ItemManager.Log("Unable to generate station loadout: no compatible hull found!");
|
||||
return null;
|
||||
}
|
||||
var hull = ItemManager.CreateEquippableInstance(hullRow);
|
||||
var entity = new OrbitalEntity(ItemManager, null, hull, "", ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
var hull = ItemManager.CreateInstance(hullData) as EquippableItem;
|
||||
var entity = new OrbitalEntity(ItemManager, null, hull, Guid.Empty, ItemManager.GameplaySettings.DefaultEntitySettings);
|
||||
entity.Faction = Faction;
|
||||
|
||||
var emptyShape = entity.UnoccupiedSpace;
|
||||
|
||||
var dockingBayRow = RandomCatalogItem(RuntimeItemCandidateKind.DockingBay, 2, item => FitsWithin(item, emptyShape));
|
||||
if (dockingBayRow == null) throw new InvalidLoadoutException("No compatible docking bay found for station!");
|
||||
var dockingBayData = RandomItem<DockingBayData>(2, item => item.Shape.FitsWithin(emptyShape, out _, out _));
|
||||
if (dockingBayData == null) throw new InvalidLoadoutException("No compatible docking bay found for station!");
|
||||
|
||||
ToShape(dockingBayRow).FitsWithin(emptyShape, out var cargoRotation, out var cargoPosition);
|
||||
var dockingBay = ItemManager.CreateEquippableInstance(dockingBayRow);
|
||||
dockingBayData.Shape.FitsWithin(emptyShape, out var cargoRotation, out var cargoPosition);
|
||||
var dockingBay = ItemManager.CreateInstance(dockingBayData) as EquippableItem;
|
||||
dockingBay.Rotation = cargoRotation;
|
||||
if (!entity.TryEquip(dockingBay, cargoPosition))
|
||||
{
|
||||
|
|
@ -100,265 +103,125 @@ public class LoadoutGenerator
|
|||
OutfitEntity(entity);
|
||||
|
||||
var cargo = entity.CargoBays.First();
|
||||
IEnumerable<AetheriaRuntimeCatalogItem> inventory = RandomCatalogItems(RuntimeItemCandidateKind.Equipment, 16, 1,
|
||||
item => item.Category != AetheriaRuntimeItemCategories.CargoBay && item.Category != AetheriaRuntimeItemCategories.DockingBay &&
|
||||
(item.Category != AetheriaRuntimeItemCategories.Hull || item.HullType == nameof(HullType.Ship)));
|
||||
IEnumerable<EquippableItemData> inventory = RandomItems<EquippableItemData>(16, 1,
|
||||
data => !(data is HullData hull && hull.HullType != HullType.Ship) && !(data is CargoBayData));
|
||||
inventory = inventory
|
||||
.Where(item => item != null);
|
||||
inventory = inventory
|
||||
.OrderByDescending(item=>item.OccupiedCells);
|
||||
.OrderByDescending(item=>item.Shape.Coordinates.Length);
|
||||
foreach (var item in inventory)
|
||||
{
|
||||
var instance = ItemManager.CreateEquippableInstance(item);
|
||||
var instance = ItemManager.CreateInstance(item);
|
||||
cargo.TryStore(instance);
|
||||
}
|
||||
|
||||
entity.CanTow = hullRow.HullCanTow;
|
||||
entity.CanTow = hullData.CanTow;
|
||||
|
||||
return EntityConstructionBlueprintCapture.Capture(entity) as OrbitalEntityConstructionBlueprint;
|
||||
return EntitySerializer.Pack(entity) as OrbitalEntityPack;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogItem RandomHull(HullType type, Predicate<AetheriaRuntimeCatalogItem> hullFilter = null)
|
||||
public HullData RandomHull(HullType type, Predicate<HullData> hullFilter = null)
|
||||
{
|
||||
return RandomCatalogItem(RuntimeItemCandidateKind.Hull, 0, item =>
|
||||
string.Equals(item.HullType, type.ToString(), StringComparison.Ordinal) &&
|
||||
(hullFilter?.Invoke(item) ?? true));
|
||||
return RandomItem<HullData>(0, item =>
|
||||
(hullFilter?.Invoke(item) ?? true) &&
|
||||
item.HullType == type);
|
||||
}
|
||||
|
||||
private AetheriaRuntimeCatalogItem[] RandomCatalogItems(
|
||||
RuntimeItemCandidateKind candidateKind,
|
||||
int count,
|
||||
float sizeExponent,
|
||||
Predicate<AetheriaRuntimeCatalogItem> typedFilter = null)
|
||||
public T[] RandomItems<T>(int count, float sizeExponent, Predicate<T> filter = null) where T : EquippableItemData
|
||||
{
|
||||
return RuntimeCatalog.EquipmentItems
|
||||
.Where(item => IsTypedCandidate(item, candidateKind))
|
||||
.Where(item =>
|
||||
return ItemManager.ItemData.GetAll<T>()
|
||||
.Where(item =>
|
||||
item.Price > 0 &&
|
||||
!string.IsNullOrWhiteSpace(item.ManufacturerKey) &&
|
||||
(Galaxy.IsPrelude || Galaxy.ContainsFaction(item.ManufacturerKey) &&
|
||||
(Faction == null || Faction.AllegianceByKey.ContainsKey(item.ManufacturerKey))) &&
|
||||
(typedFilter?.Invoke(item) ?? true))
|
||||
item.Manufacturer != Guid.Empty &&
|
||||
(Galaxy.IsPrelude || Galaxy.ContainsFaction(item.Manufacturer) &&
|
||||
(Faction == null || Faction.Allegiance.ContainsKey(item.Manufacturer))) &&
|
||||
(filter?.Invoke(item) ?? true))
|
||||
.WeightedRandomElements(ref Random, item =>
|
||||
{
|
||||
var manufacturerKey = item.ManufacturerKey;
|
||||
if (string.IsNullOrWhiteSpace(manufacturerKey))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var allegianceWeight = Faction == null
|
||||
? 1
|
||||
: string.Equals(manufacturerKey, Faction.FactionKey, StringComparison.OrdinalIgnoreCase)
|
||||
? 1
|
||||
: Faction.AllegianceByKey.TryGetValue(manufacturerKey, out var allegiance)
|
||||
? allegiance / ManufacturerDistancePenalty(manufacturerKey)
|
||||
: 0;
|
||||
return allegianceWeight *
|
||||
MathF.Pow(item.OccupiedCells, sizeExponent) / // Prioritize larger items
|
||||
MathF.Pow(item.Price, PriceExponent); // Penalize item price to a controllable degree
|
||||
},
|
||||
Faction == null ? 1 :
|
||||
(item.Manufacturer == Faction.ID ? 1 : Faction.Allegiance.ContainsKey(item.Manufacturer) ? Faction.Allegiance[item.Manufacturer] : 0.0f / // Prioritize items from allied manufacturers
|
||||
(Galaxy?.ContainsFaction(item.Manufacturer) ?? false ? Zone?.Distance[Galaxy.HomeZones[ItemManager.ItemData.Get<Faction>(item.Manufacturer)]] ?? 1 : 1)) * // Penalize distance to manufacturer headquarters
|
||||
pow(item.Shape.Coordinates.Length, sizeExponent) / // Prioritize larger items
|
||||
pow(item.Price, PriceExponent), // Penalize item price to a controllable degree
|
||||
count
|
||||
);
|
||||
}
|
||||
|
||||
private static bool IsTypedCandidate(AetheriaRuntimeCatalogItem item, RuntimeItemCandidateKind candidateKind)
|
||||
public T RandomItem<T>(float sizeExponent, Predicate<T> filter = null) where T : EquippableItemData
|
||||
{
|
||||
switch (candidateKind)
|
||||
{
|
||||
case RuntimeItemCandidateKind.Equipment:
|
||||
return !string.IsNullOrWhiteSpace(item.HardpointType);
|
||||
case RuntimeItemCandidateKind.Gear:
|
||||
return item.Category == AetheriaRuntimeItemCategories.Gear || item.Category == AetheriaRuntimeItemCategories.Weapon;
|
||||
case RuntimeItemCandidateKind.CargoBay:
|
||||
return item.Category == AetheriaRuntimeItemCategories.CargoBay || item.Category == AetheriaRuntimeItemCategories.DockingBay;
|
||||
case RuntimeItemCandidateKind.DockingBay:
|
||||
return item.Category == AetheriaRuntimeItemCategories.DockingBay;
|
||||
case RuntimeItemCandidateKind.Hull:
|
||||
return item.Category == AetheriaRuntimeItemCategories.Hull;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(candidateKind), candidateKind, null);
|
||||
}
|
||||
}
|
||||
|
||||
private float ManufacturerDistancePenalty(string manufacturerKey)
|
||||
{
|
||||
if (Galaxy == null || Zone == null || !Galaxy.ContainsFaction(manufacturerKey))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var faction = Galaxy.ResolveFactionByKey(manufacturerKey);
|
||||
return faction != null && Galaxy.HomeZones.TryGetValue(faction, out var homeZone)
|
||||
? Zone.Distance[homeZone]
|
||||
: 1;
|
||||
}
|
||||
|
||||
private AetheriaRuntimeCatalogItem RandomCatalogItem(
|
||||
RuntimeItemCandidateKind candidateKind,
|
||||
float sizeExponent,
|
||||
Predicate<AetheriaRuntimeCatalogItem> typedFilter = null)
|
||||
{
|
||||
return RandomCatalogItems(candidateKind, 1, sizeExponent, typedFilter).FirstOrDefault();
|
||||
return RandomItems(1, sizeExponent, filter).FirstOrDefault();
|
||||
}
|
||||
|
||||
private AetheriaRuntimeCatalogItem RandomCatalogItem(
|
||||
RuntimeItemCandidateKind candidateKind,
|
||||
AetheriaRuntimeHardpoint hardpoint,
|
||||
float sizeExponent,
|
||||
Predicate<AetheriaRuntimeCatalogItem> filter = null)
|
||||
public T RandomItem<T>(HardpointData hardpoint, float sizeExponent, Predicate<T> filter = null) where T : EquippableItemData
|
||||
{
|
||||
return RandomCatalogItem(
|
||||
candidateKind,
|
||||
sizeExponent,
|
||||
item => FitsHardpoint(item, hardpoint) && (filter?.Invoke(item) ?? true));
|
||||
}
|
||||
|
||||
private static bool FitsHardpoint(AetheriaRuntimeCatalogItem item, AetheriaRuntimeHardpoint hardpoint)
|
||||
{
|
||||
return item != null &&
|
||||
hardpoint != null &&
|
||||
string.Equals(item.HardpointType, hardpoint.Type, StringComparison.Ordinal) &&
|
||||
FitsWithin(item, ToShape(hardpoint), GetRotation(hardpoint));
|
||||
}
|
||||
|
||||
private static bool HasBehaviorKind(AetheriaRuntimeCatalogItem item, string behaviorKind)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(behaviorKind) &&
|
||||
item.BehaviorKinds.Contains(behaviorKind, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static bool FitsWithin(AetheriaRuntimeCatalogItem item, Shape target)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ToShape(item).FitsWithin(target, out _, out _);
|
||||
}
|
||||
|
||||
private static bool FitsWithin(AetheriaRuntimeCatalogItem item, Shape target, ItemRotation rotation)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ToShape(item).FitsWithin(target, rotation, out _);
|
||||
}
|
||||
|
||||
private static Shape ToShape(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new InvalidLoadoutException("Typed catalog shape was requested before a compatible item was selected.");
|
||||
}
|
||||
|
||||
return ToShape(item.ShapeWidth, item.ShapeHeight, item.ShapeCells);
|
||||
}
|
||||
|
||||
private static Shape ToShape(AetheriaRuntimeHardpoint hardpoint)
|
||||
{
|
||||
if (hardpoint == null)
|
||||
{
|
||||
throw new InvalidLoadoutException("Typed hardpoint shape was requested before a hardpoint was selected.");
|
||||
}
|
||||
|
||||
return ToShape(hardpoint.ShapeWidth, hardpoint.ShapeHeight, hardpoint.ShapeCells);
|
||||
}
|
||||
|
||||
private static Shape ToShape(int width, int height, IReadOnlyList<AetheriaRuntimeShapeCell> cells)
|
||||
{
|
||||
var shape = new Shape(Math.Max(width, 1), Math.Max(height, 1));
|
||||
foreach (var cell in cells)
|
||||
{
|
||||
shape.SetCell(cell.X, cell.Y, true);
|
||||
}
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private static ItemRotation GetRotation(AetheriaRuntimeHardpoint hardpoint)
|
||||
{
|
||||
return Enum.TryParse(hardpoint.Rotation, out ItemRotation rotation)
|
||||
? rotation
|
||||
: ItemRotation.None;
|
||||
return RandomItem<T>(sizeExponent, item => item.HardpointType == hardpoint.Type &&
|
||||
(filter?.Invoke(item) ?? true) &&
|
||||
item.Shape.FitsWithin(hardpoint.Shape, hardpoint.Rotation, out _) &&
|
||||
item.Shape.Coordinates.Length==hardpoint.Shape.Coordinates.Length);
|
||||
}
|
||||
|
||||
private void OutfitEntity(Entity entity)
|
||||
{
|
||||
var typedHull = ItemManager.GetRuntimeItem(entity.Hull);
|
||||
if (typedHull == null)
|
||||
var hullData = ItemManager.GetData(entity.Hull) as HullData;
|
||||
foreach (var v in hullData.Shape.Coordinates) entity.HullConductivity[v.x, v.y] = true;
|
||||
var previousItems = new List<EquippableItemData>();
|
||||
foreach (var hardpoint in hullData.Hardpoints.OrderByDescending(h=>h.Shape.Coordinates.Length))
|
||||
{
|
||||
throw new InvalidLoadoutException("Selected hull is missing from the typed runtime catalog.");
|
||||
}
|
||||
|
||||
foreach (var v in ToShape(typedHull).Coordinates) entity.HullConductivity[v.x, v.y] = true;
|
||||
var previousItems = new List<AetheriaRuntimeCatalogItem>();
|
||||
foreach (var hardpoint in typedHull.Hardpoints.OrderByDescending(h=>h.OccupiedCells))
|
||||
{
|
||||
if (hardpoint.Type == nameof(HardpointType.ControlModule))
|
||||
if (hardpoint.Type == HardpointType.ControlModule)
|
||||
{
|
||||
var controllerBehaviorKind = entity is Ship
|
||||
? "Cockpit"
|
||||
: entity is OrbitalEntity
|
||||
? "TurretController"
|
||||
: null;
|
||||
var controllerRow = RandomCatalogItem(RuntimeItemCandidateKind.Gear, hardpoint, 2, item => HasBehaviorKind(item, controllerBehaviorKind));
|
||||
if (controllerRow == null)
|
||||
var controllerData = RandomItem<GearData>(hardpoint, 2,
|
||||
item => item.Behaviors.Any(b => entity is Ship && b is CockpitData || entity is OrbitalEntity && b is TurretControllerData));
|
||||
if (controllerData == null)
|
||||
throw new InvalidLoadoutException("No compatible controller found for entity!");
|
||||
var controller = ItemManager.CreateEquippableInstance(controllerRow);
|
||||
var controller = ItemManager.CreateInstance(controllerData) as EquippableItem;
|
||||
if (!entity.TryEquip(controller))
|
||||
{
|
||||
throw new InvalidLoadoutException($"Failed to equip selected {hardpoint.Type}!");
|
||||
throw new InvalidLoadoutException($"Failed to equip selected {Enum.GetName(typeof(HardpointType), hardpoint.Type)}!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If a previously selected item fits, use that one (this is why we must process larger hardpoints first)
|
||||
var itemRow = previousItems.FirstOrDefault(i => FitsHardpoint(i, hardpoint));
|
||||
var previousItem = itemRow == null
|
||||
? null
|
||||
: entity.Equipment.FirstOrDefault(item => item.EquippableItem.ItemKey == itemRow.ItemKey);
|
||||
itemRow ??= RandomCatalogItem(RuntimeItemCandidateKind.Gear, hardpoint, 2);
|
||||
if (itemRow == null) ItemManager.Log($"No compatible item found for entity {hardpoint.Type} hardpoint!");
|
||||
var itemData = previousItems
|
||||
.FirstOrDefault(i => i.HardpointType == hardpoint.Type && i.Shape.FitsWithin(hardpoint.Shape, hardpoint.Rotation, out _));
|
||||
var previousItem = entity.Equipment.FirstOrDefault(item => item.Data == itemData);
|
||||
itemData ??= RandomItem<GearData>(hardpoint, 2);
|
||||
if (itemData == null) ItemManager.Log($"No compatible item found for entity {Enum.GetName(typeof(HardpointType), hardpoint.Type)} hardpoint!");
|
||||
else
|
||||
{
|
||||
//throw new InvalidLoadoutException($"No compatible item found for entity {hardpoint.Type} hardpoint!");
|
||||
//throw new InvalidLoadoutException($"No compatible item found for entity {Enum.GetName(typeof(HardpointType), hardpoint.Type)} hardpoint!");
|
||||
EquippableItem item;
|
||||
if(previousItem!=null)
|
||||
item = ItemManager.CreateEquippableInstance(itemRow, previousItem.EquippableItem.Quality);
|
||||
else item = ItemManager.CreateEquippableInstance(itemRow);
|
||||
item = ItemManager.CreateInstance(itemData, previousItem.EquippableItem.Quality) as EquippableItem;
|
||||
else item = ItemManager.CreateInstance(itemData) as EquippableItem;
|
||||
if (!entity.TryEquip(item))
|
||||
{
|
||||
throw new InvalidLoadoutException($"Failed to equip selected {hardpoint.Type}!");
|
||||
throw new InvalidLoadoutException($"Failed to equip selected {Enum.GetName(typeof(HardpointType), hardpoint.Type)}!");
|
||||
}
|
||||
previousItems.Add(itemRow);
|
||||
previousItems.Add(itemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var emptyShape = entity.UnoccupiedSpace;
|
||||
|
||||
var cargoRow = RandomCatalogItem(RuntimeItemCandidateKind.CargoBay, 3, item => item.Category != AetheriaRuntimeItemCategories.DockingBay && FitsWithin(item, emptyShape));
|
||||
if (cargoRow == null) throw new InvalidLoadoutException("No compatible cargo bay found for entity!");
|
||||
var cargoData = RandomItem<CargoBayData>(3, item =>
|
||||
!(item is DockingBayData) &&
|
||||
item.Shape.FitsWithin(emptyShape, out _, out _));
|
||||
if (cargoData == null) throw new InvalidLoadoutException("No compatible cargo bay found for entity!");
|
||||
|
||||
ToShape(cargoRow).FitsWithin(emptyShape, out var cargoRotation, out var cargoPosition);
|
||||
var cargo = ItemManager.CreateEquippableInstance(cargoRow);
|
||||
cargoData.Shape.FitsWithin(emptyShape, out var cargoRotation, out var cargoPosition);
|
||||
var cargo = ItemManager.CreateInstance(cargoData) as EquippableItem;
|
||||
cargo.Rotation = cargoRotation;
|
||||
if (!entity.TryEquip(cargo, cargoPosition))
|
||||
throw new InvalidLoadoutException("Failed to equip selected cargo bay!");
|
||||
|
||||
emptyShape = entity.UnoccupiedSpace;
|
||||
|
||||
var capacitorRow = RandomCatalogItem(RuntimeItemCandidateKind.Gear, 2,
|
||||
item => item.BehaviorKinds.Contains("Capacitor", StringComparer.Ordinal) &&
|
||||
FitsWithin(item, emptyShape));
|
||||
if (capacitorRow == null) throw new InvalidLoadoutException("No compatible capacitor found for entity!");
|
||||
var capacitorData = RandomItem<GearData>(2, item =>
|
||||
item.Behaviors.Any(b => b is CapacitorData) &&
|
||||
item.Shape.FitsWithin(emptyShape, out _, out _));
|
||||
if (capacitorData == null) throw new InvalidLoadoutException("No compatible capacitor found for entity!");
|
||||
|
||||
ToShape(capacitorRow).FitsWithin(emptyShape, out var capacitorRotation, out var capacitorPosition);
|
||||
var capacitor = ItemManager.CreateEquippableInstance(capacitorRow);
|
||||
capacitorData.Shape.FitsWithin(emptyShape, out var capacitorRotation, out var capacitorPosition);
|
||||
var capacitor = ItemManager.CreateInstance(capacitorData) as EquippableItem;
|
||||
capacitor.Rotation = capacitorRotation;
|
||||
if (!entity.TryEquip(capacitor, capacitorPosition))
|
||||
throw new InvalidLoadoutException("Failed to equip selected capacitor!");
|
||||
|
|
@ -380,4 +243,4 @@ public class InvalidLoadoutException : Exception
|
|||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue