|
@ -5,62 +5,101 @@ using System.Collections.Generic; |
|
|
using System.Collections; |
|
|
using System.Collections; |
|
|
using Photon.Bolt; |
|
|
using Photon.Bolt; |
|
|
using Photon.Bolt.Utils; |
|
|
using Photon.Bolt.Utils; |
|
|
|
|
|
using Unity.Netcode; |
|
|
|
|
|
|
|
|
namespace GWConquest |
|
|
namespace GWConquest |
|
|
{ |
|
|
{ |
|
|
public class Formation : GWBoltEntityListener<IFormationState>, IMovable<Zone> |
|
|
|
|
|
|
|
|
public struct Transition : INetworkSerializeByMemcpy |
|
|
|
|
|
{ |
|
|
|
|
|
public int OriginZoneID; |
|
|
|
|
|
public int TargetZoneID; |
|
|
|
|
|
public float TransitionLength; |
|
|
|
|
|
public bool IsCurved; |
|
|
|
|
|
|
|
|
|
|
|
public Zone OriginZone { |
|
|
|
|
|
get => Zone.GetFromId(OriginZoneID); |
|
|
|
|
|
} |
|
|
|
|
|
public Zone TargetZone { |
|
|
|
|
|
get => Zone.GetFromId(TargetZoneID); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Formation : NetworkBehaviour, IMovable<Zone> |
|
|
{ |
|
|
{ |
|
|
public static List<Formation> AllFormations = new List<Formation>(); |
|
|
public static List<Formation> AllFormations = new List<Formation>(); |
|
|
|
|
|
|
|
|
private Zone lastZone; |
|
|
|
|
|
|
|
|
private NetworkVariable<int> currentZoneID; |
|
|
|
|
|
private NetworkVariable<bool> isSpace; |
|
|
|
|
|
private NetworkVariable<Transition> currentTransition; |
|
|
|
|
|
private NetworkVariable<NetworkBehaviourReference> player; |
|
|
|
|
|
private GWNetworkList<NetworkBehaviourReference> units; |
|
|
|
|
|
private GWNetworkList<int> pathQueue; |
|
|
|
|
|
private NetworkVariable<NullableNetworkBehaviourReference> currentBattle; |
|
|
|
|
|
private NetworkVariable<NullableNetworkBehaviourReference> heroUnit; |
|
|
|
|
|
private GWNetworkList<NetworkBehaviourReference> subFormations; |
|
|
|
|
|
private NetworkVariable<string> formationName; |
|
|
|
|
|
private NetworkVariable<int> formationNumber; |
|
|
|
|
|
private NetworkVariable<NullableNetworkBehaviourReference> movementTargetFormation; |
|
|
|
|
|
private NetworkVariable<NullableNetworkBehaviourReference> movementOriginFormation; |
|
|
|
|
|
private NetworkVariable<bool> isEmbarked; |
|
|
|
|
|
private NetworkVariable<NullableNetworkBehaviourReference> parentFormation; |
|
|
|
|
|
private NetworkVariable<float> morale; |
|
|
|
|
|
private NetworkVariable<float> startingMorale; |
|
|
|
|
|
private NetworkVariable<FormationMovementState> movementState; |
|
|
|
|
|
private NetworkVariable<float> actionCooldown; |
|
|
|
|
|
private NetworkVariable<float> actionCooldownMax; |
|
|
|
|
|
private NetworkVariable<Vector3> fleetRestingPoint; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Zone currentZone |
|
|
public Zone currentZone |
|
|
{ |
|
|
{ |
|
|
get |
|
|
get |
|
|
{ |
|
|
{ |
|
|
return Zone.GetFromId(State.CurrentZone); |
|
|
|
|
|
|
|
|
return Zone.GetFromId(currentZoneID.Value); |
|
|
} |
|
|
} |
|
|
set |
|
|
set |
|
|
{ |
|
|
{ |
|
|
State.CurrentZone = Zone.GetZoneId(value); |
|
|
|
|
|
OnZoneChanged(); |
|
|
|
|
|
|
|
|
currentZoneID.Value = Zone.GetZoneId(value); |
|
|
|
|
|
//OnZoneChanged();
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void OnZoneChanged() |
|
|
|
|
|
|
|
|
private void OnZoneChanged(int previousValue, int newValue) |
|
|
{ |
|
|
{ |
|
|
Zone newZone = Zone.GetFromId(State.CurrentZone); |
|
|
|
|
|
if(lastZone != newZone) |
|
|
|
|
|
|
|
|
if(previousValue != newValue) |
|
|
{ |
|
|
{ |
|
|
if(lastZone != null) |
|
|
|
|
|
|
|
|
Zone previousZone = Zone.GetFromId(previousValue); |
|
|
|
|
|
Zone newZone = Zone.GetFromId(newValue); |
|
|
|
|
|
if(previousZone != null) |
|
|
{ |
|
|
{ |
|
|
lastZone.OnFormationDeparting(this); |
|
|
|
|
|
|
|
|
previousZone.OnFormationDeparting(this); |
|
|
} |
|
|
} |
|
|
if(newZone != null) |
|
|
if(newZone != null) |
|
|
{ |
|
|
{ |
|
|
newZone.OnFormationArrived(this); |
|
|
newZone.OnFormationArrived(this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
BoltLog.Info("Current zone changed from {0} to {1} on formation {2}", lastZone, newZone, this); |
|
|
|
|
|
lastZone = newZone; |
|
|
|
|
|
|
|
|
BoltLog.Info("Current zone changed from {0} to {1} on formation {2}", previousZone, newZone, this); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ZoneType ZoneType { |
|
|
public ZoneType ZoneType { |
|
|
get => State.IsSpace ? ZoneType.Space : ZoneType.Ground; |
|
|
|
|
|
set => State.IsSpace = value == ZoneType.Space; |
|
|
|
|
|
|
|
|
get => isSpace.Value ? ZoneType.Space : ZoneType.Ground; |
|
|
|
|
|
set => isSpace.Value = value == ZoneType.Space; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Player Player |
|
|
public Player Player |
|
|
{ |
|
|
{ |
|
|
get => BoltEntityCache.Get<Player>(State.Player); |
|
|
|
|
|
set => State.Player = BoltEntityCache.Set(value); |
|
|
|
|
|
|
|
|
get => player.Value.GetBehaviour<Player>(); |
|
|
|
|
|
set => player.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public string FormationName |
|
|
public string FormationName |
|
|
{ |
|
|
{ |
|
|
get => State.FormationName; |
|
|
|
|
|
|
|
|
get => formationName.Value; |
|
|
set { |
|
|
set { |
|
|
State.FormationName = value; |
|
|
|
|
|
|
|
|
formationName.Value = value; |
|
|
keepFormationName = true; |
|
|
keepFormationName = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -72,30 +111,29 @@ namespace GWConquest |
|
|
private Vector3 restingPosition; |
|
|
private Vector3 restingPosition; |
|
|
|
|
|
|
|
|
public float AnimCompletion { |
|
|
public float AnimCompletion { |
|
|
get => animDistanceCovered / State.CurrentTransition.TransitionLength; |
|
|
|
|
|
|
|
|
get => animDistanceCovered / CurrentTransition.TransitionLength; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public float AnimTimeLeft { |
|
|
public float AnimTimeLeft { |
|
|
get => (State.CurrentTransition.TransitionLength - animDistanceCovered) / movementSpeed; |
|
|
|
|
|
|
|
|
get => (CurrentTransition.TransitionLength - animDistanceCovered) / movementSpeed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public EntityList UnitEntities; |
|
|
|
|
|
|
|
|
|
|
|
public EntityList SubFormationEntities; |
|
|
|
|
|
|
|
|
public IEnumerable<Unit> Units { |
|
|
|
|
|
get => units.Select(r => r.GetBehaviour<Unit>()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public IEnumerable<Unit> Units |
|
|
|
|
|
{ |
|
|
|
|
|
get => UnitEntities.Select((e,i) => e.Entity.GetComponent<Unit>()); |
|
|
|
|
|
|
|
|
public IEnumerable<Formation> SubFormations { |
|
|
|
|
|
get => units.Select(r => r.GetBehaviour<Formation>()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int UnitCount { |
|
|
public int UnitCount { |
|
|
get => UnitEntities.Count; |
|
|
|
|
|
|
|
|
get => units.Count; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Unit HeroUnit |
|
|
public Unit HeroUnit |
|
|
{ |
|
|
{ |
|
|
get => BoltEntityCache.Get<Unit>(State.HeroUnit); |
|
|
|
|
|
set => State.HeroUnit = BoltEntityCache.Set(value); |
|
|
|
|
|
|
|
|
get => heroUnit.Value.GetBehaviour<Unit>(); |
|
|
|
|
|
set => heroUnit.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public IEnumerable<ItemStack> AllItems |
|
|
public IEnumerable<ItemStack> AllItems |
|
@ -103,52 +141,54 @@ namespace GWConquest |
|
|
get => Units.SelectMany(u => u.Inventory); |
|
|
get => Units.SelectMany(u => u.Inventory); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public IEnumerable<Formation> SubFormations |
|
|
|
|
|
{ |
|
|
|
|
|
get => SubFormationEntities.Select((e,i) => e.Entity.GetComponent<Formation>()); |
|
|
|
|
|
|
|
|
public IEnumerable<Zone> PathQueue { |
|
|
|
|
|
get => pathQueue.Select(id => Zone.GetFromId(id)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ZoneList PathQueue; |
|
|
|
|
|
|
|
|
|
|
|
public Formation MovementTargetFormation { |
|
|
public Formation MovementTargetFormation { |
|
|
get => BoltEntityCache.Get<Formation>(State.MovementTargetFormation); |
|
|
|
|
|
set => State.MovementTargetFormation = BoltEntityCache.Set(value); |
|
|
|
|
|
|
|
|
get => movementTargetFormation.Value.GetBehaviour<Formation>(); |
|
|
|
|
|
set => movementTargetFormation.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Formation MovementOriginFormation { |
|
|
public Formation MovementOriginFormation { |
|
|
get => BoltEntityCache.Get<Formation>(State.MovementOriginFormation); |
|
|
|
|
|
set => State.MovementOriginFormation = BoltEntityCache.Set(value); |
|
|
|
|
|
|
|
|
get => movementOriginFormation.Value.GetBehaviour<Formation>(); |
|
|
|
|
|
set => movementOriginFormation.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool IsOnSpaceGroundTransition |
|
|
public bool IsOnSpaceGroundTransition |
|
|
{ |
|
|
{ |
|
|
get => MovementState == FormationMovementState.Moving && Zone.GetFromId(State.CurrentTransition.OriginZone).zoneType != Zone.GetFromId(State.CurrentTransition.TargetZone).zoneType; |
|
|
|
|
|
|
|
|
get => MovementState == FormationMovementState.Moving && CurrentTransition.OriginZone.zoneType != CurrentTransition.TargetZone.zoneType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Transition CurrentTransition |
|
|
|
|
|
{ |
|
|
|
|
|
get => currentTransition.Value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool IsEmbarked { |
|
|
public bool IsEmbarked { |
|
|
get => State.IsEmbarked; |
|
|
|
|
|
set => State.IsEmbarked = value; |
|
|
|
|
|
|
|
|
get => isEmbarked.Value; |
|
|
|
|
|
set => isEmbarked.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Formation ParentFormation { |
|
|
public Formation ParentFormation { |
|
|
get => BoltEntityCache.Get<Formation>(State.ParentFormation); |
|
|
|
|
|
set => State.ParentFormation = BoltEntityCache.Set(value); |
|
|
|
|
|
|
|
|
get => parentFormation.Value.GetBehaviour<Formation>(); |
|
|
|
|
|
set => parentFormation.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public const float MoraleCap = 27 * 3 * 100; |
|
|
public const float MoraleCap = 27 * 3 * 100; |
|
|
|
|
|
|
|
|
public float Morale { |
|
|
public float Morale { |
|
|
get => State.Morale; |
|
|
|
|
|
set => State.Morale = value; |
|
|
|
|
|
|
|
|
get => morale.Value; |
|
|
|
|
|
set => morale.Value = value; |
|
|
} |
|
|
} |
|
|
public float StartingMorale { |
|
|
public float StartingMorale { |
|
|
get => State.StartingMorale; |
|
|
|
|
|
set => State.StartingMorale = value; |
|
|
|
|
|
|
|
|
get => startingMorale.Value; |
|
|
|
|
|
set => startingMorale.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public FormationMovementState MovementState { |
|
|
public FormationMovementState MovementState { |
|
|
get => (FormationMovementState) State.MovementState; |
|
|
|
|
|
set => State.MovementState = (int) value; |
|
|
|
|
|
|
|
|
get => movementState.Value; |
|
|
|
|
|
set => movementState.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool IsMoving { |
|
|
public bool IsMoving { |
|
@ -158,17 +198,17 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public float ActionCooldown { |
|
|
public float ActionCooldown { |
|
|
get => State.ActionCooldown; |
|
|
|
|
|
|
|
|
get => actionCooldown.Value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public float ActionCooldownPercent { |
|
|
public float ActionCooldownPercent { |
|
|
get => State.ActionCooldown / State.ActionCooldownMax; |
|
|
|
|
|
|
|
|
get =>actionCooldown.Value / actionCooldownMax.Value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void SetActionCooldown(float value) |
|
|
public void SetActionCooldown(float value) |
|
|
{ |
|
|
{ |
|
|
State.ActionCooldown = value; |
|
|
|
|
|
State.ActionCooldownMax = value; |
|
|
|
|
|
|
|
|
actionCooldown.Value = value; |
|
|
|
|
|
actionCooldownMax.Value = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public GameObject movingArmyPrefab; |
|
|
public GameObject movingArmyPrefab; |
|
@ -180,8 +220,8 @@ namespace GWConquest |
|
|
public float movementSpeed {get => GameManager.Instance.DefaultMovementSpeed;} |
|
|
public float movementSpeed {get => GameManager.Instance.DefaultMovementSpeed;} |
|
|
|
|
|
|
|
|
public int FormationNumber { |
|
|
public int FormationNumber { |
|
|
get => State.FormationNumber; |
|
|
|
|
|
set => State.FormationNumber = value; |
|
|
|
|
|
|
|
|
get => formationNumber.Value; |
|
|
|
|
|
set => formationNumber.Value = value; |
|
|
} |
|
|
} |
|
|
public bool keepFormationName = false; |
|
|
public bool keepFormationName = false; |
|
|
|
|
|
|
|
@ -200,9 +240,9 @@ namespace GWConquest |
|
|
{ |
|
|
{ |
|
|
return z.planet; |
|
|
return z.planet; |
|
|
} |
|
|
} |
|
|
else if(State.CurrentTransition.OriginZone != -1) |
|
|
|
|
|
|
|
|
else if(CurrentTransition.OriginZoneID != -1) |
|
|
{ |
|
|
{ |
|
|
return Zone.GetFromId(State.CurrentTransition.OriginZone).planet; |
|
|
|
|
|
|
|
|
return CurrentTransition.OriginZone.planet; |
|
|
} |
|
|
} |
|
|
else return null; |
|
|
else return null; |
|
|
} |
|
|
} |
|
@ -237,7 +277,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null) |
|
|
public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null) |
|
|
{ |
|
|
{ |
|
|
if (path.Count > 1 && entity.IsControlled && CanMove) |
|
|
|
|
|
|
|
|
if (path.Count > 1 && IsOwner && CanMove) |
|
|
{ |
|
|
{ |
|
|
if(!CanMoveTo(path[0], path[1])) |
|
|
if(!CanMoveTo(path[0], path[1])) |
|
|
{ |
|
|
{ |
|
@ -282,14 +322,14 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
if(IsEmbarked) |
|
|
if(IsEmbarked) |
|
|
{ |
|
|
{ |
|
|
if(ParentFormation != null && ParentFormation.entity.IsAttached) |
|
|
|
|
|
|
|
|
if(ParentFormation != null) |
|
|
{ |
|
|
{ |
|
|
MovementOriginFormation = ParentFormation; |
|
|
MovementOriginFormation = ParentFormation; |
|
|
ParentFormation.RemoveSubFormation(this); |
|
|
ParentFormation.RemoveSubFormation(this); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PathQueue.SetEntries(path); |
|
|
|
|
|
|
|
|
pathQueue.SetEntries(path.Select(z => Zone.GetZoneId(z))); |
|
|
|
|
|
|
|
|
if(targetFormation != null) |
|
|
if(targetFormation != null) |
|
|
{ |
|
|
{ |
|
@ -307,7 +347,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public void MoveToZone(Zone target) |
|
|
public void MoveToZone(Zone target) |
|
|
{ |
|
|
{ |
|
|
if(entity.IsOwner && MovementState == FormationMovementState.PreparingMovement) |
|
|
|
|
|
|
|
|
if(IsOwner && MovementState == FormationMovementState.PreparingMovement) |
|
|
{ |
|
|
{ |
|
|
if(!CanMoveTo(currentZone, target)) |
|
|
if(!CanMoveTo(currentZone, target)) |
|
|
{ |
|
|
{ |
|
@ -354,12 +394,12 @@ namespace GWConquest |
|
|
BoltLog.Warn($"There is {remainingFuel} required fuel remaining after consuming everything, this should not happen!"); |
|
|
BoltLog.Warn($"There is {remainingFuel} required fuel remaining after consuming everything, this should not happen!"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
State.CurrentTransition.OriginZone = Zone.GetZoneId(currentZone); |
|
|
|
|
|
State.CurrentTransition.TargetZone = Zone.GetZoneId(target); |
|
|
|
|
|
bool isGroundTransition = target.zoneType == ZoneType.Ground || currentZone.zoneType == ZoneType.Ground; |
|
|
|
|
|
//float lengthFactor = isGroundTransition ? GameManager.Instance.GroundTransitionLengthFactor : GameManager.Instance.SpaceTransitionLengthFactor;
|
|
|
|
|
|
State.CurrentTransition.TransitionLength = Zone.GetTransitionLength(currentZone, target); |
|
|
|
|
|
State.CurrentTransition.IsCurved = isGroundTransition; |
|
|
|
|
|
|
|
|
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; |
|
|
CoveredDistance = 0; |
|
|
currentZone = null; |
|
|
currentZone = null; |
|
@ -386,15 +426,15 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void OnTransitStateChanged() |
|
|
|
|
|
|
|
|
private void OnTransitStateChanged(FormationMovementState previousValue, FormationMovementState newValue) |
|
|
{ |
|
|
{ |
|
|
animDistanceCovered = 0; |
|
|
animDistanceCovered = 0; |
|
|
if(MovementState == FormationMovementState.Moving) |
|
|
|
|
|
|
|
|
if(newValue == FormationMovementState.Moving) |
|
|
{ |
|
|
{ |
|
|
var originZone = Zone.GetFromId(State.CurrentTransition.OriginZone); |
|
|
|
|
|
var targetZone = Zone.GetFromId(State.CurrentTransition.TargetZone); |
|
|
|
|
|
|
|
|
var originZone = CurrentTransition.OriginZone; |
|
|
|
|
|
var targetZone = CurrentTransition.TargetZone; |
|
|
|
|
|
|
|
|
if (State.CurrentTransition.IsCurved) |
|
|
|
|
|
|
|
|
if (CurrentTransition.IsCurved) |
|
|
{ |
|
|
{ |
|
|
if (IsOnSpaceGroundTransition && IngameUI.PlanetViewEnabled) |
|
|
if (IsOnSpaceGroundTransition && IngameUI.PlanetViewEnabled) |
|
|
{ |
|
|
{ |
|
@ -423,11 +463,13 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override void SimulateOwner() |
|
|
|
|
|
|
|
|
public void FixedUpdate() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(IsServer) |
|
|
|
|
|
{ |
|
|
if(IsEmbarked) |
|
|
if(IsEmbarked) |
|
|
{ |
|
|
{ |
|
|
if(ParentFormation != null && ParentFormation.entity.IsAttached) |
|
|
|
|
|
|
|
|
if(ParentFormation != null) |
|
|
{ |
|
|
{ |
|
|
if(currentZone != ParentFormation.currentZone) |
|
|
if(currentZone != ParentFormation.currentZone) |
|
|
{ |
|
|
{ |
|
@ -443,19 +485,22 @@ namespace GWConquest |
|
|
if(MovementState == FormationMovementState.Moving) |
|
|
if(MovementState == FormationMovementState.Moving) |
|
|
{ |
|
|
{ |
|
|
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; |
|
|
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; |
|
|
if (CoveredDistance >= State.CurrentTransition.TransitionLength) |
|
|
|
|
|
|
|
|
if (CoveredDistance >= CurrentTransition.TransitionLength) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
currentZone = Zone.GetFromId(State.CurrentTransition.TargetZone); |
|
|
|
|
|
|
|
|
currentZone = CurrentTransition.TargetZone; |
|
|
|
|
|
|
|
|
if(currentZone.zoneType == ZoneType.Space) |
|
|
if(currentZone.zoneType == ZoneType.Space) |
|
|
{ |
|
|
{ |
|
|
State.FleetRestingPoint = currentZone.planet.GetFleetArrivalPosition(Zone.GetFromId(State.CurrentTransition.OriginZone)); |
|
|
|
|
|
|
|
|
fleetRestingPoint.Value = currentZone.planet.GetFleetArrivalPosition(CurrentTransition.OriginZone); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
State.CurrentTransition.OriginZone = -1; |
|
|
|
|
|
State.CurrentTransition.TargetZone = -1; |
|
|
|
|
|
State.CurrentTransition.TransitionLength = 0; |
|
|
|
|
|
|
|
|
currentTransition.Value = new Transition() |
|
|
|
|
|
{ |
|
|
|
|
|
OriginZoneID = -1, |
|
|
|
|
|
TargetZoneID = -1, |
|
|
|
|
|
TransitionLength = 0 |
|
|
|
|
|
}; |
|
|
CoveredDistance = 0; |
|
|
CoveredDistance = 0; |
|
|
MovementState = FormationMovementState.FinishingMovement; |
|
|
MovementState = FormationMovementState.FinishingMovement; |
|
|
|
|
|
|
|
@ -466,27 +511,27 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
if(ActionCooldown <= 0) |
|
|
if(ActionCooldown <= 0) |
|
|
{ |
|
|
{ |
|
|
State.ActionCooldown = 0; |
|
|
|
|
|
|
|
|
actionCooldown.Value = 0; |
|
|
|
|
|
|
|
|
if(MovementState == FormationMovementState.PreparingMovement) |
|
|
if(MovementState == FormationMovementState.PreparingMovement) |
|
|
{ |
|
|
{ |
|
|
Zone z = PathQueue.First(); |
|
|
Zone z = PathQueue.First(); |
|
|
PathQueue.RemoveAt(0); |
|
|
|
|
|
|
|
|
pathQueue.RemoveAt(0); |
|
|
MoveToZone(z); |
|
|
MoveToZone(z); |
|
|
} |
|
|
} |
|
|
else if(MovementState == FormationMovementState.FinishingMovement) |
|
|
else if(MovementState == FormationMovementState.FinishingMovement) |
|
|
{ |
|
|
{ |
|
|
if(PathQueue.Count > 0) |
|
|
|
|
|
|
|
|
if(pathQueue.Count > 0) |
|
|
{ |
|
|
{ |
|
|
if(CanMoveTo(currentZone, PathQueue[0])) |
|
|
|
|
|
|
|
|
if(CanMoveTo(currentZone, PathQueue.First())) |
|
|
{ |
|
|
{ |
|
|
SetActionCooldown(GameManager.Instance.MovementStartingCooldown); |
|
|
SetActionCooldown(GameManager.Instance.MovementStartingCooldown); |
|
|
MovementState = FormationMovementState.PreparingMovement; |
|
|
MovementState = FormationMovementState.PreparingMovement; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {currentZone} -> {PathQueue[0]}"); |
|
|
|
|
|
PathQueue.Clear(); |
|
|
|
|
|
|
|
|
BoltLog.Info($"Formation {this} has not enough fuel for transition {currentZone} -> {PathQueue.First()}"); |
|
|
|
|
|
pathQueue.Clear(); |
|
|
MovementState = FormationMovementState.Idle; |
|
|
MovementState = FormationMovementState.Idle; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -495,7 +540,7 @@ namespace GWConquest |
|
|
{ |
|
|
{ |
|
|
if(MovementTargetFormation != null) |
|
|
if(MovementTargetFormation != null) |
|
|
{ |
|
|
{ |
|
|
if(MovementTargetFormation.entity.IsAttached && MovementTargetFormation.currentZone == currentZone) |
|
|
|
|
|
|
|
|
if(MovementTargetFormation.HasNetworkObject && MovementTargetFormation.currentZone == currentZone) |
|
|
{ |
|
|
{ |
|
|
MovementTargetFormation.AddSubFormation(this); |
|
|
MovementTargetFormation.AddSubFormation(this); |
|
|
} |
|
|
} |
|
@ -511,7 +556,8 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
State.ActionCooldown -= BoltNetwork.FrameDeltaTime; |
|
|
|
|
|
|
|
|
actionCooldown.Value -= Time.fixedDeltaTime; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -536,7 +582,7 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
private void Update() |
|
|
private void Update() |
|
|
{ |
|
|
{ |
|
|
if (entity.IsAttached) |
|
|
|
|
|
|
|
|
if (HasNetworkObject) |
|
|
{ |
|
|
{ |
|
|
if (GameManager.EntitiesLoaded) |
|
|
if (GameManager.EntitiesLoaded) |
|
|
{ |
|
|
{ |
|
@ -556,13 +602,13 @@ namespace GWConquest |
|
|
if (MovementState == FormationMovementState.Moving) |
|
|
if (MovementState == FormationMovementState.Moving) |
|
|
{ |
|
|
{ |
|
|
animDistanceCovered += movementSpeed * Time.deltaTime; |
|
|
animDistanceCovered += movementSpeed * Time.deltaTime; |
|
|
Zone originZone = Zone.GetFromId(State.CurrentTransition.OriginZone); |
|
|
|
|
|
Zone targetZone = Zone.GetFromId(State.CurrentTransition.TargetZone); |
|
|
|
|
|
|
|
|
Zone originZone = CurrentTransition.OriginZone; |
|
|
|
|
|
Zone targetZone = CurrentTransition.TargetZone; |
|
|
|
|
|
|
|
|
Vector3 originPos = originZone.transform.position; |
|
|
Vector3 originPos = originZone.transform.position; |
|
|
Vector3 targetPos = targetZone.transform.position; |
|
|
Vector3 targetPos = targetZone.transform.position; |
|
|
|
|
|
|
|
|
if (!State.CurrentTransition.IsCurved) |
|
|
|
|
|
|
|
|
if (!CurrentTransition.IsCurved) |
|
|
{ |
|
|
{ |
|
|
originPos += originZone.planet.GetFleetArrivalPosition(targetZone) * originZone.planet.GetCurrentCircleRadius(); |
|
|
originPos += originZone.planet.GetFleetArrivalPosition(targetZone) * originZone.planet.GetCurrentCircleRadius(); |
|
|
targetPos += targetZone.planet.GetFleetArrivalPosition(originZone) * targetZone.planet.GetCurrentCircleRadius(); |
|
|
targetPos += targetZone.planet.GetFleetArrivalPosition(originZone) * targetZone.planet.GetCurrentCircleRadius(); |
|
@ -588,7 +634,7 @@ namespace GWConquest |
|
|
//{
|
|
|
//{
|
|
|
newPos = Vector3.Lerp(originPos, |
|
|
newPos = Vector3.Lerp(originPos, |
|
|
targetPos, |
|
|
targetPos, |
|
|
animDistanceCovered / State.CurrentTransition.TransitionLength); |
|
|
|
|
|
|
|
|
animDistanceCovered / CurrentTransition.TransitionLength); |
|
|
newRot = Quaternion.LookRotation(newPos - oldPos, Vector3.up); |
|
|
newRot = Quaternion.LookRotation(newPos - oldPos, Vector3.up); |
|
|
//}
|
|
|
//}
|
|
|
|
|
|
|
|
@ -684,43 +730,41 @@ namespace GWConquest |
|
|
var planet = currentZone.planet; |
|
|
var planet = currentZone.planet; |
|
|
float currentCircleRadius = planet.GetCurrentCircleRadius(); |
|
|
float currentCircleRadius = planet.GetCurrentCircleRadius(); |
|
|
|
|
|
|
|
|
return planet.transform.position + State.FleetRestingPoint * 0.5f * currentCircleRadius; |
|
|
|
|
|
|
|
|
return planet.transform.position + fleetRestingPoint.Value * 0.5f * currentCircleRadius; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override void Attached() |
|
|
|
|
|
|
|
|
public override void OnNetworkSpawn() |
|
|
{ |
|
|
{ |
|
|
BoltLog.Info("Formation attached: {0}", this); |
|
|
BoltLog.Info("Formation attached: {0}", this); |
|
|
UnitEntities = new EntityList(State, "Units"); |
|
|
|
|
|
SubFormationEntities = new EntityList(State, "SubFormations"); |
|
|
|
|
|
|
|
|
|
|
|
FormationInventory = new CombinedInventory(() => Units.Select(u => u.Inventory)); |
|
|
FormationInventory = new CombinedInventory(() => Units.Select(u => u.Inventory)); |
|
|
|
|
|
|
|
|
PathQueue = new ZoneList(State, "PathQueue"); |
|
|
|
|
|
|
|
|
|
|
|
AllFormations.Add(this); |
|
|
AllFormations.Add(this); |
|
|
|
|
|
|
|
|
if(entity.IsOwner) |
|
|
|
|
|
|
|
|
if(IsOwner) |
|
|
{ |
|
|
{ |
|
|
State.CurrentZone = -1; |
|
|
|
|
|
|
|
|
currentZoneID.Value = -1; |
|
|
MovementState = FormationMovementState.Idle; |
|
|
MovementState = FormationMovementState.Idle; |
|
|
CoveredDistance = 0; |
|
|
CoveredDistance = 0; |
|
|
|
|
|
|
|
|
FormationNumber = UnityEngine.Random.Range(1, 100); |
|
|
FormationNumber = UnityEngine.Random.Range(1, 100); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
State.AddCallback("MovementState", OnTransitStateChanged); |
|
|
|
|
|
State.AddCallback("CurrentZone", OnZoneChanged); |
|
|
|
|
|
|
|
|
movementState.OnValueChanged += OnTransitStateChanged; |
|
|
|
|
|
currentZoneID.OnValueChanged += OnZoneChanged; |
|
|
|
|
|
|
|
|
|
|
|
base.OnNetworkSpawn(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public float GetFormationStrength() |
|
|
public float GetFormationStrength() |
|
|
{ |
|
|
{ |
|
|
if(entity.IsAttached) |
|
|
|
|
|
|
|
|
if(HasNetworkObject) |
|
|
{ |
|
|
{ |
|
|
return UnitEntities.Sum(unit => { |
|
|
|
|
|
if(unit.Entity != null && unit.Entity.IsAttached) |
|
|
|
|
|
|
|
|
return Units.Sum(unit => { |
|
|
|
|
|
if(unit != null && unit.HasNetworkObject) |
|
|
{ |
|
|
{ |
|
|
return unit.Entity.GetComponent<Unit>().Class.UnitStrength; |
|
|
|
|
|
|
|
|
return unit.Class.UnitStrength; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return 0f; |
|
|
return 0f; |
|
@ -740,7 +784,7 @@ namespace GWConquest |
|
|
{ |
|
|
{ |
|
|
currentZone.OnFormationChanged(this); |
|
|
currentZone.OnFormationChanged(this); |
|
|
} |
|
|
} |
|
|
if(entity.IsOwner) |
|
|
|
|
|
|
|
|
if(IsOwner) |
|
|
{ |
|
|
{ |
|
|
if(!keepFormationName) |
|
|
if(!keepFormationName) |
|
|
{ |
|
|
{ |
|
@ -754,7 +798,7 @@ namespace GWConquest |
|
|
public void OnUnitRemoved(Unit unit) |
|
|
public void OnUnitRemoved(Unit unit) |
|
|
{ |
|
|
{ |
|
|
OnUnitsChanged?.Invoke(); |
|
|
OnUnitsChanged?.Invoke(); |
|
|
if(entity.IsOwner) |
|
|
|
|
|
|
|
|
if(IsOwner) |
|
|
{ |
|
|
{ |
|
|
if(!keepFormationName) |
|
|
if(!keepFormationName) |
|
|
{ |
|
|
{ |
|
@ -765,14 +809,14 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public void AddSubFormation(Formation f) |
|
|
public void AddSubFormation(Formation f) |
|
|
{ |
|
|
{ |
|
|
SubFormationEntities.Add(f.entity); |
|
|
|
|
|
|
|
|
subFormations.Add(f); |
|
|
f.ParentFormation = this; |
|
|
f.ParentFormation = this; |
|
|
f.IsEmbarked = true; |
|
|
f.IsEmbarked = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void RemoveSubFormation(Formation f) |
|
|
public void RemoveSubFormation(Formation f) |
|
|
{ |
|
|
{ |
|
|
SubFormationEntities.Remove(f.entity); |
|
|
|
|
|
|
|
|
subFormations.Remove(f); |
|
|
f.ParentFormation = null; |
|
|
f.ParentFormation = null; |
|
|
f.IsEmbarked = false; |
|
|
f.IsEmbarked = false; |
|
|
} |
|
|
} |
|
@ -893,7 +937,7 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
State.FormationName = name; |
|
|
|
|
|
|
|
|
formationName.Value = name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
public override string ToString() |
|
@ -957,7 +1001,7 @@ namespace GWConquest |
|
|
foreach(Unit u in Units) |
|
|
foreach(Unit u in Units) |
|
|
{ |
|
|
{ |
|
|
u.BattleState = isArriving ? BattleUnitState.Arriving : BattleUnitState.InReserve; |
|
|
u.BattleState = isArriving ? BattleUnitState.Arriving : BattleUnitState.InReserve; |
|
|
u.state.ActionCooldown = 0; |
|
|
|
|
|
|
|
|
u.ResetActionCooldown(); |
|
|
|
|
|
|
|
|
if(!battle.IsSpaceBattle && !u.Class.IsHero) |
|
|
if(!battle.IsSpaceBattle && !u.Class.IsHero) |
|
|
{ |
|
|
{ |
|
@ -988,12 +1032,12 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public void RemoveDeadUnits() |
|
|
public void RemoveDeadUnits() |
|
|
{ |
|
|
{ |
|
|
for(int i = UnitEntities.Count-1; i >= 0; i--) |
|
|
|
|
|
|
|
|
for(int i = units.Count-1; i >= 0; i--) |
|
|
{ |
|
|
{ |
|
|
var unit = UnitEntities[i].Entity.GetComponent<Unit>(); |
|
|
|
|
|
|
|
|
var unit = units[i].GetBehaviour<Unit>(); |
|
|
if(unit.IsDead) |
|
|
if(unit.IsDead) |
|
|
{ |
|
|
{ |
|
|
UnitEntities.RemoveAt(i); |
|
|
|
|
|
|
|
|
units.RemoveAt(i); |
|
|
OnUnitRemoved(unit); |
|
|
OnUnitRemoved(unit); |
|
|
|
|
|
|
|
|
BoltNetwork.Destroy(unit.gameObject); |
|
|
BoltNetwork.Destroy(unit.gameObject); |
|
@ -1002,7 +1046,33 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void AddUnit(Unit unit) |
|
|
|
|
|
{ |
|
|
|
|
|
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) |
|
|
|
|
|
{ |
|
|
|
|
|
gameObject.name = "Formation_" + NetworkObjectId.ToString(); |
|
|
|
|
|
Player = player; |
|
|
|
|
|
currentZone = zone; |
|
|
|
|
|
ZoneType = zone.zoneType; |
|
|
|
|
|
|
|
|
|
|
|
if(ZoneType == ZoneType.Space) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 startPos = zone.planet.GetFleetRestingPosition(); |
|
|
|
|
|
fleetRestingPoint.Value = startPos; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|