Better Zones Client/Server
This commit is contained in:
parent
b0556d3900
commit
4b8a300c0a
16 changed files with 223 additions and 42 deletions
BIN
Assets/Resources/Elysium.asset
(Stored with Git LFS)
BIN
Assets/Resources/Elysium.asset
(Stored with Git LFS)
Binary file not shown.
BIN
Assets/Resources/Test Galaxy.asset
(Stored with Git LFS)
BIN
Assets/Resources/Test Galaxy.asset
(Stored with Git LFS)
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee668592f6b83e941906711e854fa7ae
|
||||
guid: 70345ecc9f78fcb47b1f6f5afed2681a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -122,6 +122,10 @@ public class GalaxyEditor : Editor
|
|||
{
|
||||
_currentLayer = resourceDensity;
|
||||
}
|
||||
if (GUILayout.Button("Copy"))
|
||||
{
|
||||
galaxy.MapData.ResourceDensities.Add(resourceDensity.Copy());
|
||||
}
|
||||
EndHorizontal();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
|
|
|
|||
|
|
@ -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<Object, Object>(new ReferenceEqualityComparer()));
|
||||
}
|
||||
private static Object InternalCopy(Object originalObject, IDictionary<Object, Object> 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<object, object> 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<object, object> visited, object cloneObject, Type typeToReflect, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy, Func<FieldInfo, bool> 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<T>(this T original)
|
||||
{
|
||||
return (T)Copy((Object)original);
|
||||
}
|
||||
}
|
||||
|
||||
public class ReferenceEqualityComparer : EqualityComparer<Object>
|
||||
{
|
||||
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<Array, int[]> 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<Guid, GalaxyResponseZone> _galaxyResponseZones;
|
||||
private Dictionary<Guid, GalaxyZone> _galaxyZoneObjects = new Dictionary<Guid, GalaxyZone>();
|
||||
private Dictionary<Guid, ZoneObject> _zoneObjects = new Dictionary<Guid, ZoneObject>();
|
||||
private Dictionary<Guid, ParticleSystem> _zoneBelts = new Dictionary<Guid, ParticleSystem>();
|
||||
private List<ZoneObject> _wormholes = new List<ZoneObject>();
|
||||
private Dictionary<Guid, float2> _orbitPositions = new Dictionary<Guid, float2>();
|
||||
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<PlanetData>(belt.Key);
|
||||
|
||||
belt.Value.transform.position = float3(GetOrbitPosition(_cache.Get<OrbitData>(planetData.Orbit).Parent) * ZoneSizeScale, .15f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +185,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
var instance = GalaxyZonePrototype.Instantiate<Transform>();
|
||||
instance.position = float3((Vector2) zone.Position - Vector2.one * .5f,0) * GalaxyScale;
|
||||
var instanceZone = instance.GetComponent<GalaxyZone>();
|
||||
_galaxyZoneObjects[zone.ZoneID] = instanceZone;
|
||||
instanceZone.Label.text = zone.Name;
|
||||
instanceZone.Background.GetComponent<ClickableCollider>().OnClick += (_, pointer) =>
|
||||
{
|
||||
|
|
@ -208,6 +219,8 @@ public class StrategyGameManager : MonoBehaviour
|
|||
_zoneObjects.Clear();
|
||||
foreach (var zoneObject in _wormholes) Destroy(zoneObject.gameObject); //zoneObject.GetComponent<Prototype>().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<OrbitData>(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<ClickableCollider>().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);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class ZoneGeneratorTest : MonoBehaviour
|
|||
{
|
||||
var planetData = _cache.Get<PlanetData>(belt.Key);
|
||||
|
||||
belt.Value.transform.position = (Vector2) GetOrbitPosition(_cache.Get<OrbitData>(planetData.Orbit).Parent) * ZoneSizeScale;
|
||||
belt.Value.transform.position = float3(GetOrbitPosition(_cache.Get<OrbitData>(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<OrbitData>(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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
Economy.Server/bin/Debug/netcoreapp3.1/Economy.Server.dll
(Stored with Git LFS)
BIN
Economy.Server/bin/Debug/netcoreapp3.1/Economy.Server.dll
(Stored with Git LFS)
Binary file not shown.
BIN
Economy.Server/bin/Debug/netcoreapp3.1/Economy.Shared.dll
(Stored with Git LFS)
BIN
Economy.Server/bin/Debug/netcoreapp3.1/Economy.Shared.dll
(Stored with Git LFS)
Binary file not shown.
Binary file not shown.
BIN
Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.dll
(Stored with Git LFS)
BIN
Economy.Server/obj/Debug/netcoreapp3.1/Economy.Server.dll
(Stored with Git LFS)
Binary file not shown.
BIN
Economy.Shared/bin/Debug/netstandard2.0/Economy.Shared.dll
(Stored with Git LFS)
BIN
Economy.Shared/bin/Debug/netstandard2.0/Economy.Shared.dll
(Stored with Git LFS)
Binary file not shown.
BIN
Economy.Shared/obj/Debug/netstandard2.0/Economy.Shared.dll
(Stored with Git LFS)
BIN
Economy.Shared/obj/Debug/netstandard2.0/Economy.Shared.dll
(Stored with Git LFS)
Binary file not shown.
Loading…
Reference in a new issue