From a901a8e829e861d10684f642114e9e6600f55ffc Mon Sep 17 00:00:00 2001 From: hyperion51 Date: Thu, 11 Jun 2020 02:55:11 +0100 Subject: [PATCH] Ship Building & Drydock Made it possible to turn new hulls into drones which can then be outfitted and activated for service Missing blueprint ingredients no longer crash the game and gracefully log what's broken Loadout cargo is now stored entirely separate from gear --- .../.idea/contentModel.xml | 4 +- Assets/Scripts/Editor/DatabaseInspector.cs | 52 ++------- Assets/Scripts/Editor/DatabaseView.cs | 2 +- .../ServerShared/Behaviors/Controller.cs | 4 +- .../{DatabaseItems.cs => DatabaseEntry.cs} | 47 +------- ...aseItems.cs.meta => DatabaseEntry.cs.meta} | 0 Assets/Scripts/ServerShared/Entity.cs | 21 +++- Assets/Scripts/ServerShared/GameContext.cs | 74 +++++++++---- Assets/Scripts/ServerShared/LoadoutData.cs | 29 +++++ .../Scripts/ServerShared/LoadoutData.cs.meta | 3 + Assets/Scripts/ServerShared/PlayerData.cs | 25 +++++ .../Scripts/ServerShared/PlayerData.cs.meta | 3 + Assets/Scripts/ServerShared/Ship.cs | 103 ------------------ Assets/Scripts/StrategyGameManager.cs | 4 +- Assets/Scripts/UI/ColonyTab.cs | 16 ++- Assets/Scripts/UI/PropertiesPanel.cs | 2 + Economy.Shared.Unity.csproj | 4 +- 17 files changed, 167 insertions(+), 226 deletions(-) rename Assets/Scripts/ServerShared/{DatabaseItems.cs => DatabaseEntry.cs} (52%) rename Assets/Scripts/ServerShared/{DatabaseItems.cs.meta => DatabaseEntry.cs.meta} (100%) create mode 100644 Assets/Scripts/ServerShared/LoadoutData.cs create mode 100644 Assets/Scripts/ServerShared/LoadoutData.cs.meta create mode 100644 Assets/Scripts/ServerShared/PlayerData.cs create mode 100644 Assets/Scripts/ServerShared/PlayerData.cs.meta diff --git a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml index 0a2f67029..b87903c31 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml @@ -1291,7 +1291,7 @@ - + @@ -1302,6 +1302,7 @@ + @@ -1745,6 +1746,7 @@ + diff --git a/Assets/Scripts/Editor/DatabaseInspector.cs b/Assets/Scripts/Editor/DatabaseInspector.cs index eb6c3b813..77c8a42b3 100644 --- a/Assets/Scripts/Editor/DatabaseInspector.cs +++ b/Assets/Scripts/Editor/DatabaseInspector.cs @@ -1112,14 +1112,14 @@ public class DatabaseInspector : EditorWindow { // Reserve slots in the loadout for all equippable (non-hull) hardpoints var hardpoints = loadoutHull.Hardpoints.Where(h => h.Type != HardpointType.Hull).ToArray(); - if (loadout.Items.Count < hardpoints.Length) - loadout.Items.AddRange(Enumerable.Repeat(Guid.Empty, hardpoints.Length - loadout.Items.Count)); + if (loadout.Gear.Count < hardpoints.Length) + loadout.Gear.AddRange(Enumerable.Repeat(Guid.Empty, hardpoints.Length - loadout.Gear.Count)); Space(); using (var h = new HorizontalScope()) { - GUILayout.Label($"Equipped Items: {loadout.Items.Sum(i=>((ItemData) DatabaseCache.Get(i))?.Size ?? 0)}/{loadoutHull.Capacity.Min}", EditorStyles.boldLabel); - GUILayout.Label($"Mass: {loadout.Items.Sum(i=>((ItemData) DatabaseCache.Get(i))?.Mass ?? 0)}", EditorStyles.boldLabel, GUILayout.ExpandWidth(false)); + GUILayout.Label($"Equipped Items: {loadout.Gear.Sum(i=>((ItemData) DatabaseCache.Get(i))?.Size ?? 0)}/{loadoutHull.Capacity.Min}", EditorStyles.boldLabel); + GUILayout.Label($"Mass: {loadout.Gear.Sum(i=>((ItemData) DatabaseCache.Get(i))?.Mass ?? 0)}", EditorStyles.boldLabel, GUILayout.ExpandWidth(false)); } int itemIndex = 0; @@ -1129,11 +1129,11 @@ public class DatabaseInspector : EditorWindow { var hp = hardpoints[itemIndex]; - var loadoutItem = DatabaseCache.Get(loadout.Items[itemIndex]) as EquippableItemData; + var loadoutItem = DatabaseCache.Get(loadout.Gear[itemIndex]) as EquippableItemData; if (loadoutItem != null && loadoutItem.HardpointType != hp.Type) { - loadout.Items[itemIndex] = Guid.Empty; + loadout.Gear[itemIndex] = Guid.Empty; Debug.Log($"Invalid Item \"{loadoutItem.Name}\" in {Enum.GetName(typeof(HardpointType),hp.Type)} hardpoint for loadout \"{loadout.Name}\""); GUI.changed = true; } @@ -1151,7 +1151,7 @@ public class DatabaseInspector : EditorWindow else if (currentEventType == EventType.DragPerform && good) { DragAndDrop.AcceptDrag(); - loadout.Items[itemIndex] = guid; + loadout.Gear[itemIndex] = guid; GUI.changed = true; } @@ -1166,46 +1166,16 @@ public class DatabaseInspector : EditorWindow var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, Color.black, 0, 0); if (GUI.Button(rect, GUIContent.none, GUIStyle.none)) - loadout.Items[itemIndex] = Guid.Empty; + loadout.Gear[itemIndex] = Guid.Empty; } } } } - - Space(); - LabelField("Cargo", EditorStyles.boldLabel); - using (var v = new VerticalScope(GUI.skin.box)) + for (; itemIndex < loadout.Gear.Count; itemIndex++) { - if (v.rect.Contains(current.mousePosition) && - (currentEventType == EventType.DragUpdated || currentEventType == EventType.DragPerform)) - { - var guid = (Guid) DragAndDrop.GetGenericData("Item"); - var dragItem = DatabaseCache.Get(guid) as CraftedItemData; - if (currentEventType == EventType.DragUpdated) - DragAndDrop.visualMode = dragItem != null ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if (currentEventType == EventType.DragPerform && dragItem != null) - { - DragAndDrop.AcceptDrag(); - - loadout.Items.Add(guid); - GUI.changed = true; - } - } - if(itemIndex == loadout.Items.Count) - GUILayout.Label("Nothing Here!"); - for (; itemIndex < loadout.Items.Count; itemIndex++) - { - var loadoutItem = DatabaseCache.Get(loadout.Items[itemIndex]) as ItemData; - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label(loadoutItem?.Name ?? "Invalid Item"); - var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, Color.black, 0, 0); - if (GUI.Button(rect, GUIContent.none, GUIStyle.none)) - loadout.Items.RemoveAt(itemIndex--); - } - } + loadout.Gear.RemoveAt(itemIndex--); + GUI.changed = true; } } } diff --git a/Assets/Scripts/Editor/DatabaseView.cs b/Assets/Scripts/Editor/DatabaseView.cs index e89784b08..00b9075bd 100644 --- a/Assets/Scripts/Editor/DatabaseView.cs +++ b/Assets/Scripts/Editor/DatabaseView.cs @@ -355,7 +355,7 @@ public class DatabaseListView : EditorWindow _databaseCache.Add(blueprint); Select(blueprint); } - GUILayout.Space(30); + GUILayout.Space(40); GUILayout.Label("New Blueprint"); var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, diff --git a/Assets/Scripts/ServerShared/Behaviors/Controller.cs b/Assets/Scripts/ServerShared/Behaviors/Controller.cs index 7dcd78d8e..ecaa9a090 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Controller.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Controller.cs @@ -29,7 +29,7 @@ public abstract class ControllerData : BehaviorData public abstract class ControllerBase : IBehavior, IController, IInitializableBehavior { public Guid HomeEntity; - public bool Available => Task == Guid.Empty; + public bool Available => _spaceworthy && Task == Guid.Empty; public abstract TaskType TaskType { get; } public Guid Zone => _entity.Zone; public BehaviorData Data => _controllerData; @@ -49,12 +49,14 @@ public abstract class ControllerBase : IBehavior, IController, IInitializableBeh private ControllerData _controllerData; private MovementPhase _movementPhase; private Action _onFinishMoving; + private bool _spaceworthy; public ControllerBase(GameContext context, ControllerData data, Entity entity) { _context = context; _controllerData = data; _entity = entity; + entity.GearEvent.OnChanged += () => _spaceworthy = entity.GetBehavior() != null && entity.GetBehavior() != null; } public void Initialize() diff --git a/Assets/Scripts/ServerShared/DatabaseItems.cs b/Assets/Scripts/ServerShared/DatabaseEntry.cs similarity index 52% rename from Assets/Scripts/ServerShared/DatabaseItems.cs rename to Assets/Scripts/ServerShared/DatabaseEntry.cs index f9d48fa3f..5ec08a1a6 100644 --- a/Assets/Scripts/ServerShared/DatabaseItems.cs +++ b/Assets/Scripts/ServerShared/DatabaseEntry.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using JsonKnownTypes; using MessagePack; @@ -29,7 +28,7 @@ public interface INamedEntry Union(8, typeof(GalaxyMapLayerData)), Union(9, typeof(GlobalData)), Union(10, typeof(ZoneData)), - Union(11, typeof(Player)), + Union(11, typeof(PlayerData)), Union(12, typeof(Corporation)), Union(13, typeof(MegaCorporation)), Union(14, typeof(OrbitalEntity)), @@ -50,48 +49,4 @@ public abstract class DatabaseEntry [JsonProperty("id"), Key(0)] public Guid ID = Guid.NewGuid(); [IgnoreMember] public GameContext Context { get; set; } -} - -[RethinkTable("Users"), MessagePackObject, JsonObject(MemberSerialization.OptIn)] -public class Player : DatabaseEntry, INamedEntry -{ - [JsonProperty("email"), Key(1)] - public string Email; - - [JsonProperty("password"), Key(2)] - public string Password; - - [JsonProperty("username"), Key(3)] - public string Username; - - [JsonProperty("corporation"), Key(4)] - public Guid Corporation; - - [IgnoreMember] public string EntryName - { - get => Username; - set => Username = value; - } -} - -[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] -public class LoadoutData : DatabaseEntry, INamedEntry -{ - [InspectableField, JsonProperty("name"), Key(1)] - public string Name; - - [InspectableDatabaseLink(typeof(HullData)), JsonProperty("hull"), Key(2)] - public Guid Hull; - - [JsonProperty("items"), Key(3)] - public List Items = new List(); - - [InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("resourceRequirements"), Key(4)] - public Dictionary SimpleCargo = new Dictionary(); - - [IgnoreMember] public string EntryName - { - get => Name; - set => Name = value; - } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/DatabaseItems.cs.meta b/Assets/Scripts/ServerShared/DatabaseEntry.cs.meta similarity index 100% rename from Assets/Scripts/ServerShared/DatabaseItems.cs.meta rename to Assets/Scripts/ServerShared/DatabaseEntry.cs.meta diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 6ea559ca8..8d3ff0bbf 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -66,6 +66,9 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR [JsonProperty("incompleteCargo"), Key(17)] public Dictionary IncompleteCargo = new Dictionary(); + + [JsonProperty("active"), Key(18)] + public bool Active { get; set; } //public List IncompleteCargo = new List(); [IgnoreMember] public Guid Zone; @@ -130,6 +133,11 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR Hydrate(); } + // private void GenerateHardpoints() + // { + // + // } + public void Hydrate() { //var gearIDs = EquippedItems.Append(Hull); @@ -162,9 +170,6 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR foreach (var hardpoint in Hardpoints) if(hardpoint.Gear!=null) - foreach (var behavior in hardpoint.Behaviors - .Where(behavior => behavior is IInitializableBehavior)) - ((IInitializableBehavior) behavior).Initialize(); RecalculateMass(); } @@ -193,10 +198,14 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger) }) .ToArray(); - - foreach(var behavior in hardpoint.Behaviors) + + foreach (var behavior in hardpoint.Behaviors) + { if(behavior is IPopulationAssignment populationAssignment) PopulationAssignments.Add(populationAssignment); + if(behavior is IInitializableBehavior initializableBehavior) + initializableBehavior.Initialize(); + } } public void Unequip(Hardpoint hardpoint) @@ -541,6 +550,8 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR public virtual void Update(float delta) { + if (!Active) + return; foreach (var hardpoint in Hardpoints.Where(hp=>hp.Gear!=null)) { foreach (var group in hardpoint.BehaviorGroups) diff --git a/Assets/Scripts/ServerShared/GameContext.cs b/Assets/Scripts/ServerShared/GameContext.cs index 13d651516..a21363b71 100644 --- a/Assets/Scripts/ServerShared/GameContext.cs +++ b/Assets/Scripts/ServerShared/GameContext.cs @@ -120,7 +120,7 @@ public class GameContext { // Create a list of available controllers for this task type var availableControllers = CorporationControllers[corporation.ID] - .Where(controller => controller.TaskType == tasks.Key && controller.Available).ToList(); + .Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList(); // Iterate over the highest priority tasks for which controllers are available foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count)) @@ -649,7 +649,7 @@ public class GameContext return null; } - var gearData = loadoutData.Items + var gearData = loadoutData.Gear .Take(hullData.Hardpoints.Count) .Where(id => id != Guid.Empty) .Select(id => Cache.Get(id)) @@ -661,18 +661,6 @@ public class GameContext return null; } - var cargoData = loadoutData.Items - .Skip(hullData.Hardpoints.Count) - .Where(id => id != Guid.Empty) - .Select(id => Cache.Get(id)) - .ToArray(); - - if (cargoData.Any(g=>g==null)) - { - _logger("Attempted to spawn loadout with invalid cargo ID"); - return null; - } - var gear = gearData .Select(gd => CreateInstance(gd.ID, GlobalData.StartingGearQualityMin, GlobalData.StartingGearQualityMax)) .ToArray(); @@ -683,6 +671,16 @@ public class GameContext foreach(var g in gear) Cache.Add(g); + var cargoData = loadoutData.CompoundCargo + .SelectMany(x => Enumerable.Repeat(Cache.Get(x.Key), x.Value)) + .ToArray(); + + if (cargoData.Any(g=>g==null)) + { + _logger("Attempted to spawn loadout with invalid cargo ID"); + return null; + } + var cargo = cargoData .Select(gd => CreateInstance(gd.ID, GlobalData.StartingGearQualityMin, GlobalData.StartingGearQualityMax)) .ToArray(); @@ -716,6 +714,7 @@ public class GameContext { Name = $"{loadoutData.Name} {Random.NextInt(1,255):X}" }; + entity.Active = true; Cache.Add(entity); ZoneEntities[zone][entity.ID] = entity; @@ -746,6 +745,7 @@ public class GameContext Temperature = 293, Population = 4 }; + entity.Active = true; var parentCorp = Cache.Get(corpData.Parent); foreach (var attribute in parentCorp.Personality) entity.Personality[attribute.Key] = attribute.Value; @@ -792,15 +792,45 @@ public class GameContext _logger("Attempted to create crafted item instance which has no blueprint!"); return null; } - - var ingredients = blueprint.Ingredients.SelectMany(ci => + + bool invalidIngredientFound = false; + ItemData invalidIngredient = null; + var ingredients = new List(); + foreach (var ingredient in blueprint.Ingredients) + { + var itemData = Cache.Get(ingredient.Key); + if (itemData is SimpleCommodityData) { - var ingredient = Cache.Get(ci.Key); - return ingredient is SimpleCommodityData - ? (IEnumerable) new[] {CreateInstance(ci.Key, ci.Value)} - : Enumerable.Range(0, ci.Value).Select(i => CreateInstance(ci.Key, qualityMin, qualityMax)); - }) - .ToList(); + var itemInstance = CreateInstance(ingredient.Key, ingredient.Value); + if(itemInstance == null) + { + invalidIngredientFound = true; + invalidIngredient = itemData; + } + else ingredients.Add(itemInstance); + } + else + { + for (int i = 0; i < ingredient.Value; i++) + { + var itemInstance = CreateInstance(ingredient.Key, qualityMin, qualityMax); + if (itemInstance == null) + { + invalidIngredientFound = true; + invalidIngredient = itemData; + break; + } + + ingredients.Add(itemInstance); + } + } + + } + + if (invalidIngredientFound) + { + _logger($"Unable to create crafted item ingredient: {invalidIngredient?.Name??"null"} for item {item.Name}"); + } Cache.AddAll(ingredients); diff --git a/Assets/Scripts/ServerShared/LoadoutData.cs b/Assets/Scripts/ServerShared/LoadoutData.cs new file mode 100644 index 000000000..b6cd34541 --- /dev/null +++ b/Assets/Scripts/ServerShared/LoadoutData.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using MessagePack; +using Newtonsoft.Json; + +[RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +public class LoadoutData : DatabaseEntry, INamedEntry +{ + [InspectableField, JsonProperty("name"), Key(1)] + public string Name; + + [InspectableDatabaseLink(typeof(HullData)), JsonProperty("hull"), Key(2)] + public Guid Hull; + + [JsonProperty("items"), Key(3)] + public List Gear = new List(); + + [InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("simpleCargo"), Key(4)] + public Dictionary SimpleCargo = new Dictionary(); + + [InspectableDatabaseLink(typeof(CraftedItemData)), JsonProperty("compoundCargo"), Key(5)] + public Dictionary CompoundCargo = new Dictionary(); + + [IgnoreMember] public string EntryName + { + get => Name; + set => Name = value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/LoadoutData.cs.meta b/Assets/Scripts/ServerShared/LoadoutData.cs.meta new file mode 100644 index 000000000..1573b4757 --- /dev/null +++ b/Assets/Scripts/ServerShared/LoadoutData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 897e13bb0462456b800522cd213bf70d +timeCreated: 1591829121 \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/PlayerData.cs b/Assets/Scripts/ServerShared/PlayerData.cs new file mode 100644 index 000000000..9d0afb80c --- /dev/null +++ b/Assets/Scripts/ServerShared/PlayerData.cs @@ -0,0 +1,25 @@ +using System; +using MessagePack; +using Newtonsoft.Json; + +[RethinkTable("Users"), MessagePackObject, JsonObject(MemberSerialization.OptIn)] +public class PlayerData : DatabaseEntry, INamedEntry +{ + [JsonProperty("email"), Key(1)] + public string Email; + + [JsonProperty("password"), Key(2)] + public string Password; + + [JsonProperty("username"), Key(3)] + public string Username; + + [JsonProperty("corporation"), Key(4)] + public Guid Corporation; + + [IgnoreMember] public string EntryName + { + get => Username; + set => Username = value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/PlayerData.cs.meta b/Assets/Scripts/ServerShared/PlayerData.cs.meta new file mode 100644 index 000000000..c4469f21b --- /dev/null +++ b/Assets/Scripts/ServerShared/PlayerData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6daac48880264dcc91c928f0dd9c2abb +timeCreated: 1591829144 \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Ship.cs b/Assets/Scripts/ServerShared/Ship.cs index 703715223..3b8ca2349 100644 --- a/Assets/Scripts/ServerShared/Ship.cs +++ b/Assets/Scripts/ServerShared/Ship.cs @@ -21,113 +21,10 @@ public class Ship : Entity { } - // public Gear GetEquipped(HardpointType type) - // { - // return Hardpoints.FirstOrDefault(hp => hp.HardpointData.Type == type)?.Item; - // } - // - // public T GetEquipped() where T : EquippableItemData - // { - // var data = Hardpoints.FirstOrDefault(hp => Context.GetData(hp.Item) is T); - // if (data != null) - // return Context.GetData(data.Item) as T; - // return null; - // } - // - // public void Hydrate() - // { - // GenerateBehaviors(); - // - // //HullHardpointCount = Hardpoints.Count(hp => hp.HardpointData.Type == HardpointType.Hull); - // } - // - // private void GenerateBehaviors() - // { - // } - - // public void GenerateBindings() - // { - // Bindings = new Dictionary(); - // - // var bindables = - // ItemBindings.Select(id => new {id=id.Key, eq = id.Value.First().Hardpoint.Item.ItemData}).ToList(); - // - // var weapons = bindables.Where(i => i.eq.HardpointType.IsWeapon()).ToArray(); - // - // var mouseButtons = Enumerable.Range((int) KeyCode.Mouse0, 3).Cast(); - // foreach (var x in weapons.Zip(mouseButtons, (binding, key) => new {binding,key})) - // { - // Bindings.Add(x.key, x.binding.id); - // bindables.Remove(x.binding); - // } - // - // var thruster = bindables.FirstOrDefault(x => x.eq.HardpointType == HardpointType.Thruster); - // if (thruster != null) - // { - // Bindings.Add(KeyCode.LeftShift, thruster.id); - // bindables.Remove(thruster); - // } - // - // var utility = bindables.FirstOrDefault(x => !x.eq.HardpointType.IsWeapon()); - // if (utility != null) - // { - // Bindings.Add(KeyCode.Space, utility.id); - // bindables.Remove(utility); - // } - // - // var numKeys = Enumerable.Range((int) KeyCode.Alpha1, 9).Cast(); - // foreach (var x in bindables.Zip(numKeys, (binding, key) => new {binding,key})) - // { - // Bindings.Add(x.key, x.binding.id); - // } - // - // } - - // public void Activate(KeyCode binding) - // { - // if (Bindings.ContainsKey(binding)) - // foreach (var behavior in ItemBindings[Bindings[binding]]) - // { - // behavior.Activate(); - // if(behavior.Hardpoint.ActionBarButton!=null) - // behavior.Hardpoint.ActionBarButton.Background.color = Color.yellow; - // } - // } - // - // public void Deactivate(KeyCode binding) - // { - // if(Bindings.ContainsKey(binding)) - // foreach (var behavior in ItemBindings[Bindings[binding]]) - // { - // behavior.Deactivate(); - // if(behavior.Hardpoint.ActionBarButton!=null) - // behavior.Hardpoint.ActionBarButton.Background.color = GlobalData.Instance.UnselectedElementColor; - // } - // } - public override void Update(float delta) { Position += Velocity * delta; base.Update(delta); - // foreach (var kvp in Contacts.ToArray()) - // if (kvp.Key == null || Time.time - kvp.Value > GlobalData.Instance.TargetPersistenceDuration) - // { - // Contacts.Remove(kvp.Key); - // if (kvp.Key == Target) - // Target = null; - // } } - - // public void UpdateInput(float delta) - // { - // foreach (var key in Bindings.Keys) - // { - // if(Input.GetKeyDown(key)) - // Activate(key); - // if(Input.GetKeyUp(key)) - // Deactivate(key); - // } - // - // } } diff --git a/Assets/Scripts/StrategyGameManager.cs b/Assets/Scripts/StrategyGameManager.cs index ce2c14b93..376f24a64 100644 --- a/Assets/Scripts/StrategyGameManager.cs +++ b/Assets/Scripts/StrategyGameManager.cs @@ -142,10 +142,10 @@ public class StrategyGameManager : MonoBehaviour _context.PlaceMegas(); } - var player = _cache.GetAll().FirstOrDefault(); + var player = _cache.GetAll().FirstOrDefault(); if (player == null) { - player = new Player + player = new PlayerData { Context = _context, Username = Environment.UserName diff --git a/Assets/Scripts/UI/ColonyTab.cs b/Assets/Scripts/UI/ColonyTab.cs index 90ef8adab..9583779c5 100644 --- a/Assets/Scripts/UI/ColonyTab.cs +++ b/Assets/Scripts/UI/ColonyTab.cs @@ -140,6 +140,7 @@ public class ColonyTab : MonoBehaviour if (child) { panel.Title.text = entity.Name; + panel.AddField("Active", () => entity.Active, active => entity.Active = active); panel.AddSection("General"); panel.AddEntityProperties(entity); } @@ -303,8 +304,17 @@ public class ColonyTab : MonoBehaviour } else if (data.clickCount == 2 && item is Gear gear) { - // Equip Item - entity.Equip(gear.ID, true); + // Item is a hull, create a ship entity and make it a child + if (gear.ItemData is HullData) + { + entity.RemoveCargo(gear); + var ship = new Ship(Context, gear.ID, Enumerable.Empty(), Enumerable.Empty(), entity.Zone, entity.Corporation); + ship.Name = gear.Name; + _context.Cache.Add(ship); + _context.SetParent(ship, entity); + } + else // Equip Item + entity.Equip(gear.ID, true); } } }; @@ -341,7 +351,7 @@ public class ColonyTab : MonoBehaviour } else { - var instanceList = panel.AddList(group.Key.Name); + var instanceList = panel.AddList($"{group.Count().ToString()} {group.Key.Name}"); foreach (var item in group) { var button = instanceList.AddProperty(item.Name, null, eventData => onClick(item, eventData), true).Button; diff --git a/Assets/Scripts/UI/PropertiesPanel.cs b/Assets/Scripts/UI/PropertiesPanel.cs index df9871534..4835b4ca5 100644 --- a/Assets/Scripts/UI/PropertiesPanel.cs +++ b/Assets/Scripts/UI/PropertiesPanel.cs @@ -440,6 +440,7 @@ public class PropertiesPanel : MonoBehaviour public void AddEntityProperties(Entity entity) { + AddField("Name", () => entity.Name, name => entity.Name = name); AddProperty("Capacity", () => $"{entity.OccupiedCapacity}/{entity.Capacity:0}"); AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GlobalData.SignificantDigits)}"); AddProperty("Temperature", () => $"{entity.Temperature:0}°K"); @@ -508,6 +509,7 @@ public class PropertiesPanel : MonoBehaviour void InspectChildrenInternal() { + Clear(); foreach (var child in entity.Children) { var childEntity = Context.Cache.Get(child); diff --git a/Economy.Shared.Unity.csproj b/Economy.Shared.Unity.csproj index c509fa977..433eaf93b 100644 --- a/Economy.Shared.Unity.csproj +++ b/Economy.Shared.Unity.csproj @@ -107,7 +107,7 @@ - + @@ -117,6 +117,7 @@ + @@ -507,6 +508,7 @@ +