From f6081ef965fcf5e91fa0430bfe152c9ea231855c Mon Sep 17 00:00:00 2001 From: laurids Date: Thu, 20 Jul 2023 23:02:07 +0200 Subject: [PATCH] (WIP) Completely removed Bolt from Scripts --- Assets/GWConquest/Scripts/Battle.cs | 11 +- Assets/GWConquest/Scripts/BattleFlank.cs | 2 +- Assets/GWConquest/Scripts/BoltEntityCache.cs | 58 ----- .../Scripts/BoltEntityCache.cs.meta | 11 - Assets/GWConquest/Scripts/BoltList.cs | 240 ------------------ Assets/GWConquest/Scripts/BoltList.cs.meta | 11 - Assets/GWConquest/Scripts/District.cs | 2 +- Assets/GWConquest/Scripts/EntityList.cs | 119 --------- Assets/GWConquest/Scripts/EntityList.cs.meta | 11 - Assets/GWConquest/Scripts/Formation.cs | 5 +- Assets/GWConquest/Scripts/GWBoltBehaviour.cs | 35 --- .../Scripts/GWBoltBehaviour.cs.meta | 11 - Assets/GWConquest/Scripts/GWNetworkArray.cs | 5 - .../GWConquest/Scripts/GWNetworkArray.cs.meta | 11 - Assets/GWConquest/Scripts/GWNetworkManager.cs | 26 +- Assets/GWConquest/Scripts/GameManager.cs | 39 +-- Assets/GWConquest/Scripts/Planet.cs | 2 +- Assets/GWConquest/Scripts/PlanetPlacement.cs | 21 +- Assets/GWConquest/Scripts/Player.cs | 5 + Assets/GWConquest/Scripts/UI/MainMenu.cs | 28 +- Assets/GWConquest/Scripts/UI/PauseMenu.cs | 5 +- Assets/GWConquest/Scripts/Unit.cs | 2 +- Assets/GWConquest/Scripts/Zone.cs | 18 +- 23 files changed, 88 insertions(+), 590 deletions(-) delete mode 100644 Assets/GWConquest/Scripts/BoltEntityCache.cs delete mode 100644 Assets/GWConquest/Scripts/BoltEntityCache.cs.meta delete mode 100644 Assets/GWConquest/Scripts/BoltList.cs delete mode 100644 Assets/GWConquest/Scripts/BoltList.cs.meta delete mode 100644 Assets/GWConquest/Scripts/EntityList.cs delete mode 100644 Assets/GWConquest/Scripts/EntityList.cs.meta delete mode 100644 Assets/GWConquest/Scripts/GWBoltBehaviour.cs delete mode 100644 Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta delete mode 100644 Assets/GWConquest/Scripts/GWNetworkArray.cs delete mode 100644 Assets/GWConquest/Scripts/GWNetworkArray.cs.meta diff --git a/Assets/GWConquest/Scripts/Battle.cs b/Assets/GWConquest/Scripts/Battle.cs index e8add39..9f1eb2d 100644 --- a/Assets/GWConquest/Scripts/Battle.cs +++ b/Assets/GWConquest/Scripts/Battle.cs @@ -19,6 +19,8 @@ namespace GWConquest private NetworkVariable victorID; private NetworkVariable preparingCooldown; + public GameObject BattleFlankPrefab; + public IEnumerable Formations { get => formations.Select(r => r.GetBehaviour()); @@ -149,7 +151,9 @@ namespace GWConquest private BattleFlank InstantiateNewFlank(int maxUnitCount) { - var go = BoltNetwork.Instantiate(BoltPrefabs.BattleFlank); + GameObject go = Instantiate(BattleFlankPrefab); + go.GetComponent().Spawn(); + var flank = go.GetComponent(); flank.Battle = this; flank.MaxUnitCount = maxUnitCount; @@ -227,7 +231,7 @@ namespace GWConquest { if(IsInPreparing) { - PreparingCooldown -= BoltNetwork.FrameDeltaTime; + PreparingCooldown -= Time.fixedDeltaTime; if(PreparingCooldown <= 0) { PreparingCooldown = 0; @@ -287,8 +291,7 @@ namespace GWConquest foreach(var flank in AllFlanks.ToList()) { - BoltNetwork.Destroy(flank.gameObject); - Destroy(flank.gameObject); + flank.NetworkObject.Despawn(); } } diff --git a/Assets/GWConquest/Scripts/BattleFlank.cs b/Assets/GWConquest/Scripts/BattleFlank.cs index cbc8b8f..2e3cb3b 100644 --- a/Assets/GWConquest/Scripts/BattleFlank.cs +++ b/Assets/GWConquest/Scripts/BattleFlank.cs @@ -130,7 +130,7 @@ namespace GWConquest { { if(GetDeathCooldown(i) > 0) { - deathCooldowns[i] -= BoltNetwork.FrameDeltaTime; + deathCooldowns[i] -= Time.fixedDeltaTime; if(GetDeathCooldown(i) <= 0) { var unit = GetUnit(i); diff --git a/Assets/GWConquest/Scripts/BoltEntityCache.cs b/Assets/GWConquest/Scripts/BoltEntityCache.cs deleted file mode 100644 index 46c95ab..0000000 --- a/Assets/GWConquest/Scripts/BoltEntityCache.cs +++ /dev/null @@ -1,58 +0,0 @@ - -using UnityEngine; -using System.Collections.Generic; - -namespace GWConquest -{ - public static class BoltEntityCache - { - private static Dictionary dictionary = new Dictionary(); - - public static T Get(NetworkId id) where T : class, IEntityBehaviour - { - if(id == default(NetworkId)) - { - return null; - } - - if(dictionary.ContainsKey(id)) - { - var behaviour = dictionary[id]; - if(behaviour.entity.NetworkId == id) - { - return behaviour as T; - } - } - - var entity = BoltNetwork.FindEntity(id); - if(entity == null) - { - return null; - } - else { - var newBeh = entity.GetComponent(); - dictionary[id] = newBeh; - return newBeh; - } - - } - - public static NetworkId Set(T behaviour) where T : class, IEntityBehaviour - { - if(behaviour == null) - { - return default(NetworkId); - } - else { - return behaviour.entity.NetworkId; - } - } - - public static void ClearCache() - { - dictionary.Clear(); - } - } - - -} \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/BoltEntityCache.cs.meta b/Assets/GWConquest/Scripts/BoltEntityCache.cs.meta deleted file mode 100644 index a5d8dae..0000000 --- a/Assets/GWConquest/Scripts/BoltEntityCache.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c2f033f40a5a03e4ba66c6f9240d2043 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GWConquest/Scripts/BoltList.cs b/Assets/GWConquest/Scripts/BoltList.cs deleted file mode 100644 index 0a50f95..0000000 --- a/Assets/GWConquest/Scripts/BoltList.cs +++ /dev/null @@ -1,240 +0,0 @@ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using UdpKit; - -namespace GWConquest -{ - public abstract class BoltList : IList where TokenClass : BoltListToken, new() - { - private IState state; - private string propertyName; - - public BoltList(IState _state, string _propertyName) - { - state = _state; - propertyName = _propertyName; - } - - private TokenClass Token - { - get - { - TokenClass token = state.GetDynamic(propertyName) as TokenClass; - if (token == null) - { - return new TokenClass(); - } - else - { - return token; - } - } - set => state.SetDynamic(propertyName, value); - } - - public void FromToken(TokenClass token) - { - Token = token; - } - - public T this[int index] - { - get => Token.entries[index]; - set - { - Token.entries[index] = value; - Token = new TokenClass().SetEntries(Token.entries) as TokenClass; - } - } - - public int Count => Token.entries.Length; - - public bool IsReadOnly => false; - - public void Add(T item) - { - if (!Contains(item)) - { - - Token = new TokenClass().SetEntries(Token.entries.Append(item)) as TokenClass; - } - } - - public void Clear() - { - Token = new TokenClass(); - } - - public bool Contains(T item) - { - return Token.entries.Contains(item); - } - - public void CopyTo(T[] array, int arrayIndex) - { - Token.entries.CopyTo(array, arrayIndex); - } - - public IEnumerator GetEnumerator() - { - return new GenericListEnumerator(this); - } - - public int IndexOf(T item) - { - return Array.IndexOf(Token.entries, item); - } - - public void Insert(int index, T item) - { - List list = Token.entries.ToList(); - list.Insert(index, item); - Token = new TokenClass().SetEntries(list) as TokenClass; - } - - public bool Remove(T item) - { - List list = Token.entries.ToList(); - if (list.Remove(item)) - { - Token = new TokenClass().SetEntries(list) as TokenClass; - return true; - } - else return false; - } - - public void RemoveAt(int index) - { - List list = Token.entries.ToList(); - list.RemoveAt(index); - Token = new TokenClass().SetEntries(list) as TokenClass; - } - - IEnumerator IEnumerable.GetEnumerator() - { - return new GenericListEnumerator(this); - } - - public override string ToString() - { - return "BoltList " + Util.PrintEnumerable(this); - } - - public void SetEntries(IEnumerable entries) - { - Token = new TokenClass().SetEntries(entries) as TokenClass; - } - } - - public abstract class BoltListToken : IProtocolToken - { - public BoltListToken() - { - entries = new T[0]; - } - - public BoltListToken SetEntries(IEnumerable _entities) - { - entries = _entities.ToArray(); - return this; - } - - public T[] entries { get; private set; } - - public void Read(UdpPacket packet) - { - //Debug.LogFormat("Reading Bolt list..."); - int count = packet.ReadInt(); - entries = new T[count]; - for (int i = 0; i < count; i++) - { - entries[i] = ReadEntry(packet); - } - //Debug.LogFormat("Finished reading Bolt list {0}", this); - } - - public void Write(UdpPacket packet) - { - //Debug.LogFormat("Writing Bolt list..."); - packet.WriteInt(entries.Length); - foreach (T e in entries) - { - WriteEntry(packet, e); - } - //Debug.LogFormat("Finished writing Bolt list {0}", this); - } - - public override string ToString() - { - return "BoltList " + Util.PrintEnumerable(entries); - } - - public override bool Equals(object obj) - { - if(obj == null || !(obj is BoltListToken)) - return false; - - var other = obj as BoltListToken; - - if(entries.Length != other.entries.Length) - return false; - - for(int i = 0; i < entries.Length; i++) - { - if(entries[i] == null) - { - if(other.entries[i] != null) - return false; - } - else { - if(!entries[i].Equals(other.entries[i])) - return false; - } - } - - return true; - } - - public abstract T ReadEntry(UdpPacket packet); - - public abstract void WriteEntry(UdpPacket packet, T entry); - - } - - public class ZoneListToken : BoltListToken { - public override Zone ReadEntry(UdpPacket packet) - { - return Zone.GetFromId(packet.ReadInt()); - } - - public override void WriteEntry(UdpPacket packet, Zone entry) - { - packet.WriteInt(Zone.GetZoneId(entry)); - } - } - - public class ZoneList : BoltList - { - public ZoneList(IState _state, string _propertyName) : base(_state, _propertyName) {} - } - - public class StringListToken : BoltListToken { - public override string ReadEntry(UdpPacket packet) - { - return packet.ReadString(); - } - - public override void WriteEntry(UdpPacket packet, string entry) - { - packet.WriteString(entry); - } - } - - public class StringList : BoltList - { - public StringList(IState _state, string _propertyName) : base(_state, _propertyName) {} - } -} \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/BoltList.cs.meta b/Assets/GWConquest/Scripts/BoltList.cs.meta deleted file mode 100644 index d85b5f5..0000000 --- a/Assets/GWConquest/Scripts/BoltList.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fda8796fd8800ef46a1ae47fa4de74a7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GWConquest/Scripts/District.cs b/Assets/GWConquest/Scripts/District.cs index c67427f..87a91ec 100644 --- a/Assets/GWConquest/Scripts/District.cs +++ b/Assets/GWConquest/Scripts/District.cs @@ -285,7 +285,7 @@ namespace GWConquest { Debug.LogFormat("Player {0} is the only player in district {1}, starting allegiance change...", player, this); } - captureCooldown.Value += BoltNetwork.FrameDeltaTime; + captureCooldown.Value += Time.fixedDeltaTime; } return; } diff --git a/Assets/GWConquest/Scripts/EntityList.cs b/Assets/GWConquest/Scripts/EntityList.cs deleted file mode 100644 index 71abcd8..0000000 --- a/Assets/GWConquest/Scripts/EntityList.cs +++ /dev/null @@ -1,119 +0,0 @@ -using UdpKit; - -using System.Collections.Generic; -using System.Linq; -using System.Collections; -using System; - -namespace GWConquest -{ - public class GenericListEnumerator : IEnumerator - { - private int position = -1; - private IList list; - - public GenericListEnumerator(IList _list) - { - list = _list; - } - - public T Current => list[position]; - - object IEnumerator.Current => list[position]; - - public void Dispose() { } - - public bool MoveNext() - { - position++; - return position < list.Count; - } - - public void Reset() - { - position = -1; - } - } - - public class CachedBoltEntity - { - public NetworkId NetworkId { get; private set; } - private BoltEntity cachedEntity; - - public CachedBoltEntity(NetworkId id) - { - NetworkId = id; - } - - public CachedBoltEntity(BoltEntity e) - { - NetworkId = e.NetworkId; - cachedEntity = e; - } - - public BoltEntity Entity - { - get - { - if (cachedEntity == null) - { - cachedEntity = BoltNetwork.FindEntity(NetworkId); - } - return cachedEntity; - } - } - - public override bool Equals(object obj) - { - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - - var other = obj as CachedBoltEntity; - - return NetworkId == other.NetworkId; - } - - public override int GetHashCode() - { - return NetworkId.PackedValue.GetHashCode(); - } - - public override string ToString() - { - return Entity?.ToString(); - } - } - - public class EntityListToken : BoltListToken - { - public override CachedBoltEntity ReadEntry(UdpPacket packet) - { - var id = new NetworkId(packet.ReadULong()); - return new CachedBoltEntity(id); - } - - public override void WriteEntry(UdpPacket packet, CachedBoltEntity entry) - { - packet.WriteULong(entry.NetworkId.PackedValue); - } - - - } - - public class EntityList : BoltList - { - public EntityList(IState _state, string _propertyName) : base(_state, _propertyName) { } - - public void Add(BoltEntity e) - { - Add(new CachedBoltEntity(e)); - } - - public bool Remove(BoltEntity e) - { - return Remove(new CachedBoltEntity(e)); - } - } -} \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/EntityList.cs.meta b/Assets/GWConquest/Scripts/EntityList.cs.meta deleted file mode 100644 index 3dccab7..0000000 --- a/Assets/GWConquest/Scripts/EntityList.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 38983f1af3b8f9446a9a71fc1d5ebfc7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GWConquest/Scripts/Formation.cs b/Assets/GWConquest/Scripts/Formation.cs index 463e5ef..db9e355 100644 --- a/Assets/GWConquest/Scripts/Formation.cs +++ b/Assets/GWConquest/Scripts/Formation.cs @@ -507,7 +507,7 @@ namespace GWConquest } if (MovementState == FormationMovementState.Moving) { - CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; + CoveredDistance += movementSpeed * Time.fixedDeltaTime; if (CoveredDistance >= CurrentTransition.TransitionLength) { @@ -1076,8 +1076,7 @@ namespace GWConquest units.RemoveAt(i); OnUnitRemoved(unit); - BoltNetwork.Destroy(unit.gameObject); - Destroy(unit.gameObject); + unit.NetworkObject.Despawn(); } } } diff --git a/Assets/GWConquest/Scripts/GWBoltBehaviour.cs b/Assets/GWConquest/Scripts/GWBoltBehaviour.cs deleted file mode 100644 index 4ad020b..0000000 --- a/Assets/GWConquest/Scripts/GWBoltBehaviour.cs +++ /dev/null @@ -1,35 +0,0 @@ - - -namespace GWConquest { - public abstract class GWBoltBehaviour : EntityBehaviour where T : class, IState - { - private T _state = null; - - public T State { - get { - /*if(_state == null) - { - _state = state; - } - return _state;*/ - return state; - } - } - } - - public abstract class GWBoltEntityListener : EntityEventListener where T : class, IState - { - private T _state = null; - - public T State { - get { - /*if(_state == null) - { - _state = state; - } - return _state;*/ - return state; - } - } - } -} \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta b/Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta deleted file mode 100644 index 85fafba..0000000 --- a/Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f48b9c6bc6be7154e809c78208e38787 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GWConquest/Scripts/GWNetworkArray.cs b/Assets/GWConquest/Scripts/GWNetworkArray.cs deleted file mode 100644 index 531c5ff..0000000 --- a/Assets/GWConquest/Scripts/GWNetworkArray.cs +++ /dev/null @@ -1,5 +0,0 @@ -using Unity.Netcode; - -namespace GWConquest { - -} \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/GWNetworkArray.cs.meta b/Assets/GWConquest/Scripts/GWNetworkArray.cs.meta deleted file mode 100644 index 9809ab7..0000000 --- a/Assets/GWConquest/Scripts/GWNetworkArray.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5893ec9dc0d5802479ca61e4b13ac64f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/GWConquest/Scripts/GWNetworkManager.cs b/Assets/GWConquest/Scripts/GWNetworkManager.cs index 1e61dc5..dbd7de1 100644 --- a/Assets/GWConquest/Scripts/GWNetworkManager.cs +++ b/Assets/GWConquest/Scripts/GWNetworkManager.cs @@ -19,6 +19,7 @@ namespace GWConquest { public GameObject UnitPrefab; public GameObject FormationPrefab; + public GameObject BattlePrefab; public override void OnNetworkSpawn() { @@ -39,6 +40,8 @@ namespace GWConquest { else { ServerSceneLoadCompleteRemote(sceneEvent.ClientId); } + + GameManager.Instance.SceneLoadLocalDone(false); } } @@ -46,6 +49,7 @@ namespace GWConquest { if(sceneEvent.SceneEventType == SceneEventType.LoadComplete) { ClientSceneLoadComplete(); + GameManager.Instance.SceneLoadLocalDone(true); } } } @@ -66,7 +70,7 @@ namespace GWConquest { serverPlayer.SetFaction((ushort) GameManager.HostFactionIndex); serverPlayer.AssignStartingPlanets(); - GameManager.Instance.SceneLoadLocalDone(); + GameManager.Instance.ServerSceneLoadLocalDone(); //foreach(GameObject go in FindObjectsOfType()) { // go.SendMessage("OnSceneLoadLocalDone", SendMessageOptions.DontRequireReceiver); @@ -154,10 +158,30 @@ namespace GWConquest { public Formation SpawnFormation(Zone zone, Player player) { GameObject go = Instantiate(FormationPrefab); + go.GetComponent().Spawn(); + Formation playerFormation = go.GetComponent(); playerFormation.Initialize(zone, player); return playerFormation; } + public Battle SpawnBattle(Zone zone) + { + var go = Instantiate(BattlePrefab); + go.GetComponent().Spawn(); + + Battle battle = go.GetComponent(); + battle.Zone = zone; + foreach (Formation f in zone.Formations) + { + battle.AddFormation(f); + } + battle.Init(); + + Debug.LogFormat("Starting battle at zone {0}", this); + + return battle; + } + } } \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/GameManager.cs b/Assets/GWConquest/Scripts/GameManager.cs index 31b84d6..a0a680b 100644 --- a/Assets/GWConquest/Scripts/GameManager.cs +++ b/Assets/GWConquest/Scripts/GameManager.cs @@ -1,7 +1,6 @@ using UnityEngine; using System.Collections; - - +using Unity.Netcode; namespace GWConquest { @@ -85,6 +84,8 @@ namespace GWConquest public bool SpawnAIPlayer; + public GameObject PlayerPrefab; + public bool IsLoaded { get; private set; } = false; public float TimeScale = 1f; @@ -118,7 +119,7 @@ namespace GWConquest BattleLog.Instance = new BattleLog(); } - public void SceneLoadLocalDone() + public void ServerSceneLoadLocalDone() { if(SpawnAIPlayer) { @@ -128,11 +129,12 @@ namespace GWConquest var faction = Factions[i]; if(faction.IsAI) { - BoltEntity playerEntity = BoltNetwork.Instantiate(BoltPrefabs.Player); - IPlayerState playerState = playerEntity.GetState(); ; - playerState.IsAI = true; - playerState.FactionIndex = i; - playerEntity.GetComponent().AssignStartingPlanets(); + GameObject go = Instantiate(PlayerPrefab); + go.GetComponent().Spawn(); + Player player = go.GetComponent(); + player.SetAI(); + player.SetFaction((ushort) i); + player.AssignStartingPlanets(); } } @@ -141,26 +143,11 @@ namespace GWConquest IsLoaded = true; } - public void FixedUpdate() { - if(Input.GetKeyDown(KeyCode.F1)) - { - var ui = IngameUI.Instance.gameObject; - ui.SetActive(!ui.activeSelf); - } - } - - public void SetEntitiesLoaded() + public void SceneLoadLocalDone(bool isClient) { - StartCoroutine(EntitiesLoadedAsync()); - } - - private IEnumerator EntitiesLoadedAsync() - { - yield return new WaitForSecondsRealtime(1f); - yield return new WaitForFixedUpdate(); EntitiesLoaded = true; - if(BoltNetwork.IsClient) + if(isClient) { Debug.LogFormat("Loading non-static planets on client..."); InitPlanetsClient(); @@ -176,6 +163,7 @@ namespace GWConquest LoadingScreen.Dismiss(); } + private void InitPlanetsClient() { var allPlanets = FindObjectsOfType(); @@ -212,7 +200,6 @@ namespace GWConquest BattleLog.Instance = null; - BoltEntityCache.ClearCache(); District.AllDistricts.Clear(); Formation.AllFormations.Clear(); diff --git a/Assets/GWConquest/Scripts/Planet.cs b/Assets/GWConquest/Scripts/Planet.cs index c23141d..3003152 100644 --- a/Assets/GWConquest/Scripts/Planet.cs +++ b/Assets/GWConquest/Scripts/Planet.cs @@ -338,7 +338,7 @@ namespace GWConquest { formationsChangedSinceLastFrame = true; - if(BoltNetwork.IsServer) + if(IsServer) { var currentPlayers = GetAllFormations(ZoneType.Space).Select(f => f.Player).Distinct(); foreach(Player player in currentPlayers) diff --git a/Assets/GWConquest/Scripts/PlanetPlacement.cs b/Assets/GWConquest/Scripts/PlanetPlacement.cs index fa2238c..f1cc022 100644 --- a/Assets/GWConquest/Scripts/PlanetPlacement.cs +++ b/Assets/GWConquest/Scripts/PlanetPlacement.cs @@ -2,8 +2,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; - - +using Unity.Netcode; namespace GWConquest @@ -26,6 +25,10 @@ namespace GWConquest public Transform PlanetConnectionParent; public GameObject[] PlanetPrefabs; + public GameObject PlanetPrefab; + public GameObject DistrictPrefab; + public GameObject FactoryPrefab; + private string[] PlanetNames; public float MinPlanetDistance; @@ -120,7 +123,8 @@ namespace GWConquest public Planet PlacePlanet(Vector3 position, ref int nextZoneId) { - var planetGO = BoltNetwork.Instantiate(BoltPrefabs.Planet, position, Quaternion.identity); + var planetGO = Instantiate(PlanetPrefab, position, Quaternion.identity); + planetGO.GetComponent().Spawn(); var planet = planetGO.GetComponent(); var planetName = DrawName(); @@ -166,11 +170,11 @@ namespace GWConquest public void SpawnDistrict(Planet planet, ref int nextZoneId) { - PrefabId prefabID; + GameObject prefab; DistrictType type; if(Random.value <= districtSettings.FactoryChance) { - prefabID = BoltPrefabs.Factory; + prefab = FactoryPrefab; int factoryType = Random.Range(0, 3); switch(factoryType) { @@ -190,11 +194,11 @@ namespace GWConquest } else if(Random.value <= districtSettings.FoodChance / (1f - districtSettings.FactoryChance)) { - prefabID = BoltPrefabs.District; + prefab = DistrictPrefab; type = DistrictType.Food; } else { - prefabID = BoltPrefabs.Factory; + prefab = FactoryPrefab; type = DistrictType.Civil; } @@ -212,7 +216,8 @@ namespace GWConquest districtPos += planet.transform.position; - var go = BoltNetwork.Instantiate(prefabID, districtPos, Quaternion.identity); + var go = Instantiate(prefab, districtPos, Quaternion.identity); + go.GetComponent().Spawn(); go.transform.SetParent(planet.transform); var district = go.GetComponent(); diff --git a/Assets/GWConquest/Scripts/Player.cs b/Assets/GWConquest/Scripts/Player.cs index d4b3ee0..10db373 100644 --- a/Assets/GWConquest/Scripts/Player.cs +++ b/Assets/GWConquest/Scripts/Player.cs @@ -91,6 +91,11 @@ namespace GWConquest factionIndex.Value = ind; } + public void SetAI() + { + isAI.Value = true; + } + public NetworkClient Client { get diff --git a/Assets/GWConquest/Scripts/UI/MainMenu.cs b/Assets/GWConquest/Scripts/UI/MainMenu.cs index a614cb5..ed3e7fe 100644 --- a/Assets/GWConquest/Scripts/UI/MainMenu.cs +++ b/Assets/GWConquest/Scripts/UI/MainMenu.cs @@ -1,17 +1,19 @@  -using Photon.Bolt.Matchmaking; using System; using UdpKit; using UnityEngine; +using Unity.Netcode; namespace GWConquest { - public class MainMenu : GlobalEventListener + public class MainMenu : MonoBehaviour { private void Start() { GameOptions.ApplyOptions(); + + NetworkManager.Singleton.OnServerStarted += ServerStartDone; } public void StartServer(int hostFactionIndex) @@ -22,39 +24,33 @@ namespace GWConquest LoadingScreen.Show(); - BoltLauncher.StartServer(); + NetworkManager.Singleton.StartHost(); } public void StartClient() { GameManager.ClearAllCaches(); - BoltLauncher.StartClient(); + NetworkManager.Singleton.StartClient(); } public void CancelClient() { - BoltLauncher.Shutdown(); + NetworkManager.Singleton.Shutdown(); } public void Quit() { Application.Quit(); } - public override void BoltStartDone() + public void ServerStartDone() { - if(BoltNetwork.IsServer) - { - string matchName = Guid.NewGuid().ToString(); + Debug.Log("Server start done"); - BoltMatchmaking.CreateSession( - sessionID: matchName, - sceneToLoad: "GalaxyMap" - ); - } + NetworkManager.Singleton.SceneManager.LoadScene("GalaxyMap", UnityEngine.SceneManagement.LoadSceneMode.Single); } - public override void SessionListUpdated(Map sessionList) + /*public override void SessionListUpdated(Map sessionList) { Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count); @@ -69,6 +65,6 @@ namespace GWConquest BoltMatchmaking.JoinSession(photonSession); } } - } + }*/ } } \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/UI/PauseMenu.cs b/Assets/GWConquest/Scripts/UI/PauseMenu.cs index c6775f7..c17e6c1 100644 --- a/Assets/GWConquest/Scripts/UI/PauseMenu.cs +++ b/Assets/GWConquest/Scripts/UI/PauseMenu.cs @@ -1,6 +1,7 @@  using UnityEngine; using UnityEngine.SceneManagement; +using Unity.Netcode; namespace GWConquest { @@ -8,13 +9,13 @@ namespace GWConquest { public void QuitToMainMenu() { - BoltLauncher.Shutdown(); + NetworkManager.Singleton.Shutdown(); SceneManager.LoadScene("MainMenu"); } public void QuitToDesktop() { - BoltLauncher.Shutdown(); + NetworkManager.Singleton.Shutdown(); Application.Quit(); } } diff --git a/Assets/GWConquest/Scripts/Unit.cs b/Assets/GWConquest/Scripts/Unit.cs index a77f2ee..66465c8 100644 --- a/Assets/GWConquest/Scripts/Unit.cs +++ b/Assets/GWConquest/Scripts/Unit.cs @@ -498,7 +498,7 @@ namespace GWConquest if (ShieldsCooldown == 0 && Shields < Class.Shields) { float regRate = Class.ShieldRegeneration / GameManager.Instance.BattleTurnLength; - Shields += regRate * BoltNetwork.FrameDeltaTime; + Shields += regRate * Time.fixedDeltaTime; if (Shields > Class.Shields) { Shields = Class.Shields; diff --git a/Assets/GWConquest/Scripts/Zone.cs b/Assets/GWConquest/Scripts/Zone.cs index ff6fbb9..694fb03 100644 --- a/Assets/GWConquest/Scripts/Zone.cs +++ b/Assets/GWConquest/Scripts/Zone.cs @@ -1,8 +1,7 @@ using System.Collections.Generic; using UnityEngine; using System.Linq; - - +using Unity.Netcode; namespace GWConquest { @@ -111,7 +110,7 @@ namespace GWConquest OnFormationChanged(formation); - if (BoltNetwork.IsServer) + if (NetworkManager.Singleton.IsServer) { if (CurrentBattle != null) { @@ -132,16 +131,7 @@ namespace GWConquest { if (ShouldStartBattle()) { - var battleEntity = BoltNetwork.Instantiate(BoltPrefabs.Battle); - CurrentBattle = battleEntity.GetComponent(); - CurrentBattle.Zone = this; - foreach (Formation f in Formations) - { - CurrentBattle.AddFormation(f); - } - CurrentBattle.Init(); - - Debug.LogFormat("Starting battle at zone {0}", this); + GWNetworkManager.Instance.SpawnBattle(this); } } @@ -154,7 +144,7 @@ namespace GWConquest { OnFormationChanged(formation); - if (BoltNetwork.IsServer) + if (NetworkManager.Singleton.IsServer) { if (CurrentBattle != null) {