From 40359c15bfc2ac69fcd16cb2d9c953eeb0d2035f Mon Sep 17 00:00:00 2001 From: laurids Date: Sat, 6 Apr 2024 15:22:56 +0200 Subject: [PATCH] Battle phases (WIP) --- Assets/GWConquest/Scripts/Battle.cs | 60 ++++++++++++++++-------- Assets/GWConquest/Scripts/GameManager.cs | 7 ++- Assets/GWConquest/Scripts/Unit.cs | 2 +- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/Assets/GWConquest/Scripts/Battle.cs b/Assets/GWConquest/Scripts/Battle.cs index 76c1c79..1c6b2f9 100644 --- a/Assets/GWConquest/Scripts/Battle.cs +++ b/Assets/GWConquest/Scripts/Battle.cs @@ -13,9 +13,9 @@ namespace GWConquest private NetworkVariable battleName = new NetworkVariable(); private GWNetworkList flanks = new GWNetworkList(); private NetworkVariable flankCount = new NetworkVariable(); - private NetworkVariable isOver = new NetworkVariable(); private NetworkVariable victorID = new NetworkVariable(); - private NetworkVariable preparingCooldown = new NetworkVariable(); + private NetworkVariable phaseCooldown = new NetworkVariable(); + private NetworkVariable battlePhase = new NetworkVariable(); public GameObject BattleFlankPrefab; @@ -125,19 +125,19 @@ namespace GWConquest public bool IsOver { - get => isOver.Value; - set => isOver.Value = value; + get => Phase == BattlePhase.Finished; } - public float PreparingCooldown + public float PhaseCooldown { - get => preparingCooldown.Value; - set => preparingCooldown.Value = value; + get => phaseCooldown.Value; + private set => phaseCooldown.Value = value; } - public bool IsInPreparing + public BattlePhase Phase { - get => PreparingCooldown > 0; + get => battlePhase.Value; + private set => battlePhase.Value = value; } public Player Victor @@ -174,7 +174,8 @@ namespace GWConquest public void Init() { - PreparingCooldown = GameManager.Instance.BattlePreparingCooldown; + Phase = BattlePhase.Command; + PhaseCooldown = GameManager.Instance.BattleCommandPhaseLength; flankCount.Value = Zone.zoneType == ZoneType.Ground ? 3 : 1; int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 29 : 86; @@ -240,15 +241,8 @@ namespace GWConquest { if (IsSpawned && IsServer) { - if (IsInPreparing) - { - PreparingCooldown -= Time.fixedDeltaTime; - if (PreparingCooldown <= 0) - { - PreparingCooldown = 0; - } - } - else if (!IsOver) + var phase = Phase; + if (phase == BattlePhase.Combat) { var gm = GameManager.Instance; @@ -276,6 +270,25 @@ namespace GWConquest SimulateTurn(); } + + if (phase != BattlePhase.Finished) + { + PhaseCooldown -= Time.fixedDeltaTime; + if (PhaseCooldown <= 0) + { + PhaseCooldown = 0; + if (phase == BattlePhase.Command) + { + Phase = BattlePhase.Combat; + } + else if (phase == BattlePhase.Combat) + { + Phase = BattlePhase.Command; + } + } + } + + } @@ -283,7 +296,7 @@ namespace GWConquest public void SetBattleOver() { - IsOver = true; + Phase = BattlePhase.Finished; var victoriousPlayer = AllPlayers.FirstOrDefault(); if (victoriousPlayer != null) @@ -767,4 +780,11 @@ namespace GWConquest FullHidden, ClassHidden } + + public enum BattlePhase + { + Command, + Combat, + Finished + } } \ No newline at end of file diff --git a/Assets/GWConquest/Scripts/GameManager.cs b/Assets/GWConquest/Scripts/GameManager.cs index 0a58ee1..dfe6718 100644 --- a/Assets/GWConquest/Scripts/GameManager.cs +++ b/Assets/GWConquest/Scripts/GameManager.cs @@ -28,8 +28,11 @@ namespace GWConquest public float BattleTurnDeviation { get => battleTurnDeviation * TimeScale; } [SerializeField] - private float battlePreparingCooldown; - public float BattlePreparingCooldown { get => battlePreparingCooldown * TimeScale; } + private float battleCommandPhaseLength; + public float BattleCommandPhaseLength { get => battleCommandPhaseLength * TimeScale; } + [SerializeField] + private float battleCombatPhaseLength; + public float BattleCombatPhaseLength { get => battleCombatPhaseLength * TimeScale; } [SerializeField] private float moveToFlankCooldown; diff --git a/Assets/GWConquest/Scripts/Unit.cs b/Assets/GWConquest/Scripts/Unit.cs index b8eab09..fd032db 100644 --- a/Assets/GWConquest/Scripts/Unit.cs +++ b/Assets/GWConquest/Scripts/Unit.cs @@ -464,7 +464,7 @@ namespace GWConquest if (IsSpawned && IsServer) { var battle = CurrentBattle; - if (!IsDead && battle != null && !battle.IsInPreparing) + if (!IsDead && battle != null && battle.Phase == BattlePhase.Combat) { if (BattleState == BattleUnitState.Arriving) {