Browse Source

Battle phases (WIP)

master
laurids 5 months ago
parent
commit
40359c15bf
3 changed files with 46 additions and 23 deletions
  1. +40
    -20
      Assets/GWConquest/Scripts/Battle.cs
  2. +5
    -2
      Assets/GWConquest/Scripts/GameManager.cs
  3. +1
    -1
      Assets/GWConquest/Scripts/Unit.cs

+ 40
- 20
Assets/GWConquest/Scripts/Battle.cs View File

@ -13,9 +13,9 @@ namespace GWConquest
private NetworkVariable<FixedString128Bytes> battleName = new NetworkVariable<FixedString128Bytes>(); private NetworkVariable<FixedString128Bytes> battleName = new NetworkVariable<FixedString128Bytes>();
private GWNetworkList<NullableNetworkBehaviourReference> flanks = new GWNetworkList<NullableNetworkBehaviourReference>(); 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<int> victorID = new NetworkVariable<int>(); private NetworkVariable<int> victorID = new NetworkVariable<int>();
private NetworkVariable<float> preparingCooldown = new NetworkVariable<float>();
private NetworkVariable<float> phaseCooldown = new NetworkVariable<float>();
private NetworkVariable<BattlePhase> battlePhase = new NetworkVariable<BattlePhase>();
public GameObject BattleFlankPrefab; public GameObject BattleFlankPrefab;
@ -125,19 +125,19 @@ namespace GWConquest
public bool IsOver 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 public Player Victor
@ -174,7 +174,8 @@ namespace GWConquest
public void Init() public void Init()
{ {
PreparingCooldown = GameManager.Instance.BattlePreparingCooldown;
Phase = BattlePhase.Command;
PhaseCooldown = GameManager.Instance.BattleCommandPhaseLength;
flankCount.Value = Zone.zoneType == ZoneType.Ground ? 3 : 1; flankCount.Value = Zone.zoneType == ZoneType.Ground ? 3 : 1;
int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 29 : 86; int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 29 : 86;
@ -240,15 +241,8 @@ namespace GWConquest
{ {
if (IsSpawned && IsServer) 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; var gm = GameManager.Instance;
@ -276,6 +270,25 @@ namespace GWConquest
SimulateTurn(); 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() public void SetBattleOver()
{ {
IsOver = true;
Phase = BattlePhase.Finished;
var victoriousPlayer = AllPlayers.FirstOrDefault(); var victoriousPlayer = AllPlayers.FirstOrDefault();
if (victoriousPlayer != null) if (victoriousPlayer != null)
@ -767,4 +780,11 @@ namespace GWConquest
FullHidden, FullHidden,
ClassHidden ClassHidden
} }
public enum BattlePhase
{
Command,
Combat,
Finished
}
} }

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

@ -28,8 +28,11 @@ namespace GWConquest
public float BattleTurnDeviation { get => battleTurnDeviation * TimeScale; } public float BattleTurnDeviation { get => battleTurnDeviation * TimeScale; }
[SerializeField] [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] [SerializeField]
private float moveToFlankCooldown; private float moveToFlankCooldown;


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

@ -464,7 +464,7 @@ namespace GWConquest
if (IsSpawned && IsServer) if (IsSpawned && IsServer)
{ {
var battle = CurrentBattle; var battle = CurrentBattle;
if (!IsDead && battle != null && !battle.IsInPreparing)
if (!IsDead && battle != null && battle.Phase == BattlePhase.Combat)
{ {
if (BattleState == BattleUnitState.Arriving) if (BattleState == BattleUnitState.Arriving)
{ {


Loading…
Cancel
Save