Browse Source

Random Planets - Netcode Part 1

bolt_update
laurids 3 years ago
parent
commit
561566e680
5 changed files with 84 additions and 16 deletions
  1. +47
    -13
      Assets/GWConquest/Scripts/Planet.cs
  2. +4
    -0
      Assets/GWConquest/Scripts/PlanetConnection.cs
  3. +5
    -0
      Assets/GWConquest/Scripts/PlanetPlacement.cs
  4. +22
    -0
      Assets/GWConquest/Scripts/ServerCallbacks.cs
  5. +6
    -3
      Assets/GWConquest/Scripts/Unit.cs

+ 47
- 13
Assets/GWConquest/Scripts/Planet.cs View File

@ -118,6 +118,32 @@ namespace GWConquest
{ {
ConnectedPlanetsList = new EntityList(State, "ConnectedPlanets"); ConnectedPlanetsList = new EntityList(State, "ConnectedPlanets");
if(BoltNetwork.IsClient)
{
State.AddCallback("SpaceZoneID", () => {
BoltLog.Info("Space zone id changed to {0} on client planet {1}, static: {2}", State.SpaceZoneID, State.PlanetName, PlanetStatic);
var zone = GetMainZone(ZoneType.Space);
zone.SetZoneId(State.SpaceZoneID);
zone.zoneType = ZoneType.Space;
});
State.AddCallback("AttackZoneID", () => {
BoltLog.Info("Attack zone id changed to {0} on client planet {1}, static: {2}", State.AttackZoneID, State.PlanetName, PlanetStatic);
var zone = GetAttackZones(ZoneType.Ground)[0];
zone.SetZoneId(State.AttackZoneID);
zone.zoneType = ZoneType.Ground;
});
State.AddCallback("PlanetName", () => {
BoltLog.Info("planet name changed to {0} on client planet, static: {1}", State.PlanetName, PlanetStatic);
planetName = State.PlanetName;
});
State.AddCallback("ConnectedPlanets", () => {
BoltLog.Info("Connected planets changed to {0} on client planet{1}, static: {2}", ConnectedPlanetsList, State.PlanetName, PlanetStatic);
});
}
if(PlanetStatic) if(PlanetStatic)
{ {
foreach (Zone zone in groundZones) foreach (Zone zone in groundZones)
@ -134,18 +160,6 @@ namespace GWConquest
State.SpaceZoneID = Zone.GetZoneId(GetMainZone(ZoneType.Space)); State.SpaceZoneID = Zone.GetZoneId(GetMainZone(ZoneType.Space));
State.AttackZoneID = Zone.GetZoneId(GetAttackZones(ZoneType.Ground)[0]); State.AttackZoneID = Zone.GetZoneId(GetAttackZones(ZoneType.Ground)[0]);
State.PlanetName = planetName; State.PlanetName = planetName;
/*foreach(var conn in connections)
{
if(conn.planet1 == this)
{
ConnectedPlanetsList.Add(conn.planet2.entity);
}
else if(conn.planet2 == this)
{
ConnectedPlanetsList.Add(conn.planet1.entity);
}
}*/
} }
} }
@ -170,8 +184,28 @@ namespace GWConquest
} }
} }
public void UpdateConnectionsServer()
{
foreach (var conn in connections)
{
if (conn.planet1 == this)
{
ConnectedPlanetsList.Add(conn.planet2.entity);
}
else if (conn.planet2 == this)
{
ConnectedPlanetsList.Add(conn.planet1.entity);
}
}
}
public void FinishSetup() public void FinishSetup()
{ {
if(entity.IsOwner)
{
UpdateConnectionsServer();
}
pathfindingGraph = new PathfindingGraph<Zone>(groundZones); pathfindingGraph = new PathfindingGraph<Zone>(groundZones);
foreach(DistrictConnection conn in GetComponentsInChildren<DistrictConnection>()) foreach(DistrictConnection conn in GetComponentsInChildren<DistrictConnection>())
{ {
@ -204,7 +238,7 @@ namespace GWConquest
PlanetPathfindingGraph = new PathfindingGraph<Zone>(spaceZones); PlanetPathfindingGraph = new PathfindingGraph<Zone>(spaceZones);
foreach(PlanetConnection conn in FindObjectsOfType<PlanetConnection>())
foreach(PlanetConnection conn in FindObjectsOfType<PlanetConnection>().Where(c => !c.IsPreConnection))
{ {
float connLength = Vector3.Distance(conn.planet1.transform.position, conn.planet2.transform.position); float connLength = Vector3.Distance(conn.planet1.transform.position, conn.planet2.transform.position);
PlanetPathfindingGraph.AddConnection(conn.planet1.GetMainZone(ZoneType.Space), conn.planet2.GetMainZone(ZoneType.Space), connLength); PlanetPathfindingGraph.AddConnection(conn.planet1.GetMainZone(ZoneType.Space), conn.planet2.GetMainZone(ZoneType.Space), connLength);


+ 4
- 0
Assets/GWConquest/Scripts/PlanetConnection.cs View File

@ -130,12 +130,16 @@ namespace GWConquest
{ {
lineRenderer.enabled = true; lineRenderer.enabled = true;
lineRenderer.SetPositions(new Vector3[] { planet1.transform.position, planet2.transform.position }); lineRenderer.SetPositions(new Vector3[] { planet1.transform.position, planet2.transform.position });
#if UNITY_EDITOR
UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(lineRenderer); UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(lineRenderer);
#endif
} }
else else
{ {
lineRenderer.enabled = false; lineRenderer.enabled = false;
#if UNITY_EDITOR
UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(lineRenderer); UnityEditor.PrefabUtility.RecordPrefabInstancePropertyModifications(lineRenderer);
#endif
} }


+ 5
- 0
Assets/GWConquest/Scripts/PlanetPlacement.cs View File

@ -72,6 +72,11 @@ namespace GWConquest
return planet; return planet;
} }
public void InitPlanetPrefab(Planet planet)
{
}
public PlanetConnection SpawnPlanetConnection(Planet planet1, Planet planet2) public PlanetConnection SpawnPlanetConnection(Planet planet1, Planet planet2)
{ {
GameObject pcGO = Instantiate(PlanetConnectionPrefab); GameObject pcGO = Instantiate(PlanetConnectionPrefab);


+ 22
- 0
Assets/GWConquest/Scripts/ServerCallbacks.cs View File

@ -1,5 +1,7 @@
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UdpKit;
using Bolt;
namespace GWConquest namespace GWConquest
{ {
@ -67,6 +69,26 @@ namespace GWConquest
configEvnt.Send(); configEvnt.Send();
} }
public override void ConnectRequest(UdpEndPoint endpoint, IProtocolToken token)
{
BoltLog.Info("Connect request recieved");
if(GameManager.EntitiesLoaded)
{
BoltLog.Info("Accepting connect request");
BoltNetwork.Accept(endpoint);
}
else {
BoltLog.Info("Refusing connect request");
BoltNetwork.Refuse(endpoint);
}
}
public override void Connected(BoltConnection connection)
{
BoltLog.Info("Client connected");
}
public override void OnEvent(BuildUnitEvent evnt) public override void OnEvent(BuildUnitEvent evnt)
{ {
Zone zone = Zone.GetFromId(evnt.Zone); Zone zone = Zone.GetFromId(evnt.Zone);


+ 6
- 3
Assets/GWConquest/Scripts/Unit.cs View File

@ -192,9 +192,12 @@ namespace GWConquest
Inventory.StorageCapacity = Class.InventorySlots; Inventory.StorageCapacity = Class.InventorySlots;
Equipment.StorageCapacity = Class.EquipmentSlots; Equipment.StorageCapacity = Class.EquipmentSlots;
Fuel = Class.FuelCapacity;
Food = Class.FoodCapacity;
Supplies = Class.SuppliesCapacity;
if(entity.IsOwner)
{
Fuel = Class.FuelCapacity;
Food = Class.FoodCapacity;
Supplies = Class.SuppliesCapacity;
}
}); });
if(BoltNetwork.IsServer) if(BoltNetwork.IsServer)


Loading…
Cancel
Save