diff --git a/Assets/GWConquest/Scripts/Battle.cs b/Assets/GWConquest/Scripts/Battle.cs index 4f392c6..6f430f1 100644 --- a/Assets/GWConquest/Scripts/Battle.cs +++ b/Assets/GWConquest/Scripts/Battle.cs @@ -13,7 +13,7 @@ namespace GWConquest private GWNetworkList formations = new GWNetworkList(); private NetworkVariable zoneID = new NetworkVariable(); private NetworkVariable battleName = new NetworkVariable(); - private GWNetworkList flanks = new GWNetworkList(); + private GWNetworkList flanks = new GWNetworkList(); private NetworkVariable flankCount = new NetworkVariable(); private NetworkVariable isOver = new NetworkVariable(); private NetworkVariable victorID = new NetworkVariable(); @@ -85,7 +85,6 @@ namespace GWConquest public int FlankCount { get => flankCount.Value; - set => flankCount.Value = value; } public void SetFlank(ushort index, BattleFlank flank) @@ -165,6 +164,11 @@ namespace GWConquest flankCount.Value = Zone.zoneType == ZoneType.Ground ? 6 : 2; int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 9 : 20; + + for(int i = 0; i < FlankCount; i++) + { + flanks.Add(null); + } var allPlayers = AllPlayers.ToList(); if(allPlayers.Count() >= 2) diff --git a/Assets/GWConquest/Scripts/GWNetworkManager.cs b/Assets/GWConquest/Scripts/GWNetworkManager.cs index 3a6b774..b50b031 100644 --- a/Assets/GWConquest/Scripts/GWNetworkManager.cs +++ b/Assets/GWConquest/Scripts/GWNetworkManager.cs @@ -68,9 +68,8 @@ namespace GWConquest { planet.FinishSetup(); } - Player serverPlayer = NetworkManager.SpawnManager.GetLocalPlayerObject().GetComponent(); - serverPlayer.SetFaction((ushort) GameManager.HostFactionIndex); - serverPlayer.AssignStartingPlanets(); + Player serverPlayer = GameManager.Instance.SpawnPlayer((ushort) GameManager.HostFactionIndex); + Player.CurrentPlayer = serverPlayer; GameManager.Instance.ServerSceneLoadLocalDone(); @@ -101,10 +100,8 @@ namespace GWConquest { public void ServerSceneLoadCompleteRemote(ulong clientID) { - Player clientPlayer = NetworkManager.SpawnManager.GetPlayerNetworkObject(clientID).GetComponent(); - - clientPlayer.SetFaction((ushort) ((GameManager.HostFactionIndex + 1) % 2)); - clientPlayer.AssignStartingPlanets(); + Player clientPlayer = GameManager.Instance.SpawnPlayer((ushort) ((GameManager.HostFactionIndex + 1) % 2)); + clientPlayer.NetworkObject.ChangeOwnership(clientID); } public void ClientSceneLoadComplete() diff --git a/Assets/GWConquest/Scripts/GameManager.cs b/Assets/GWConquest/Scripts/GameManager.cs index a0a680b..7e4fef4 100644 --- a/Assets/GWConquest/Scripts/GameManager.cs +++ b/Assets/GWConquest/Scripts/GameManager.cs @@ -129,12 +129,8 @@ namespace GWConquest var faction = Factions[i]; if(faction.IsAI) { - GameObject go = Instantiate(PlayerPrefab); - go.GetComponent().Spawn(); - Player player = go.GetComponent(); + Player player = SpawnPlayer((ushort) i); player.SetAI(); - player.SetFaction((ushort) i); - player.AssignStartingPlanets(); } } @@ -143,6 +139,16 @@ namespace GWConquest IsLoaded = true; } + public Player SpawnPlayer(ushort faction) + { + GameObject go = Instantiate(PlayerPrefab); + go.GetComponent().Spawn(); + Player player = go.GetComponent(); + player.SetFaction(faction); + player.AssignStartingPlanets(); + return player; + } + public void SceneLoadLocalDone(bool isClient) { EntitiesLoaded = true; diff --git a/Assets/GWConquest/Scripts/Planet.cs b/Assets/GWConquest/Scripts/Planet.cs index 7437cf1..13c4e71 100644 --- a/Assets/GWConquest/Scripts/Planet.cs +++ b/Assets/GWConquest/Scripts/Planet.cs @@ -53,7 +53,7 @@ namespace GWConquest public string planetName; public string PlanetName { - get => planetNameVar.ToString(); + get => planetNameVar.Value.ToString(); set => planetNameVar.Value = value; } diff --git a/Assets/GWConquest/Scripts/Player.cs b/Assets/GWConquest/Scripts/Player.cs index a28c56e..c1aaf1d 100644 --- a/Assets/GWConquest/Scripts/Player.cs +++ b/Assets/GWConquest/Scripts/Player.cs @@ -82,8 +82,11 @@ namespace GWConquest public override void OnGainedOwnership() { - CurrentPlayer = this; - Debug.LogFormat("Current player is {0} with connection ID {1}", this, OwnerClientId); + if(!IsServer) + { + CurrentPlayer = this; + Debug.LogFormat("Current player is {0} with connection ID {1}", this, OwnerClientId); + } } public void SetFaction(ushort ind) diff --git a/Assets/GWConquest/Scripts/Unit.cs b/Assets/GWConquest/Scripts/Unit.cs index 9057c6c..e7f8030 100644 --- a/Assets/GWConquest/Scripts/Unit.cs +++ b/Assets/GWConquest/Scripts/Unit.cs @@ -205,8 +205,8 @@ namespace GWConquest get => Class.CanGoToFlank; } - public Inventory Inventory; - public Inventory Equipment; + public Inventory Inventory => inventory; + public Inventory Equipment => equipment; private void OnFormationChanged(NetworkBehaviourReference previousValue, NetworkBehaviourReference newValue) {