Browse Source

Serverside now runs

master
laurids 1 year ago
parent
commit
9290503a17
6 changed files with 29 additions and 19 deletions
  1. +6
    -2
      Assets/GWConquest/Scripts/Battle.cs
  2. +4
    -7
      Assets/GWConquest/Scripts/GWNetworkManager.cs
  3. +11
    -5
      Assets/GWConquest/Scripts/GameManager.cs
  4. +1
    -1
      Assets/GWConquest/Scripts/Planet.cs
  5. +5
    -2
      Assets/GWConquest/Scripts/Player.cs
  6. +2
    -2
      Assets/GWConquest/Scripts/Unit.cs

+ 6
- 2
Assets/GWConquest/Scripts/Battle.cs View File

@ -13,7 +13,7 @@ namespace GWConquest
private GWNetworkList<NetworkBehaviourReference> formations = new GWNetworkList<NetworkBehaviourReference>(); private GWNetworkList<NetworkBehaviourReference> formations = new GWNetworkList<NetworkBehaviourReference>();
private NetworkVariable<int> zoneID = new NetworkVariable<int>(); private NetworkVariable<int> zoneID = new NetworkVariable<int>();
private NetworkVariable<FixedString128Bytes> battleName = new NetworkVariable<FixedString128Bytes>(); private NetworkVariable<FixedString128Bytes> battleName = new NetworkVariable<FixedString128Bytes>();
private GWNetworkList<NetworkBehaviourReference> flanks = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<NullableNetworkBehaviourReference> flanks = new GWNetworkList<NullableNetworkBehaviourReference>();
private NetworkVariable<int> flankCount = new NetworkVariable<int>(); private NetworkVariable<int> flankCount = new NetworkVariable<int>();
private NetworkVariable<bool> isOver = new NetworkVariable<bool>(); private NetworkVariable<bool> isOver = new NetworkVariable<bool>();
private NetworkVariable<int> victorID = new NetworkVariable<int>(); private NetworkVariable<int> victorID = new NetworkVariable<int>();
@ -85,7 +85,6 @@ namespace GWConquest
public int FlankCount { public int FlankCount {
get => flankCount.Value; get => flankCount.Value;
set => flankCount.Value = value;
} }
public void SetFlank(ushort index, BattleFlank flank) public void SetFlank(ushort index, BattleFlank flank)
@ -165,6 +164,11 @@ namespace GWConquest
flankCount.Value = Zone.zoneType == ZoneType.Ground ? 6 : 2; flankCount.Value = Zone.zoneType == ZoneType.Ground ? 6 : 2;
int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 9 : 20; int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 9 : 20;
for(int i = 0; i < FlankCount; i++)
{
flanks.Add(null);
}
var allPlayers = AllPlayers.ToList(); var allPlayers = AllPlayers.ToList();
if(allPlayers.Count() >= 2) if(allPlayers.Count() >= 2)


+ 4
- 7
Assets/GWConquest/Scripts/GWNetworkManager.cs View File

@ -68,9 +68,8 @@ namespace GWConquest {
planet.FinishSetup(); planet.FinishSetup();
} }
Player serverPlayer = NetworkManager.SpawnManager.GetLocalPlayerObject().GetComponent<Player>();
serverPlayer.SetFaction((ushort) GameManager.HostFactionIndex);
serverPlayer.AssignStartingPlanets();
Player serverPlayer = GameManager.Instance.SpawnPlayer((ushort) GameManager.HostFactionIndex);
Player.CurrentPlayer = serverPlayer;
GameManager.Instance.ServerSceneLoadLocalDone(); GameManager.Instance.ServerSceneLoadLocalDone();
@ -101,10 +100,8 @@ namespace GWConquest {
public void ServerSceneLoadCompleteRemote(ulong clientID) public void ServerSceneLoadCompleteRemote(ulong clientID)
{ {
Player clientPlayer = NetworkManager.SpawnManager.GetPlayerNetworkObject(clientID).GetComponent<Player>();
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() public void ClientSceneLoadComplete()


+ 11
- 5
Assets/GWConquest/Scripts/GameManager.cs View File

@ -129,12 +129,8 @@ namespace GWConquest
var faction = Factions[i]; var faction = Factions[i];
if(faction.IsAI) if(faction.IsAI)
{ {
GameObject go = Instantiate(PlayerPrefab);
go.GetComponent<NetworkObject>().Spawn();
Player player = go.GetComponent<Player>();
Player player = SpawnPlayer((ushort) i);
player.SetAI(); player.SetAI();
player.SetFaction((ushort) i);
player.AssignStartingPlanets();
} }
} }
@ -143,6 +139,16 @@ namespace GWConquest
IsLoaded = true; IsLoaded = true;
} }
public Player SpawnPlayer(ushort faction)
{
GameObject go = Instantiate(PlayerPrefab);
go.GetComponent<NetworkObject>().Spawn();
Player player = go.GetComponent<Player>();
player.SetFaction(faction);
player.AssignStartingPlanets();
return player;
}
public void SceneLoadLocalDone(bool isClient) public void SceneLoadLocalDone(bool isClient)
{ {
EntitiesLoaded = true; EntitiesLoaded = true;


+ 1
- 1
Assets/GWConquest/Scripts/Planet.cs View File

@ -53,7 +53,7 @@ namespace GWConquest
public string planetName; public string planetName;
public string PlanetName { public string PlanetName {
get => planetNameVar.ToString();
get => planetNameVar.Value.ToString();
set => planetNameVar.Value = value; set => planetNameVar.Value = value;
} }


+ 5
- 2
Assets/GWConquest/Scripts/Player.cs View File

@ -82,8 +82,11 @@ namespace GWConquest
public override void OnGainedOwnership() 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) public void SetFaction(ushort ind)


+ 2
- 2
Assets/GWConquest/Scripts/Unit.cs View File

@ -205,8 +205,8 @@ namespace GWConquest
get => Class.CanGoToFlank; get => Class.CanGoToFlank;
} }
public Inventory Inventory;
public Inventory Equipment;
public Inventory Inventory => inventory;
public Inventory Equipment => equipment;
private void OnFormationChanged(NetworkBehaviourReference previousValue, NetworkBehaviourReference newValue) private void OnFormationChanged(NetworkBehaviourReference previousValue, NetworkBehaviourReference newValue)
{ {


Loading…
Cancel
Save