diff --git a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml index 4d1d47022..b9b4754f5 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml @@ -1282,6 +1282,7 @@ + diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 151cba81c..dff8a9e10 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -8351,7 +8351,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1082785902} m_Direction: 0 m_Value: 0 - m_Size: 1 + m_Size: 0.99999994 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -24596,8 +24596,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 943.50006, y: 0} - m_SizeDelta: {x: 1887.0001, y: 0} + m_AnchoredPosition: {x: 943.5, y: 0} + m_SizeDelta: {x: 1887, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1101630447 MonoBehaviour: diff --git a/Assets/Scripts/Editor/DatabaseInspector.cs b/Assets/Scripts/Editor/DatabaseInspector.cs index ed6f12ccb..ffeb476ba 100644 --- a/Assets/Scripts/Editor/DatabaseInspector.cs +++ b/Assets/Scripts/Editor/DatabaseInspector.cs @@ -642,6 +642,12 @@ public class DatabaseInspector : EditorWindow using (var h = new HorizontalScope(_list.ListItemStyle)) { var entry = DatabaseCache.Get(ingredient.Key); + if (entry == null) + { + value.Remove(ingredient.Key); + GUI.changed = true; + return; + } if(entry is INamedEntry named) GUILayout.Label(named.EntryName); else GUILayout.Label(entry.ID.ToString()); diff --git a/Assets/Scripts/ServerShared/Agents/AgentTask.cs b/Assets/Scripts/ServerShared/Agents/AgentTask.cs index cdb83ca5c..0fc930e53 100644 --- a/Assets/Scripts/ServerShared/Agents/AgentTask.cs +++ b/Assets/Scripts/ServerShared/Agents/AgentTask.cs @@ -1,10 +1,13 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; public abstract class AgentTask { - + public abstract AgentJob JobType { get; } + public int Priority; + public Guid Zone; } public enum AgentJob @@ -13,5 +16,6 @@ public enum AgentJob Haul, Tow, Defend, - Attack + Attack, + Explore } diff --git a/Assets/Scripts/ServerShared/Agents/StationTowing.cs b/Assets/Scripts/ServerShared/Agents/StationTowing.cs new file mode 100644 index 000000000..d4fc5d707 --- /dev/null +++ b/Assets/Scripts/ServerShared/Agents/StationTowing.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class StationTowing : AgentTask +{ + public override AgentJob JobType => AgentJob.Tow; + + private Guid _entity; + private Guid _targetOrbit; + + public StationTowing(Guid zone, Guid entity, Guid targetOrbit) + { + Zone = zone; + _entity = entity; + _targetOrbit = targetOrbit; + } +} diff --git a/Assets/Scripts/ServerShared/Agents/StationTowing.cs.meta b/Assets/Scripts/ServerShared/Agents/StationTowing.cs.meta new file mode 100644 index 000000000..2b97242c4 --- /dev/null +++ b/Assets/Scripts/ServerShared/Agents/StationTowing.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8845fb5e89a4bf46abdf94517139172 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index cb610b272..8d63329b4 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -3,31 +3,37 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; +using JsonKnownTypes; +using MessagePack; +using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -public class Entity +[MessagePackObject, + JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter))] +public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver { - public Dictionary AxisOverrides = new Dictionary(); - public readonly Dictionary VisibilitySources = new Dictionary(); + [IgnoreMember] public Dictionary AxisOverrides = new Dictionary(); + [IgnoreMember] public readonly Dictionary VisibilitySources = new Dictionary(); public float Temperature; public float Energy; public float2 Position; public float2 Direction = float2(0,1); public float2 Velocity; - public Dictionary> Bindings; - public Dictionary Axes; - public readonly GameContext Context; + [IgnoreMember] public Dictionary> Bindings; + [IgnoreMember] public Dictionary Axes; public readonly List Cargo; public readonly List EquippedItems; - protected readonly List Behaviors; + [IgnoreMember] protected List Behaviors; public Gear Hull { get; } - public float Mass { get; private set; } - public float SpecificHeat { get; private set; } - public float Visibility => VisibilitySources.Values.Sum(); + [IgnoreMember] public float Mass { get; private set; } + [IgnoreMember] public float SpecificHeat { get; private set; } + [IgnoreMember] public float Visibility => VisibilitySources.Values.Sum(); + + public object[] PersistedBehaviors; public Entity(GameContext context, Gear hull, IEnumerable items, IEnumerable cargo) { @@ -103,4 +109,39 @@ public class Entity foreach (var item in EquippedItems.Where(item => item.ItemData.Performance(Temperature) < .01f)) item.Durability -= delta; } + + public void OnBeforeSerialize() + { + PersistedBehaviors = Behaviors + .Where(b => b is IPersistentBehavior) + .Cast() + .Select(b => b.Store()).ToArray(); + } + + public void OnAfterDeserialize() + { + RecalculateMass(); + + var activeItems = Hull == null ? EquippedItems : EquippedItems.Append(Hull); + + Behaviors = activeItems + .Where(i=>i.ItemData.Behaviors?.Any()??false) + .SelectMany(i => i.ItemData.Behaviors + .Select(bd => bd.CreateInstance(Context, this, i))) + .OrderBy(b => b.GetType().GetCustomAttribute()?.Order ?? 0).ToList(); + + Bindings = Behaviors + .Where(b => b is IActivatedBehavior) + .GroupBy(b => b.Item.ID, (guid, behaviors) => new {guid, behaviors}) + .ToDictionary(g => g.guid, g => g.behaviors.Cast().ToList()); + + Axes = Behaviors + .Where(b => b is IAnalogBehavior) + .ToDictionary(b => b as IAnalogBehavior, b => 0f); + + foreach (var behavior in Behaviors) + { + behavior.Initialize(); + } + } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index ead467c67..4ce69d5a4 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -14,20 +14,20 @@ using Unity.Mathematics; JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter))] public abstract class ItemData : DatabaseEntry, INamedEntry { - [InspectableField, JsonProperty("name"), Key(1)] + [InspectableField, JsonProperty("name"), Key(1)] public string Name; - [InspectableText, JsonProperty("description"), Key(2)] + [InspectableText, JsonProperty("description"), Key(2)] public string Description; - [InspectableField, JsonProperty("mass"), Key(3)] + [InspectableField, JsonProperty("mass"), Key(3)] public float Mass; - [InspectableField, JsonProperty("size"), Key(4)] + [InspectableField, JsonProperty("size"), Key(4)] public float Size; // Heat needed to change temperature of 1 gram by 1 degree - [InspectableField, JsonProperty("specificHeat"), Key(5)] + [InspectableField, JsonProperty("specificHeat"), Key(5)] public float SpecificHeat; [IgnoreMember] public string EntryName @@ -75,25 +75,25 @@ public class CompoundCommodityData : CraftedItemData {} JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter))] public abstract class EquippableItemData : CraftedItemData { - [InspectableField, JsonProperty("draw"), Key(6)] + [InspectableField, JsonProperty("draw"), Key(6)] public PerformanceStat EnergyDraw = new PerformanceStat(); - [InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)] + [InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)] public float4[] HeatPerformanceCurve; - [TemperatureInspectable, JsonProperty("minTemp"), Key(8)] + [TemperatureInspectable, JsonProperty("minTemp"), Key(8)] public float MinimumTemperature; - [TemperatureInspectable, JsonProperty("maxTemp"), Key(9)] + [TemperatureInspectable, JsonProperty("maxTemp"), Key(9)] public float MaximumTemperature; - [InspectableField, JsonProperty("durabilityStat"), Key(10)] + [InspectableField, JsonProperty("durabilityStat"), Key(10)] public PerformanceStat Durability = new PerformanceStat(); - [InspectableField, JsonProperty("durabilityExponent"), Key(11)] + [InspectableField, JsonProperty("durabilityExponent"), Key(11)] public PerformanceStat DurabilityExponent = new PerformanceStat(); - [InspectableField, JsonProperty("heatExponent"), Key(12)] + [InspectableField, JsonProperty("heatExponent"), Key(12)] public PerformanceStat HeatExponent = new PerformanceStat(); [InspectableField, JsonProperty("behaviors"), Key(13)] diff --git a/Assets/Scripts/StrategyGameManager.cs b/Assets/Scripts/StrategyGameManager.cs index e12356df1..09edbc40a 100644 --- a/Assets/Scripts/StrategyGameManager.cs +++ b/Assets/Scripts/StrategyGameManager.cs @@ -126,9 +126,12 @@ public class StrategyGameManager : MonoBehaviour if (_currentTab == ZoneTabButton) { - if (_populatedZone != _selectedZone && _cache.Get(_selectedZone) != null) + var zone = _cache.Get(_selectedZone); + if (_populatedZone != _selectedZone && zone != null) PopulateZone(); Camera.transform.position = -Vector3.forward; + if (zone != null) + Camera.orthographicSize = zone.Radius * ZoneSizeScale; } if (_currentTab == TechTabButton) diff --git a/Economy.Shared.Unity.csproj b/Economy.Shared.Unity.csproj index e0977aec9..6c4b6f9d4 100644 --- a/Economy.Shared.Unity.csproj +++ b/Economy.Shared.Unity.csproj @@ -66,6 +66,7 @@ +