diff --git a/Assets/Resources/Elysium.asset b/Assets/Resources/Elysium.asset index a0b0a5cd0..f53b5b69b 100644 --- a/Assets/Resources/Elysium.asset +++ b/Assets/Resources/Elysium.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7307338a03d4a6e6c7deb40795b9102c79160d498b25b4bfca94cc64fe866b23 -size 17581 +oid sha256:30c451432161fff5c202ce8217149ad255f4f3a66cd71aec2ce8722dd3f6d310 +size 7770 diff --git a/Assets/Resources/Test Galaxy.asset b/Assets/Resources/Test Galaxy.asset index cfbc229f9..f196e29f7 100644 --- a/Assets/Resources/Test Galaxy.asset +++ b/Assets/Resources/Test Galaxy.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:707784bc14567850c6f44adf99d2d802c050d0214a95c7941e64daca771a5b1d -size 16811 +oid sha256:5a3b71fa9248f9b9339a7a69762264af697a0df5983825fbe4540a1a5eac8180 +size 7774 diff --git a/Assets/Resources/Test Galaxy.asset.meta b/Assets/Resources/Test Galaxy.asset.meta index 9c51f200b..1d0fc56f2 100644 --- a/Assets/Resources/Test Galaxy.asset.meta +++ b/Assets/Resources/Test Galaxy.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ee668592f6b83e941906711e854fa7ae +guid: 70345ecc9f78fcb47b1f6f5afed2681a NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 6a63fdadf..4741d5022 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -7880,7 +7880,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 435654366} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 0ae6f9307731b8f469a018c69d95d2ba, type: 3} m_Name: @@ -21734,7 +21734,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1126386499} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 1c1faf0a46b9cf24498cd5ec93c34c71, type: 3} m_Name: @@ -21749,6 +21749,8 @@ MonoBehaviour: GalaxyScale: 100 ZoneObjectPrefab: {fileID: 5321404118521994133, guid: f9521191d31952a42a76632d158de0d3, type: 3} + BeltPrefab: {fileID: 3696484618621710612, guid: de2171f0e78642f48ac4cb15f3c012c5, + type: 3} ZoneRoot: {fileID: 435654367} PlanetSprite: {fileID: 2800000, guid: 0d2acbd593b7fd349b0b26b4844733ef, type: 3} GasGiantSprite: {fileID: 2800000, guid: 39505115515c61f4db3c5c5397a5ba49, type: 3} @@ -21757,9 +21759,9 @@ MonoBehaviour: WormholeSprite: {fileID: 2800000, guid: 6d0b27330fdcc8347b1e09a2d17a0673, type: 3} SelectedColor: {r: 1, g: 0.44583336, b: 0.050000012, a: 1} UnselectedColor: {r: 0.20084397, g: 0.5982815, b: 0.797, a: 1} - ZoneSizeScale: 0.01 - ZoneMassScale: 0.5 - ZoneMassPower: 0.333 + ZoneSizeScale: 0.02 + ZoneMassScale: 10 + ZoneMassPower: 0.25 ZoneBackground: {fileID: 1956833085} ZoneBoundary: {fileID: 548600404} --- !u!4 &1126386501 diff --git a/Assets/Scripts/Editor/GalaxyEditor.cs b/Assets/Scripts/Editor/GalaxyEditor.cs index e8b29a325..f912a3049 100644 --- a/Assets/Scripts/Editor/GalaxyEditor.cs +++ b/Assets/Scripts/Editor/GalaxyEditor.cs @@ -122,6 +122,10 @@ public class GalaxyEditor : Editor { _currentLayer = resourceDensity; } + if (GUILayout.Button("Copy")) + { + galaxy.MapData.ResourceDensities.Add(resourceDensity.Copy()); + } EndHorizontal(); } EditorGUI.indentLevel--; diff --git a/Assets/Scripts/ServerShared/Extensions.cs b/Assets/Scripts/ServerShared/Extensions.cs index 590b4de17..8881887bb 100644 --- a/Assets/Scripts/ServerShared/Extensions.cs +++ b/Assets/Scripts/ServerShared/Extensions.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text.RegularExpressions; using LiteNetLib; using MessagePack; @@ -217,3 +218,124 @@ public static class Extensions return t * (t * (a * t + b) + c) + d; } } + +// https://github.com/Burtsev-Alexey/net-object-deep-copy +public static class ObjectExtensions +{ + private static readonly MethodInfo CloneMethod = typeof(Object).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance); + + public static bool IsPrimitive(this Type type) + { + if (type == typeof(String)) return true; + return (type.IsValueType & type.IsPrimitive); + } + + public static Object Copy(this Object originalObject) + { + return InternalCopy(originalObject, new Dictionary(new ReferenceEqualityComparer())); + } + private static Object InternalCopy(Object originalObject, IDictionary visited) + { + if (originalObject == null) return null; + var typeToReflect = originalObject.GetType(); + if (IsPrimitive(typeToReflect)) return originalObject; + if (visited.ContainsKey(originalObject)) return visited[originalObject]; + if (typeof(Delegate).IsAssignableFrom(typeToReflect)) return null; + var cloneObject = CloneMethod.Invoke(originalObject, null); + if (typeToReflect.IsArray) + { + var arrayType = typeToReflect.GetElementType(); + if (IsPrimitive(arrayType) == false) + { + Array clonedArray = (Array)cloneObject; + clonedArray.ForEach((array, indices) => array.SetValue(InternalCopy(clonedArray.GetValue(indices), visited), indices)); + } + + } + visited.Add(originalObject, cloneObject); + CopyFields(originalObject, visited, cloneObject, typeToReflect); + RecursiveCopyBaseTypePrivateFields(originalObject, visited, cloneObject, typeToReflect); + return cloneObject; + } + + private static void RecursiveCopyBaseTypePrivateFields(object originalObject, IDictionary visited, object cloneObject, Type typeToReflect) + { + if (typeToReflect.BaseType != null) + { + RecursiveCopyBaseTypePrivateFields(originalObject, visited, cloneObject, typeToReflect.BaseType); + CopyFields(originalObject, visited, cloneObject, typeToReflect.BaseType, BindingFlags.Instance | BindingFlags.NonPublic, info => info.IsPrivate); + } + } + + private static void CopyFields(object originalObject, IDictionary visited, object cloneObject, Type typeToReflect, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy, Func filter = null) + { + foreach (FieldInfo fieldInfo in typeToReflect.GetFields(bindingFlags)) + { + if (filter != null && filter(fieldInfo) == false) continue; + if (IsPrimitive(fieldInfo.FieldType)) continue; + var originalFieldValue = fieldInfo.GetValue(originalObject); + var clonedFieldValue = InternalCopy(originalFieldValue, visited); + fieldInfo.SetValue(cloneObject, clonedFieldValue); + } + } + public static T Copy(this T original) + { + return (T)Copy((Object)original); + } +} + +public class ReferenceEqualityComparer : EqualityComparer +{ + public override bool Equals(object x, object y) + { + return ReferenceEquals(x, y); + } + public override int GetHashCode(object obj) + { + if (obj == null) return 0; + return obj.GetHashCode(); + } +} +public static class ArrayExtensions +{ + public static void ForEach(this Array array, Action action) + { + if (array.LongLength == 0) return; + ArrayTraverse walker = new ArrayTraverse(array); + do action(array, walker.Position); + while (walker.Step()); + } +} + +internal class ArrayTraverse +{ + public int[] Position; + private int[] maxLengths; + + public ArrayTraverse(Array array) + { + maxLengths = new int[array.Rank]; + for (int i = 0; i < array.Rank; ++i) + { + maxLengths[i] = array.GetLength(i) - 1; + } + Position = new int[array.Rank]; + } + + public bool Step() + { + for (int i = 0; i < Position.Length; ++i) + { + if (Position[i] < maxLengths[i]) + { + Position[i]++; + for (int j = 0; j < i; j++) + { + Position[j] = 0; + } + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/GlobalData.cs b/Assets/Scripts/ServerShared/GlobalData.cs index bd4821d22..847be4f3b 100644 --- a/Assets/Scripts/ServerShared/GlobalData.cs +++ b/Assets/Scripts/ServerShared/GlobalData.cs @@ -89,12 +89,15 @@ public class GlobalData : DatabaseEntry [InspectableField] [JsonProperty("beltProbability")] [Key(25)] public float BeltProbability = .05f; - [InspectableField] [JsonProperty("beltMassCeiling")] [Key(25)] + [InspectableField] [JsonProperty("beltMassCeiling")] [Key(26)] public float BeltMassCeiling = 500f; - [InspectableField] [JsonProperty("beltMassRatio")] [Key(26)] + [InspectableField] [JsonProperty("beltMassRatio")] [Key(27)] public float BeltMassRatio = 100f; + [InspectableField] [JsonProperty("beltMassExponent")] [Key(28)] + public float BeltMassExponent = 100f; + public float PlanetRadius(float mass) { return pow(mass, 1 / RadiusPower); diff --git a/Assets/Scripts/ServerShared/ZoneGenerator.cs b/Assets/Scripts/ServerShared/ZoneGenerator.cs index 35d7a42bb..8584511cd 100644 --- a/Assets/Scripts/ServerShared/ZoneGenerator.cs +++ b/Assets/Scripts/ServerShared/ZoneGenerator.cs @@ -176,8 +176,8 @@ public class ZoneGenerator var beltCandidates = rosette ? root.AllPlanets().Where(p => p != root && p.Parent != root && p.Mass < global.BeltMassCeiling && !binaries.Contains(p)) : root.AllPlanets().Where(p => p != root && p.Mass < global.BeltMassCeiling && !binaries.Contains(p)); - foreach(var planet in beltCandidates) - if (random.NextFloat() < global.BeltProbability) + foreach(var planet in beltCandidates.Reverse()) + if (random.NextFloat() < global.BeltProbability && !planet.Parent.Children.Any(p=>p.Belt)) planet.Belt = true; return root.AllPlanets().ToArray(); diff --git a/Assets/Scripts/StrategyGameManager.cs b/Assets/Scripts/StrategyGameManager.cs index e4c726e57..49ed7ae93 100644 --- a/Assets/Scripts/StrategyGameManager.cs +++ b/Assets/Scripts/StrategyGameManager.cs @@ -18,6 +18,7 @@ public class StrategyGameManager : MonoBehaviour public MeshRenderer GalaxyBackground; public float GalaxyScale; public ZoneObject ZoneObjectPrefab; + public ParticleSystem BeltPrefab; public Transform ZoneRoot; public Texture2D PlanetSprite; public Texture2D GasGiantSprite; @@ -42,7 +43,9 @@ public class StrategyGameManager : MonoBehaviour private GalaxyZone _selectedGalaxyZone; private ZoneResponseMessage _zoneResponse; private Dictionary _galaxyResponseZones; + private Dictionary _galaxyZoneObjects = new Dictionary(); private Dictionary _zoneObjects = new Dictionary(); + private Dictionary _zoneBelts = new Dictionary(); private List _wormholes = new List(); private Dictionary _orbitPositions = new Dictionary(); private Vector3 _galaxyCameraPos = -Vector3.forward; @@ -117,6 +120,13 @@ public class StrategyGameManager : MonoBehaviour planet.Value.transform.position = (Vector2) GetOrbitPosition(planetData.Orbit) * ZoneSizeScale; } + + foreach (var belt in _zoneBelts) + { + var planetData = _cache.Get(belt.Key); + + belt.Value.transform.position = float3(GetOrbitPosition(_cache.Get(planetData.Orbit).Parent) * ZoneSizeScale, .15f); + } } } @@ -175,6 +185,7 @@ public class StrategyGameManager : MonoBehaviour var instance = GalaxyZonePrototype.Instantiate(); instance.position = float3((Vector2) zone.Position - Vector2.one * .5f,0) * GalaxyScale; var instanceZone = instance.GetComponent(); + _galaxyZoneObjects[zone.ZoneID] = instanceZone; instanceZone.Label.text = zone.Name; instanceZone.Background.GetComponent().OnClick += (_, pointer) => { @@ -208,6 +219,8 @@ public class StrategyGameManager : MonoBehaviour _zoneObjects.Clear(); foreach (var zoneObject in _wormholes) Destroy(zoneObject.gameObject); //zoneObject.GetComponent().ReturnToPool(); _wormholes.Clear(); + foreach (var belt in _zoneBelts.Values) Destroy(belt.gameObject); + _zoneBelts.Clear(); _populatedZone = _selectedZone; @@ -216,21 +229,42 @@ public class StrategyGameManager : MonoBehaviour { if (entry is PlanetData planet) { - var planetObject = Instantiate(ZoneObjectPrefab, ZoneRoot); - _zoneObjects[planet.ID] = planetObject; - planetObject.Label.text = planet.Name; - planetObject.GravityMesh.gameObject.SetActive(true); - planetObject.GravityMesh.transform.localScale = - Vector3.one * (pow(planet.Mass, _context.GlobalData.GravityRadiusExponent) * - _context.GlobalData.GravityRadiusMultiplier * ZoneSizeScale); - var depth = pow(planet.Mass, ZoneMassPower) * ZoneMassScale; - if (depth > zoneDepth) - zoneDepth = depth; - planetObject.GravityMesh.material.SetFloat("_Depth", depth); - planetObject.Icon.material.SetTexture("_MainTex", - planet.Mass > _context.GlobalData.SunMass ? SunSprite : - planet.Mass > _context.GlobalData.GasGiantMass ? GasGiantSprite : - PlanetSprite); + if (!planet.Belt) + { + var planetObject = Instantiate(ZoneObjectPrefab, ZoneRoot); + _zoneObjects[planet.ID] = planetObject; + planetObject.Label.text = planet.Name; + planetObject.GravityMesh.gameObject.SetActive(true); + planetObject.GravityMesh.transform.localScale = + Vector3.one * (pow(planet.Mass, _context.GlobalData.GravityRadiusExponent) * + _context.GlobalData.GravityRadiusMultiplier * 2 * ZoneSizeScale); + var depth = pow(planet.Mass, ZoneMassPower) * ZoneMassScale; + if (depth > zoneDepth) + zoneDepth = depth; + planetObject.GravityMesh.material.SetFloat("_Depth", depth); + planetObject.Icon.material.SetTexture("_MainTex", + planet.Mass > _context.GlobalData.SunMass ? SunSprite : + planet.Mass > _context.GlobalData.GasGiantMass ? GasGiantSprite : + PlanetSprite); + } + else + { + var beltObject = Instantiate(BeltPrefab, transform); + _zoneBelts[planet.ID] = beltObject; + var orbit = _cache.Get(planet.Orbit); + var beltEmission = beltObject.emission; + beltEmission.rateOverTime = + new ParticleSystem.MinMaxCurve( + pow(planet.Mass,_context.GlobalData.BeltMassExponent) + / _context.GlobalData.BeltMassRatio * orbit.Distance); + var beltShape = beltObject.shape; + beltShape.radius = orbit.Distance * ZoneSizeScale; + beltShape.donutRadius = orbit.Distance * ZoneSizeScale / 2; + var beltVelocity = beltObject.velocityOverLifetime; + beltVelocity.orbitalZ = orbit.Distance * ZoneSizeScale / orbit.Period; + beltObject.Simulate(60); + beltObject.Play(); + } } } var radius = (_zoneResponse.Zone.Radius * ZoneSizeScale * 2); @@ -248,6 +282,20 @@ public class StrategyGameManager : MonoBehaviour wormholeObject.GravityMesh.gameObject.SetActive(false); wormholeObject.Icon.material.SetTexture("_MainTex", WormholeSprite); wormholeObject.Label.text = otherZone.Name; + wormholeObject.Icon.GetComponent().OnClick += (_, pointer) => + { + // If the user double clicks on a wormhole, switch to that zone + if (pointer.clickCount == 2) + { + _selectedGalaxyZone.Background.material.SetColor("_TintColor", UnselectedColor); + if(_selectedZone != wormhole) + CultClient.Send(new ZoneRequestMessage{ZoneID = wormhole}); + _selectedZone = wormhole; + _selectedGalaxyZone = _galaxyZoneObjects[wormhole]; + _selectedGalaxyZone.Background.material.SetColor("_TintColor", SelectedColor); + + } + }; } } } diff --git a/Assets/Scripts/ZoneGeneratorTest.cs b/Assets/Scripts/ZoneGeneratorTest.cs index 5a0ceb9d6..8800c3915 100644 --- a/Assets/Scripts/ZoneGeneratorTest.cs +++ b/Assets/Scripts/ZoneGeneratorTest.cs @@ -75,7 +75,7 @@ public class ZoneGeneratorTest : MonoBehaviour { var planetData = _cache.Get(belt.Key); - belt.Value.transform.position = (Vector2) GetOrbitPosition(_cache.Get(planetData.Orbit).Parent) * ZoneSizeScale; + belt.Value.transform.position = float3(GetOrbitPosition(_cache.Get(planetData.Orbit).Parent) * ZoneSizeScale, .15f); } if (Input.GetKeyDown(KeyCode.Space)) { @@ -140,12 +140,14 @@ public class ZoneGeneratorTest : MonoBehaviour _zoneBelts[planet.ID] = beltObject; var orbit = _cache.Get(planet.Orbit); var beltEmission = beltObject.emission; - beltEmission.rateOverTime = new ParticleSystem.MinMaxCurve(planet.Mass / Galaxy.MapData.GlobalData.BeltMassRatio * orbit.Distance); + beltEmission.rateOverTime = new ParticleSystem.MinMaxCurve(pow(planet.Mass,Galaxy.MapData.GlobalData.BeltMassExponent) / Galaxy.MapData.GlobalData.BeltMassRatio * orbit.Distance); var beltShape = beltObject.shape; beltShape.radius = orbit.Distance * ZoneSizeScale; beltShape.donutRadius = orbit.Distance * ZoneSizeScale / 2; var beltVelocity = beltObject.velocityOverLifetime; - beltVelocity.orbitalZ = orbit.Distance * ZoneSizeScale * PI / orbit.Period * ZoneOrbitSpeed; + beltVelocity.orbitalZ = orbit.Distance * ZoneSizeScale / orbit.Period * ZoneOrbitSpeed; + beltObject.Simulate(60); + beltObject.Play(); } } diff --git a/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Server.dll b/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Server.dll index 101733837..250f89358 100644 --- a/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Server.dll +++ b/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Server.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:36b135848d9adc1b16c5558ddde765953a2a5855c003529f9a9300739b4563ce -size 30208 +oid sha256:55362430e15cdc89c54b9cd50fbfa54e286a1cedc5f81dbd05a8d309c1c83f48 +size 28672 diff --git a/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Shared.dll b/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Shared.dll index 7d245bf64..037b6e0de 100644 --- a/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Shared.dll +++ b/Economy.Server/bin/Debug/netcoreapp3.1/Economy.Shared.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2c12be4c0222ec2371a7772c208056fd4543f940240fc85d0b4ae38c2a73530 -size 1391104 +oid sha256:85174ebd9f2cf8d1d598bf287911aa15b1cdaca148a0a107a336a2118847ea63 +size 1397248 diff --git a/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.csprojAssemblyReference.cache b/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.csprojAssemblyReference.cache index 9cdb8e63f..32b2ddc17 100644 Binary files a/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.csprojAssemblyReference.cache and b/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.csprojAssemblyReference.cache differ diff --git a/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.dll b/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.dll index 101733837..250f89358 100644 --- a/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.dll +++ b/Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:36b135848d9adc1b16c5558ddde765953a2a5855c003529f9a9300739b4563ce -size 30208 +oid sha256:55362430e15cdc89c54b9cd50fbfa54e286a1cedc5f81dbd05a8d309c1c83f48 +size 28672 diff --git a/Economy.Shared/bin/Debug/netstandard2.0/Economy.Shared.dll b/Economy.Shared/bin/Debug/netstandard2.0/Economy.Shared.dll index 7d245bf64..037b6e0de 100644 --- a/Economy.Shared/bin/Debug/netstandard2.0/Economy.Shared.dll +++ b/Economy.Shared/bin/Debug/netstandard2.0/Economy.Shared.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2c12be4c0222ec2371a7772c208056fd4543f940240fc85d0b4ae38c2a73530 -size 1391104 +oid sha256:85174ebd9f2cf8d1d598bf287911aa15b1cdaca148a0a107a336a2118847ea63 +size 1397248 diff --git a/Economy.Shared/obj/Debug/netstandard2.0/Economy.Shared.dll b/Economy.Shared/obj/Debug/netstandard2.0/Economy.Shared.dll index 7d245bf64..037b6e0de 100644 --- a/Economy.Shared/obj/Debug/netstandard2.0/Economy.Shared.dll +++ b/Economy.Shared/obj/Debug/netstandard2.0/Economy.Shared.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2c12be4c0222ec2371a7772c208056fd4543f940240fc85d0b4ae38c2a73530 -size 1391104 +oid sha256:85174ebd9f2cf8d1d598bf287911aa15b1cdaca148a0a107a336a2118847ea63 +size 1397248