|
|
@ -9,17 +9,19 @@ using Unity.Netcode; |
|
|
|
|
|
|
|
namespace GWConquest |
|
|
|
{ |
|
|
|
public struct Transition : INetworkSerializeByMemcpy |
|
|
|
public struct Transition : INetworkSerializeByMemcpy |
|
|
|
{ |
|
|
|
public int OriginZoneID; |
|
|
|
public int TargetZoneID; |
|
|
|
public float TransitionLength; |
|
|
|
public bool IsCurved; |
|
|
|
|
|
|
|
public Zone OriginZone { |
|
|
|
public Zone OriginZone |
|
|
|
{ |
|
|
|
get => Zone.GetFromId(OriginZoneID); |
|
|
|
} |
|
|
|
public Zone TargetZone { |
|
|
|
public Zone TargetZone |
|
|
|
{ |
|
|
|
get => Zone.GetFromId(TargetZoneID); |
|
|
|
} |
|
|
|
} |
|
|
@ -66,25 +68,26 @@ namespace GWConquest |
|
|
|
} |
|
|
|
|
|
|
|
private void OnZoneChanged(int previousValue, int newValue) |
|
|
|
{ |
|
|
|
if(previousValue != newValue) |
|
|
|
{ |
|
|
|
if (previousValue != newValue) |
|
|
|
{ |
|
|
|
Zone previousZone = Zone.GetFromId(previousValue); |
|
|
|
Zone newZone = Zone.GetFromId(newValue); |
|
|
|
if(previousZone != null) |
|
|
|
if (previousZone != null) |
|
|
|
{ |
|
|
|
previousZone.OnFormationDeparting(this); |
|
|
|
} |
|
|
|
if(newZone != null) |
|
|
|
if (newZone != null) |
|
|
|
{ |
|
|
|
newZone.OnFormationArrived(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BoltLog.Info("Current zone changed from {0} to {1} on formation {2}", previousZone, newZone, this); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public ZoneType ZoneType { |
|
|
|
public ZoneType ZoneType |
|
|
|
{ |
|
|
|
get => isSpace.Value ? ZoneType.Space : ZoneType.Ground; |
|
|
|
set => isSpace.Value = value == ZoneType.Space; |
|
|
|
} |
|
|
@ -98,7 +101,8 @@ namespace GWConquest |
|
|
|
public string FormationName |
|
|
|
{ |
|
|
|
get => formationName.Value; |
|
|
|
set { |
|
|
|
set |
|
|
|
{ |
|
|
|
formationName.Value = value; |
|
|
|
keepFormationName = true; |
|
|
|
} |
|
|
@ -110,23 +114,28 @@ namespace GWConquest |
|
|
|
|
|
|
|
private Vector3 restingPosition; |
|
|
|
|
|
|
|
public float AnimCompletion { |
|
|
|
public float AnimCompletion |
|
|
|
{ |
|
|
|
get => animDistanceCovered / CurrentTransition.TransitionLength; |
|
|
|
} |
|
|
|
|
|
|
|
public float AnimTimeLeft { |
|
|
|
public float AnimTimeLeft |
|
|
|
{ |
|
|
|
get => (CurrentTransition.TransitionLength - animDistanceCovered) / movementSpeed; |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<Unit> Units { |
|
|
|
public IEnumerable<Unit> Units |
|
|
|
{ |
|
|
|
get => units.Select(r => r.GetBehaviour<Unit>()); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<Formation> SubFormations { |
|
|
|
public IEnumerable<Formation> SubFormations |
|
|
|
{ |
|
|
|
get => units.Select(r => r.GetBehaviour<Formation>()); |
|
|
|
} |
|
|
|
|
|
|
|
public int UnitCount { |
|
|
|
public int UnitCount |
|
|
|
{ |
|
|
|
get => units.Count; |
|
|
|
} |
|
|
|
|
|
|
@ -141,16 +150,19 @@ namespace GWConquest |
|
|
|
get => Units.SelectMany(u => u.Inventory); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<Zone> PathQueue { |
|
|
|
public IEnumerable<Zone> PathQueue |
|
|
|
{ |
|
|
|
get => pathQueue.Select(id => Zone.GetFromId(id)); |
|
|
|
} |
|
|
|
|
|
|
|
public Formation MovementTargetFormation { |
|
|
|
public Formation MovementTargetFormation |
|
|
|
{ |
|
|
|
get => movementTargetFormation.Value.GetBehaviour<Formation>(); |
|
|
|
set => movementTargetFormation.Value = value; |
|
|
|
} |
|
|
|
|
|
|
|
public Formation MovementOriginFormation { |
|
|
|
public Formation MovementOriginFormation |
|
|
|
{ |
|
|
|
get => movementOriginFormation.Value.GetBehaviour<Formation>(); |
|
|
|
set => movementOriginFormation.Value = value; |
|
|
|
} |
|
|
@ -165,61 +177,70 @@ namespace GWConquest |
|
|
|
get => currentTransition.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public bool IsEmbarked { |
|
|
|
public bool IsEmbarked |
|
|
|
{ |
|
|
|
get => isEmbarked.Value; |
|
|
|
set => isEmbarked.Value = value; |
|
|
|
} |
|
|
|
|
|
|
|
public Formation ParentFormation { |
|
|
|
public Formation ParentFormation |
|
|
|
{ |
|
|
|
get => parentFormation.Value.GetBehaviour<Formation>(); |
|
|
|
set => parentFormation.Value = value; |
|
|
|
} |
|
|
|
|
|
|
|
public const float MoraleCap = 27 * 3 * 100; |
|
|
|
|
|
|
|
public float Morale { |
|
|
|
public float Morale |
|
|
|
{ |
|
|
|
get => morale.Value; |
|
|
|
set => morale.Value = value; |
|
|
|
} |
|
|
|
public float StartingMorale { |
|
|
|
public float StartingMorale |
|
|
|
{ |
|
|
|
get => startingMorale.Value; |
|
|
|
set => startingMorale.Value = value; |
|
|
|
} |
|
|
|
|
|
|
|
public FormationMovementState MovementState { |
|
|
|
public FormationMovementState MovementState |
|
|
|
{ |
|
|
|
get => movementState.Value; |
|
|
|
set => movementState.Value = value; |
|
|
|
} |
|
|
|
|
|
|
|
public bool IsMoving { |
|
|
|
public bool IsMoving |
|
|
|
{ |
|
|
|
get => MovementState == FormationMovementState.Moving || |
|
|
|
MovementState == FormationMovementState.PreparingMovement || |
|
|
|
MovementState == FormationMovementState.FinishingMovement; |
|
|
|
} |
|
|
|
|
|
|
|
public float ActionCooldown { |
|
|
|
|
|
|
|
public float ActionCooldown |
|
|
|
{ |
|
|
|
get => actionCooldown.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public float ActionCooldownPercent { |
|
|
|
get =>actionCooldown.Value / actionCooldownMax.Value; |
|
|
|
public float ActionCooldownPercent |
|
|
|
{ |
|
|
|
get => actionCooldown.Value / actionCooldownMax.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public void SetActionCooldown(float value) |
|
|
|
{ |
|
|
|
actionCooldown.Value = value; |
|
|
|
actionCooldownMax.Value = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public GameObject movingArmyPrefab; |
|
|
|
public float movingArmyScale; |
|
|
|
public GameObject movingArmyIcon {get; private set;} |
|
|
|
public GameObject movingArmyIcon { get; private set; } |
|
|
|
|
|
|
|
private Vector3 arrivalPosition; |
|
|
|
|
|
|
|
public float movementSpeed {get => GameManager.Instance.DefaultMovementSpeed;} |
|
|
|
public float movementSpeed { get => GameManager.Instance.DefaultMovementSpeed; } |
|
|
|
|
|
|
|
public int FormationNumber { |
|
|
|
public int FormationNumber |
|
|
|
{ |
|
|
|
get => formationNumber.Value; |
|
|
|
set => formationNumber.Value = value; |
|
|
|
} |
|
|
@ -233,18 +254,20 @@ namespace GWConquest |
|
|
|
get => !IsMoving; |
|
|
|
} |
|
|
|
|
|
|
|
public Planet CurrentPlanet { |
|
|
|
get { |
|
|
|
public Planet CurrentPlanet |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
var z = currentZone; |
|
|
|
if(z != null) |
|
|
|
if (z != null) |
|
|
|
{ |
|
|
|
return z.planet; |
|
|
|
} |
|
|
|
else if(CurrentTransition.OriginZoneID != -1) |
|
|
|
else if (CurrentTransition.OriginZoneID != -1) |
|
|
|
{ |
|
|
|
return CurrentTransition.OriginZone.planet; |
|
|
|
} |
|
|
|
else return null; |
|
|
|
else return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -252,7 +275,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
public void TryMoveToPlanet(Planet planet) |
|
|
|
{ |
|
|
|
if(currentZone.zoneType == ZoneType.Space) |
|
|
|
if (currentZone.zoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
var targetZone = planet.GetMainZone(ZoneType.Space); |
|
|
|
|
|
|
@ -265,27 +288,27 @@ namespace GWConquest |
|
|
|
var pathfindingGraph = targetZone.zoneType == ZoneType.Space ? Planet.PlanetPathfindingGraph : targetZone.planet.pathfindingGraph; |
|
|
|
var shortestPath = pathfindingGraph.FindShortestPath(this, currentZone, targetZone); |
|
|
|
|
|
|
|
if(shortestPath != null) |
|
|
|
if (shortestPath != null) |
|
|
|
{ |
|
|
|
StartMovingOnPath(shortestPath.zones); |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
BoltLog.Warn("No path found between {0} and {1}", currentZone, targetZone); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null) |
|
|
|
public void StartMovingOnPath(List<Zone> path, Formation targetFormation = null) |
|
|
|
{ |
|
|
|
if (path.Count > 1 && IsOwner && CanMove) |
|
|
|
{ |
|
|
|
if(!CanMoveTo(path[0], path[1])) |
|
|
|
if (!CanMoveTo(path[0], path[1])) |
|
|
|
{ |
|
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {path[0]} -> {path[1]}"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int[] zoneIDs = path.GetRange(1, path.Count-1).Select(z => Zone.GetZoneId(z)).ToArray(); |
|
|
|
int[] zoneIDs = path.GetRange(1, path.Count - 1).Select(z => Zone.GetZoneId(z)).ToArray(); |
|
|
|
BeginMovementServerRpc(zoneIDs, targetFormation); |
|
|
|
} |
|
|
|
else |
|
|
@ -297,22 +320,22 @@ namespace GWConquest |
|
|
|
|
|
|
|
public void BeginMovementServer(int[] zoneIDs, Formation targetFormation) |
|
|
|
{ |
|
|
|
|
|
|
|
if(zoneIDs == null) |
|
|
|
|
|
|
|
if (zoneIDs == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException("Movement path is null!"); |
|
|
|
} |
|
|
|
|
|
|
|
Zone firstZone = Zone.GetFromId(zoneIDs[0]); |
|
|
|
if(!CanMoveTo(currentZone,firstZone)) |
|
|
|
if (!CanMoveTo(currentZone, firstZone)) |
|
|
|
{ |
|
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {currentZone} -> {firstZone}"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if(IsEmbarked) |
|
|
|
if (IsEmbarked) |
|
|
|
{ |
|
|
|
if(ParentFormation != null) |
|
|
|
if (ParentFormation != null) |
|
|
|
{ |
|
|
|
MovementOriginFormation = ParentFormation; |
|
|
|
ParentFormation.RemoveSubFormation(this); |
|
|
@ -321,7 +344,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
pathQueue.SetEntries(zoneIDs); |
|
|
|
|
|
|
|
if(targetFormation != null) |
|
|
|
if (targetFormation != null) |
|
|
|
{ |
|
|
|
MovementTargetFormation = targetFormation; |
|
|
|
} |
|
|
@ -330,9 +353,9 @@ namespace GWConquest |
|
|
|
MovementState = FormationMovementState.PreparingMovement; |
|
|
|
} |
|
|
|
|
|
|
|
public void BeginMovementServer(Zone targetZone, Formation targetFormation=null) |
|
|
|
public void BeginMovementServer(Zone targetZone, Formation targetFormation = null) |
|
|
|
{ |
|
|
|
BeginMovementServer(new int[] {Zone.GetZoneId(targetZone)}, targetFormation: targetFormation); |
|
|
|
BeginMovementServer(new int[] { Zone.GetZoneId(targetZone) }, targetFormation: targetFormation); |
|
|
|
} |
|
|
|
|
|
|
|
[ServerRpc] |
|
|
@ -343,27 +366,28 @@ namespace GWConquest |
|
|
|
|
|
|
|
public void MoveToZone(Zone target) |
|
|
|
{ |
|
|
|
if(IsOwner && MovementState == FormationMovementState.PreparingMovement) |
|
|
|
if (IsOwner && MovementState == FormationMovementState.PreparingMovement) |
|
|
|
{ |
|
|
|
if(!CanMoveTo(currentZone, target)) |
|
|
|
if (!CanMoveTo(currentZone, target)) |
|
|
|
{ |
|
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {currentZone} -> {target}"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int remainingFuel = 0; |
|
|
|
foreach(Unit u in Units) |
|
|
|
foreach (Unit u in Units) |
|
|
|
{ |
|
|
|
int fuelRequired = u.GetFuelCostForJump(currentZone, target); |
|
|
|
int totalFuel = u.TotalFuel; |
|
|
|
if(fuelRequired > 0) |
|
|
|
if (fuelRequired > 0) |
|
|
|
{ |
|
|
|
if(totalFuel >= fuelRequired) |
|
|
|
if (totalFuel >= fuelRequired) |
|
|
|
{ |
|
|
|
u.ConsumeTotalFuel(fuelRequired); |
|
|
|
} |
|
|
|
else { |
|
|
|
int diff = fuelRequired -totalFuel; |
|
|
|
else |
|
|
|
{ |
|
|
|
int diff = fuelRequired - totalFuel; |
|
|
|
u.ConsumeTotalFuel(totalFuel); |
|
|
|
remainingFuel += diff; |
|
|
|
} |
|
|
@ -371,32 +395,34 @@ namespace GWConquest |
|
|
|
} |
|
|
|
|
|
|
|
//consume remaining fuel from other ships
|
|
|
|
foreach(Unit u in Units) |
|
|
|
foreach (Unit u in Units) |
|
|
|
{ |
|
|
|
int totalFuel = u.TotalFuel; |
|
|
|
if(totalFuel >= remainingFuel) |
|
|
|
if (totalFuel >= remainingFuel) |
|
|
|
{ |
|
|
|
u.ConsumeTotalFuel(remainingFuel); |
|
|
|
remainingFuel = 0; |
|
|
|
break; |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
u.ConsumeTotalFuel(totalFuel); |
|
|
|
remainingFuel -= totalFuel; |
|
|
|
} |
|
|
|
} |
|
|
|
if(remainingFuel != 0) |
|
|
|
if (remainingFuel != 0) |
|
|
|
{ |
|
|
|
BoltLog.Warn($"There is {remainingFuel} required fuel remaining after consuming everything, this should not happen!"); |
|
|
|
} |
|
|
|
|
|
|
|
currentTransition.Value = new Transition() { |
|
|
|
currentTransition.Value = new Transition() |
|
|
|
{ |
|
|
|
OriginZoneID = Zone.GetZoneId(currentZone), |
|
|
|
TargetZoneID = Zone.GetZoneId(target), |
|
|
|
TransitionLength = Zone.GetTransitionLength(currentZone, target), |
|
|
|
IsCurved = target.zoneType == ZoneType.Ground || currentZone.zoneType == ZoneType.Ground |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
CoveredDistance = 0; |
|
|
|
currentZone = null; |
|
|
|
MovementState = FormationMovementState.Moving; |
|
|
@ -425,7 +451,7 @@ namespace GWConquest |
|
|
|
private void OnTransitStateChanged(FormationMovementState previousValue, FormationMovementState newValue) |
|
|
|
{ |
|
|
|
animDistanceCovered = 0; |
|
|
|
if(newValue == FormationMovementState.Moving) |
|
|
|
if (newValue == FormationMovementState.Moving) |
|
|
|
{ |
|
|
|
var originZone = CurrentTransition.OriginZone; |
|
|
|
var targetZone = CurrentTransition.TargetZone; |
|
|
@ -442,118 +468,120 @@ namespace GWConquest |
|
|
|
arrivalPosition = targetZone.planet.GetFleetArrivalPosition(originZone); |
|
|
|
} |
|
|
|
|
|
|
|
if(originZone.planet == targetZone.planet) |
|
|
|
if (originZone.planet == targetZone.planet) |
|
|
|
{ |
|
|
|
originZone.planet.InTransitFormations.Add(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var planet = currentZone.planet; |
|
|
|
if(planet.InTransitFormations.Contains(this)) |
|
|
|
if (planet.InTransitFormations.Contains(this)) |
|
|
|
{ |
|
|
|
planet.InTransitFormations.Remove(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void FixedUpdate() |
|
|
|
{ |
|
|
|
if(IsServer) |
|
|
|
if (IsServer) |
|
|
|
{ |
|
|
|
if(IsEmbarked) |
|
|
|
{ |
|
|
|
if(ParentFormation != null) |
|
|
|
if (IsEmbarked) |
|
|
|
{ |
|
|
|
if(currentZone != ParentFormation.currentZone) |
|
|
|
if (ParentFormation != null) |
|
|
|
{ |
|
|
|
currentZone = ParentFormation.currentZone; |
|
|
|
if (currentZone != ParentFormation.currentZone) |
|
|
|
{ |
|
|
|
currentZone = ParentFormation.currentZone; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
BoltLog.Error("Formation {0} lost its parent formation {1}!", this, ParentFormation); |
|
|
|
ParentFormation = null; |
|
|
|
IsEmbarked = false; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
BoltLog.Error("Formation {0} lost its parent formation {1}!", this, ParentFormation); |
|
|
|
ParentFormation = null; |
|
|
|
IsEmbarked = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if(MovementState == FormationMovementState.Moving) |
|
|
|
{ |
|
|
|
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; |
|
|
|
if (CoveredDistance >= CurrentTransition.TransitionLength) |
|
|
|
{ |
|
|
|
if (MovementState == FormationMovementState.Moving) |
|
|
|
{ |
|
|
|
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; |
|
|
|
if (CoveredDistance >= CurrentTransition.TransitionLength) |
|
|
|
{ |
|
|
|
|
|
|
|
currentZone = CurrentTransition.TargetZone; |
|
|
|
currentZone = CurrentTransition.TargetZone; |
|
|
|
|
|
|
|
if(currentZone.zoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
fleetRestingPoint.Value = currentZone.planet.GetFleetArrivalPosition(CurrentTransition.OriginZone); |
|
|
|
} |
|
|
|
if (currentZone.zoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
fleetRestingPoint.Value = currentZone.planet.GetFleetArrivalPosition(CurrentTransition.OriginZone); |
|
|
|
} |
|
|
|
|
|
|
|
currentTransition.Value = new Transition() |
|
|
|
{ |
|
|
|
OriginZoneID = -1, |
|
|
|
TargetZoneID = -1, |
|
|
|
TransitionLength = 0 |
|
|
|
}; |
|
|
|
CoveredDistance = 0; |
|
|
|
MovementState = FormationMovementState.FinishingMovement; |
|
|
|
|
|
|
|
SetActionCooldown(GameManager.Instance.MovementFinishedCooldown); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
currentTransition.Value = new Transition() |
|
|
|
{ |
|
|
|
OriginZoneID = -1, |
|
|
|
TargetZoneID = -1, |
|
|
|
TransitionLength = 0 |
|
|
|
}; |
|
|
|
CoveredDistance = 0; |
|
|
|
MovementState = FormationMovementState.FinishingMovement; |
|
|
|
|
|
|
|
if(ActionCooldown <= 0) |
|
|
|
{ |
|
|
|
actionCooldown.Value = 0; |
|
|
|
SetActionCooldown(GameManager.Instance.MovementFinishedCooldown); |
|
|
|
|
|
|
|
if(MovementState == FormationMovementState.PreparingMovement) |
|
|
|
{ |
|
|
|
Zone z = PathQueue.First(); |
|
|
|
pathQueue.RemoveAt(0); |
|
|
|
MoveToZone(z); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(MovementState == FormationMovementState.FinishingMovement) |
|
|
|
|
|
|
|
if (ActionCooldown <= 0) |
|
|
|
{ |
|
|
|
if(pathQueue.Count > 0) |
|
|
|
actionCooldown.Value = 0; |
|
|
|
|
|
|
|
if (MovementState == FormationMovementState.PreparingMovement) |
|
|
|
{ |
|
|
|
if(CanMoveTo(currentZone, PathQueue.First())) |
|
|
|
{ |
|
|
|
SetActionCooldown(GameManager.Instance.MovementStartingCooldown); |
|
|
|
MovementState = FormationMovementState.PreparingMovement; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {currentZone} -> {PathQueue.First()}"); |
|
|
|
pathQueue.Clear(); |
|
|
|
MovementState = FormationMovementState.Idle; |
|
|
|
} |
|
|
|
|
|
|
|
Zone z = PathQueue.First(); |
|
|
|
pathQueue.RemoveAt(0); |
|
|
|
MoveToZone(z); |
|
|
|
} |
|
|
|
else |
|
|
|
else if (MovementState == FormationMovementState.FinishingMovement) |
|
|
|
{ |
|
|
|
if(MovementTargetFormation != null) |
|
|
|
if (pathQueue.Count > 0) |
|
|
|
{ |
|
|
|
if(MovementTargetFormation.HasNetworkObject && MovementTargetFormation.currentZone == currentZone) |
|
|
|
if (CanMoveTo(currentZone, PathQueue.First())) |
|
|
|
{ |
|
|
|
SetActionCooldown(GameManager.Instance.MovementStartingCooldown); |
|
|
|
MovementState = FormationMovementState.PreparingMovement; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
MovementTargetFormation.AddSubFormation(this); |
|
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {currentZone} -> {PathQueue.First()}"); |
|
|
|
pathQueue.Clear(); |
|
|
|
MovementState = FormationMovementState.Idle; |
|
|
|
} |
|
|
|
MovementTargetFormation = null; |
|
|
|
|
|
|
|
} |
|
|
|
if(MovementOriginFormation != null) |
|
|
|
else |
|
|
|
{ |
|
|
|
MovementOriginFormation = null; |
|
|
|
} |
|
|
|
if (MovementTargetFormation != null) |
|
|
|
{ |
|
|
|
if (MovementTargetFormation.HasNetworkObject && MovementTargetFormation.currentZone == currentZone) |
|
|
|
{ |
|
|
|
MovementTargetFormation.AddSubFormation(this); |
|
|
|
} |
|
|
|
MovementTargetFormation = null; |
|
|
|
} |
|
|
|
if (MovementOriginFormation != null) |
|
|
|
{ |
|
|
|
MovementOriginFormation = null; |
|
|
|
} |
|
|
|
|
|
|
|
MovementState = FormationMovementState.Idle; |
|
|
|
MovementState = FormationMovementState.Idle; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
actionCooldown.Value -= Time.fixedDeltaTime; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
actionCooldown.Value -= Time.fixedDeltaTime; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -584,11 +612,12 @@ namespace GWConquest |
|
|
|
{ |
|
|
|
if (currentZone != null && movingArmyIcon == null) |
|
|
|
{ |
|
|
|
if(currentZone.zoneType == ZoneType.Space) |
|
|
|
if (currentZone.zoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
MakeMovingIcon(IngameUI.Instance.MovingFleetsTransform); |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
MakeMovingIcon(IngameUI.Instance.PlanetView.DistrictIcons); |
|
|
|
} |
|
|
|
} |
|
|
@ -680,11 +709,11 @@ namespace GWConquest |
|
|
|
|
|
|
|
if (movingArmyIcon != null) |
|
|
|
{ |
|
|
|
if(ZoneType == ZoneType.Space) |
|
|
|
if (ZoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
if (!IngameUI.PlanetViewEnabled) |
|
|
|
{ |
|
|
|
if(GWCamera.Instance.ShowCircles || MovementState == FormationMovementState.Moving) |
|
|
|
if (GWCamera.Instance.ShowCircles || MovementState == FormationMovementState.Moving) |
|
|
|
{ |
|
|
|
movingArmyIcon.SetActive(true); |
|
|
|
var stick = movingArmyIcon.GetComponent<StickToFormation>(); |
|
|
@ -698,10 +727,11 @@ namespace GWConquest |
|
|
|
movingArmyIcon.SetActive(false); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if(IngameUI.PlanetViewEnabled && IngameUI.Instance.PlanetView.selectedPlanet == CurrentPlanet) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (IngameUI.PlanetViewEnabled && IngameUI.Instance.PlanetView.selectedPlanet == CurrentPlanet) |
|
|
|
{ |
|
|
|
if(MovementState == FormationMovementState.Moving) |
|
|
|
if (MovementState == FormationMovementState.Moving) |
|
|
|
{ |
|
|
|
//movingArmyIcon.SetActive(true);
|
|
|
|
var stick = movingArmyIcon.GetComponent<StickToFormation>(); |
|
|
@ -720,7 +750,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
private Vector3 GetRestingPosition() |
|
|
|
{ |
|
|
|
if(currentZone == null) |
|
|
|
if (currentZone == null) |
|
|
|
return Vector3.zero; |
|
|
|
|
|
|
|
var planet = currentZone.planet; |
|
|
@ -737,7 +767,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
AllFormations.Add(this); |
|
|
|
|
|
|
|
if(IsOwner) |
|
|
|
if (IsOwner) |
|
|
|
{ |
|
|
|
currentZoneID.Value = -1; |
|
|
|
MovementState = FormationMovementState.Idle; |
|
|
@ -750,24 +780,27 @@ namespace GWConquest |
|
|
|
currentZoneID.OnValueChanged += OnZoneChanged; |
|
|
|
|
|
|
|
base.OnNetworkSpawn(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public float GetFormationStrength() |
|
|
|
{ |
|
|
|
if(HasNetworkObject) |
|
|
|
if (HasNetworkObject) |
|
|
|
{ |
|
|
|
return Units.Sum(unit => { |
|
|
|
if(unit != null && unit.HasNetworkObject) |
|
|
|
return Units.Sum(unit => |
|
|
|
{ |
|
|
|
if (unit != null && unit.HasNetworkObject) |
|
|
|
{ |
|
|
|
return unit.Class.UnitStrength; |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
return 0f; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
return 0f; |
|
|
|
} |
|
|
|
} |
|
|
@ -776,31 +809,31 @@ namespace GWConquest |
|
|
|
public void OnUnitAdded(Unit unit) |
|
|
|
{ |
|
|
|
BoltLog.Info("Unit {0} added to formation {1}", unit, this); |
|
|
|
if(currentZone != null) |
|
|
|
if (currentZone != null) |
|
|
|
{ |
|
|
|
currentZone.OnFormationChanged(this); |
|
|
|
} |
|
|
|
if(IsOwner) |
|
|
|
if (IsOwner) |
|
|
|
{ |
|
|
|
if(!keepFormationName) |
|
|
|
if (!keepFormationName) |
|
|
|
{ |
|
|
|
ConstructName(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
OnUnitsChanged?.Invoke(); |
|
|
|
} |
|
|
|
|
|
|
|
public void OnUnitRemoved(Unit unit) |
|
|
|
{ |
|
|
|
OnUnitsChanged?.Invoke(); |
|
|
|
if(IsOwner) |
|
|
|
if (IsOwner) |
|
|
|
{ |
|
|
|
if(!keepFormationName) |
|
|
|
if (!keepFormationName) |
|
|
|
{ |
|
|
|
ConstructName(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void AddSubFormation(Formation f) |
|
|
@ -825,7 +858,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
public event Action OnUnitsChanged; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public float GetModifierForTransition(Zone origin, Zone target) |
|
|
|
{ |
|
|
|
return 1f; |
|
|
@ -833,11 +866,12 @@ namespace GWConquest |
|
|
|
|
|
|
|
public bool CanMoveTo(Zone origin, Zone target) |
|
|
|
{ |
|
|
|
if(origin.zoneType == target.zoneType) |
|
|
|
if (origin.zoneType == target.zoneType) |
|
|
|
{ |
|
|
|
return Units.Sum(u => u.TotalFuel) >= GetFuelCostForJump(origin, target); |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
//TODO Fuel für Landung??
|
|
|
|
return true; |
|
|
|
} |
|
|
@ -850,23 +884,25 @@ namespace GWConquest |
|
|
|
|
|
|
|
public FormationCategory Category |
|
|
|
{ |
|
|
|
get { |
|
|
|
get |
|
|
|
{ |
|
|
|
var units = Units; |
|
|
|
float totalUnits = units.Count(); |
|
|
|
if(ZoneType == ZoneType.Space) |
|
|
|
if (ZoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
return FormationCategory.FleetBattle; |
|
|
|
} |
|
|
|
else { |
|
|
|
if(units.Count(u => u.Class.UnitType == UnitType.Vehicle) / totalUnits >= 0.3) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (units.Count(u => u.Class.UnitType == UnitType.Vehicle) / totalUnits >= 0.3) |
|
|
|
{ |
|
|
|
return FormationCategory.ArmyArmoured; |
|
|
|
} |
|
|
|
else if(units.Count(u => u.Class.UnitType == UnitType.Artillery) / totalUnits >= 0.3) |
|
|
|
else if (units.Count(u => u.Class.UnitType == UnitType.Artillery) / totalUnits >= 0.3) |
|
|
|
{ |
|
|
|
return FormationCategory.ArmyArtillery; |
|
|
|
} |
|
|
|
else if(units.Count(u => u.Class.UnitType == UnitType.Infantry) / totalUnits >= 0.5) |
|
|
|
else if (units.Count(u => u.Class.UnitType == UnitType.Infantry) / totalUnits >= 0.5) |
|
|
|
{ |
|
|
|
return FormationCategory.ArmyInfantry; |
|
|
|
} |
|
|
@ -874,7 +910,7 @@ namespace GWConquest |
|
|
|
{ |
|
|
|
return FormationCategory.ArmyCombined; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -887,47 +923,48 @@ namespace GWConquest |
|
|
|
var units = Units; |
|
|
|
float totalUnits = units.Count(); |
|
|
|
|
|
|
|
if(ZoneType == ZoneType.Ground) |
|
|
|
if (ZoneType == ZoneType.Ground) |
|
|
|
{ |
|
|
|
if(totalUnits < 5) |
|
|
|
if (totalUnits < 5) |
|
|
|
{ |
|
|
|
name += "Company"; |
|
|
|
} |
|
|
|
else if(totalUnits < 10) |
|
|
|
else if (totalUnits < 10) |
|
|
|
{ |
|
|
|
name += "Battalion"; |
|
|
|
} |
|
|
|
else if(totalUnits < 20) |
|
|
|
else if (totalUnits < 20) |
|
|
|
{ |
|
|
|
name += "Division"; |
|
|
|
} |
|
|
|
else if(totalUnits < 40) |
|
|
|
else if (totalUnits < 40) |
|
|
|
{ |
|
|
|
name += "Corps"; |
|
|
|
} |
|
|
|
else if(totalUnits < 60) |
|
|
|
else if (totalUnits < 60) |
|
|
|
{ |
|
|
|
name += "Army"; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if(totalUnits < 5) |
|
|
|
else |
|
|
|
{ |
|
|
|
if (totalUnits < 5) |
|
|
|
{ |
|
|
|
name += "Squadron"; |
|
|
|
} |
|
|
|
else if(totalUnits < 10) |
|
|
|
else if (totalUnits < 10) |
|
|
|
{ |
|
|
|
name += "Flotilla"; |
|
|
|
} |
|
|
|
else if(totalUnits < 20) |
|
|
|
else if (totalUnits < 20) |
|
|
|
{ |
|
|
|
name += "Force"; |
|
|
|
} |
|
|
|
else if(totalUnits < 40) |
|
|
|
else if (totalUnits < 40) |
|
|
|
{ |
|
|
|
name += "Fleet"; |
|
|
|
} |
|
|
|
else if(totalUnits < 60) |
|
|
|
else if (totalUnits < 60) |
|
|
|
{ |
|
|
|
name += "Armada"; |
|
|
|
} |
|
|
@ -943,13 +980,13 @@ namespace GWConquest |
|
|
|
|
|
|
|
public void TakeMoraleDamage(float moraleDamage) |
|
|
|
{ |
|
|
|
if(Morale > 0) |
|
|
|
if (Morale > 0) |
|
|
|
{ |
|
|
|
if(DebugUI.LogBattleEvents) |
|
|
|
if (DebugUI.LogBattleEvents) |
|
|
|
BoltLog.Info("Formation {0} took {1} points of morale damage", this, moraleDamage); |
|
|
|
Morale -= moraleDamage; |
|
|
|
|
|
|
|
if(Morale <= 0) |
|
|
|
if (Morale <= 0) |
|
|
|
{ |
|
|
|
Morale = 0; |
|
|
|
BoltLog.Info("Formation {0} is demoralized and will flee!", this); |
|
|
@ -957,15 +994,15 @@ namespace GWConquest |
|
|
|
|
|
|
|
BeginMovementServer(retreatZone); |
|
|
|
|
|
|
|
foreach(Unit u in Units) |
|
|
|
foreach (Unit u in Units) |
|
|
|
{ |
|
|
|
if(u.CurrentFlank != null) |
|
|
|
if (u.CurrentFlank != null) |
|
|
|
{ |
|
|
|
u.CurrentBattle.MoveUnitToReserve(u); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
PlayFormationDemoralizedAnimation(); |
|
|
|
PlayFormationDemoralizedAnimationClientRpc(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -973,11 +1010,12 @@ namespace GWConquest |
|
|
|
public Zone GetRetreatZone() |
|
|
|
{ |
|
|
|
IEnumerable<Zone> zones; |
|
|
|
if(currentZone.zoneType == ZoneType.Ground) |
|
|
|
if (currentZone.zoneType == ZoneType.Ground) |
|
|
|
{ |
|
|
|
zones = currentZone.planet.pathfindingGraph.GetConnectedNodes(currentZone); |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
zones = Planet.PlanetPathfindingGraph.GetConnectedNodes(currentZone); |
|
|
|
} |
|
|
|
var list = zones.ToList(); |
|
|
@ -993,34 +1031,36 @@ namespace GWConquest |
|
|
|
bool isArriving = MovementState == FormationMovementState.FinishingMovement; |
|
|
|
|
|
|
|
GameManager gm = GameManager.Instance; |
|
|
|
foreach(Unit u in Units) |
|
|
|
foreach (Unit u in Units) |
|
|
|
{ |
|
|
|
u.BattleState = isArriving ? BattleUnitState.Arriving : BattleUnitState.InReserve; |
|
|
|
u.ResetActionCooldown(); |
|
|
|
|
|
|
|
if(!battle.IsSpaceBattle && !u.Class.IsHero) |
|
|
|
|
|
|
|
if (!battle.IsSpaceBattle && !u.Class.IsHero) |
|
|
|
{ |
|
|
|
if(Battle.Check(gm.StartRevealChance)) |
|
|
|
if (Battle.Check(gm.StartRevealChance)) |
|
|
|
{ |
|
|
|
if(Battle.Check(gm.StartFullRevealChance)) |
|
|
|
if (Battle.Check(gm.StartFullRevealChance)) |
|
|
|
{ |
|
|
|
u.RevealState = RevealState.Visible; |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
u.RevealState = RevealState.ClassHidden; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
{ |
|
|
|
u.RevealState = RevealState.FullHidden; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[ClientRpc] |
|
|
|
public void PlayFormationDemoralizedAnimation() |
|
|
|
public void PlayFormationDemoralizedAnimationClientRpc() |
|
|
|
{ |
|
|
|
if(HeroUnit != null && HeroUnit.CurrentIcon != null) |
|
|
|
if (HeroUnit != null && HeroUnit.CurrentIcon != null) |
|
|
|
{ |
|
|
|
HeroUnit.CurrentIcon.PlayDemoralizedAnim(); |
|
|
|
} |
|
|
@ -1028,10 +1068,10 @@ namespace GWConquest |
|
|
|
|
|
|
|
public void RemoveDeadUnits() |
|
|
|
{ |
|
|
|
for(int i = units.Count-1; i >= 0; i--) |
|
|
|
for (int i = units.Count - 1; i >= 0; i--) |
|
|
|
{ |
|
|
|
var unit = units[i].GetBehaviour<Unit>(); |
|
|
|
if(unit.IsDead) |
|
|
|
if (unit.IsDead) |
|
|
|
{ |
|
|
|
units.RemoveAt(i); |
|
|
|
OnUnitRemoved(unit); |
|
|
@ -1047,14 +1087,7 @@ namespace GWConquest |
|
|
|
units.Add(unit); |
|
|
|
} |
|
|
|
|
|
|
|
public static Formation SpawnFormation(Zone zone, Player player) |
|
|
|
{ |
|
|
|
BoltEntity formationEntity = BoltNetwork.Instantiate(BoltPrefabs.Formation); |
|
|
|
player.AssignControl(formationEntity); |
|
|
|
Formation playerFormation = formationEntity.GetComponent<Formation>(); |
|
|
|
playerFormation.Initialize(zone, player); |
|
|
|
return playerFormation; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(Zone zone, Player player) |
|
|
|
{ |
|
|
@ -1063,7 +1096,7 @@ namespace GWConquest |
|
|
|
currentZone = zone; |
|
|
|
ZoneType = zone.zoneType; |
|
|
|
|
|
|
|
if(ZoneType == ZoneType.Space) |
|
|
|
if (ZoneType == ZoneType.Space) |
|
|
|
{ |
|
|
|
Vector3 startPos = zone.planet.GetFleetRestingPosition(); |
|
|
|
fleetRestingPoint.Value = startPos; |
|
|
@ -1071,7 +1104,7 @@ namespace GWConquest |
|
|
|
} |
|
|
|
|
|
|
|
[ServerRpc] |
|
|
|
public void AssignLeaderRpc(NullableNetworkBehaviourReference unit) |
|
|
|
public void AssignLeaderServerRpc(NullableNetworkBehaviourReference unit) |
|
|
|
{ |
|
|
|
heroUnit.Value = unit; |
|
|
|
} |
|
|
@ -1080,13 +1113,14 @@ namespace GWConquest |
|
|
|
{ |
|
|
|
return FormationInventory; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public enum FormationMovementState { |
|
|
|
public enum FormationMovementState |
|
|
|
{ |
|
|
|
Idle, PreparingMovement, FinishingMovement, Moving |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |