|
@ -6,25 +6,25 @@ using System.Collections; |
|
|
|
|
|
|
|
|
namespace GWConquest |
|
|
namespace GWConquest |
|
|
{ |
|
|
{ |
|
|
public class Formation : Bolt.EntityBehaviour<IFormationState>, IMovable<Zone> |
|
|
|
|
|
|
|
|
public class Formation : GWBoltBehaviour<IFormationState>, IMovable<Zone> |
|
|
{ |
|
|
{ |
|
|
private Zone lastZone; |
|
|
private Zone lastZone; |
|
|
public Zone currentZone |
|
|
public Zone currentZone |
|
|
{ |
|
|
{ |
|
|
get |
|
|
get |
|
|
{ |
|
|
{ |
|
|
return Zone.GetFromId(state.CurrentZone); |
|
|
|
|
|
|
|
|
return Zone.GetFromId(State.CurrentZone); |
|
|
} |
|
|
} |
|
|
set |
|
|
set |
|
|
{ |
|
|
{ |
|
|
state.CurrentZone = Zone.GetZoneId(value); |
|
|
|
|
|
|
|
|
State.CurrentZone = Zone.GetZoneId(value); |
|
|
OnZoneChanged(); |
|
|
OnZoneChanged(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void OnZoneChanged() |
|
|
private void OnZoneChanged() |
|
|
{ |
|
|
{ |
|
|
Zone newZone = Zone.GetFromId(state.CurrentZone); |
|
|
|
|
|
|
|
|
Zone newZone = Zone.GetFromId(State.CurrentZone); |
|
|
if(lastZone != newZone) |
|
|
if(lastZone != newZone) |
|
|
{ |
|
|
{ |
|
|
if(lastZone != null) |
|
|
if(lastZone != null) |
|
@ -42,27 +42,27 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ZoneType ZoneType { |
|
|
public ZoneType ZoneType { |
|
|
get => state.IsSpace ? ZoneType.Space : ZoneType.Ground; |
|
|
|
|
|
set => state.IsSpace = value == ZoneType.Space; |
|
|
|
|
|
|
|
|
get => State.IsSpace ? ZoneType.Space : ZoneType.Ground; |
|
|
|
|
|
set => State.IsSpace = value == ZoneType.Space; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Player Player |
|
|
public Player Player |
|
|
{ |
|
|
{ |
|
|
get |
|
|
get |
|
|
{ |
|
|
{ |
|
|
return state.Player?.GetComponent<Player>(); |
|
|
|
|
|
|
|
|
return State.Player?.GetComponent<Player>(); |
|
|
} |
|
|
} |
|
|
set |
|
|
set |
|
|
{ |
|
|
{ |
|
|
state.Player = value.entity; |
|
|
|
|
|
|
|
|
State.Player = value.entity; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public string FormationName |
|
|
public string FormationName |
|
|
{ |
|
|
{ |
|
|
get => state.FormationName; |
|
|
|
|
|
|
|
|
get => State.FormationName; |
|
|
set { |
|
|
set { |
|
|
state.FormationName = value; |
|
|
|
|
|
|
|
|
State.FormationName = value; |
|
|
keepFormationName = true; |
|
|
keepFormationName = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -82,8 +82,8 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public Unit HeroUnit |
|
|
public Unit HeroUnit |
|
|
{ |
|
|
{ |
|
|
get => state.HeroUnit?.GetComponent<Unit>(); |
|
|
|
|
|
set => state.HeroUnit = value.entity; |
|
|
|
|
|
|
|
|
get => State.HeroUnit?.GetComponent<Unit>(); |
|
|
|
|
|
set => State.HeroUnit = value.entity; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public IEnumerable<ItemStack> AllItems |
|
|
public IEnumerable<ItemStack> AllItems |
|
@ -99,18 +99,18 @@ namespace GWConquest |
|
|
public ZoneList PathQueue; |
|
|
public ZoneList PathQueue; |
|
|
|
|
|
|
|
|
public Formation MovementTargetFormation { |
|
|
public Formation MovementTargetFormation { |
|
|
get => state.MovementTargetFormation?.GetComponent<Formation>(); |
|
|
|
|
|
set => state.MovementTargetFormation = value?.entity; |
|
|
|
|
|
|
|
|
get => State.MovementTargetFormation?.GetComponent<Formation>(); |
|
|
|
|
|
set => State.MovementTargetFormation = value?.entity; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool IsEmbarked { |
|
|
public bool IsEmbarked { |
|
|
get => state.IsEmbarked; |
|
|
|
|
|
set => state.IsEmbarked = value; |
|
|
|
|
|
|
|
|
get => State.IsEmbarked; |
|
|
|
|
|
set => State.IsEmbarked = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public Formation ParentFormation { |
|
|
public Formation ParentFormation { |
|
|
get => state.ParentFormation?.GetComponent<Formation>(); |
|
|
|
|
|
set => state.ParentFormation = value?.entity; |
|
|
|
|
|
|
|
|
get => State.ParentFormation?.GetComponent<Formation>(); |
|
|
|
|
|
set => State.ParentFormation = value?.entity; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public GameObject fleetIcon; |
|
|
public GameObject fleetIcon; |
|
@ -128,12 +128,12 @@ namespace GWConquest |
|
|
|
|
|
|
|
|
public bool CanMove |
|
|
public bool CanMove |
|
|
{ |
|
|
{ |
|
|
get => !state.IsInTransit; |
|
|
|
|
|
|
|
|
get => !State.IsInTransit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void TryMoveToPlanet(Planet planet) |
|
|
public void TryMoveToPlanet(Planet planet) |
|
|
{ |
|
|
{ |
|
|
if(entity.IsControlled && !state.IsInTransit |
|
|
|
|
|
|
|
|
if(entity.IsControlled && !State.IsInTransit |
|
|
&& currentZone.planet.IsConnectedTo(planet)) |
|
|
&& currentZone.planet.IsConnectedTo(planet)) |
|
|
{ |
|
|
{ |
|
|
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); |
|
|
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); |
|
@ -144,13 +144,13 @@ namespace GWConquest |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2}) to planet {3}", |
|
|
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2}) to planet {3}", |
|
|
this, entity.IsControlled, state.IsInTransit, planet); |
|
|
|
|
|
|
|
|
this, entity.IsControlled, State.IsInTransit, planet); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null) |
|
|
public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null) |
|
|
{ |
|
|
{ |
|
|
if (path.Count > 1 && entity.IsControlled && !state.IsInTransit) |
|
|
|
|
|
|
|
|
if (path.Count > 1 && entity.IsControlled && !State.IsInTransit) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); |
|
|
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); |
|
@ -172,13 +172,13 @@ namespace GWConquest |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2})", |
|
|
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2})", |
|
|
this, entity.IsControlled, state.IsInTransit); |
|
|
|
|
|
|
|
|
this, entity.IsControlled, State.IsInTransit); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void MoveToZone(Zone target) |
|
|
public void MoveToZone(Zone target) |
|
|
{ |
|
|
{ |
|
|
if(entity.IsOwner && !state.IsInTransit) |
|
|
|
|
|
|
|
|
if(entity.IsOwner && !State.IsInTransit) |
|
|
{ |
|
|
{ |
|
|
if(IsEmbarked) |
|
|
if(IsEmbarked) |
|
|
{ |
|
|
{ |
|
@ -188,8 +188,8 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.CurrentTransition.OriginZone = Zone.GetZoneId(currentZone); |
|
|
|
|
|
state.CurrentTransition.TargetZone = Zone.GetZoneId(target); |
|
|
|
|
|
|
|
|
State.CurrentTransition.OriginZone = Zone.GetZoneId(currentZone); |
|
|
|
|
|
State.CurrentTransition.TargetZone = Zone.GetZoneId(target); |
|
|
bool isGroundTransition = target.zoneType == ZoneType.Ground || currentZone.zoneType == ZoneType.Ground; |
|
|
bool isGroundTransition = target.zoneType == ZoneType.Ground || currentZone.zoneType == ZoneType.Ground; |
|
|
//float lengthFactor = isGroundTransition ? GameManager.Instance.GroundTransitionLengthFactor : GameManager.Instance.SpaceTransitionLengthFactor;
|
|
|
//float lengthFactor = isGroundTransition ? GameManager.Instance.GroundTransitionLengthFactor : GameManager.Instance.SpaceTransitionLengthFactor;
|
|
|
float lengthFactor; |
|
|
float lengthFactor; |
|
@ -212,29 +212,29 @@ namespace GWConquest |
|
|
lengthFactor = GameManager.Instance.SpaceTransitionLengthFactor; |
|
|
lengthFactor = GameManager.Instance.SpaceTransitionLengthFactor; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
state.CurrentTransition.TransitionLength |
|
|
|
|
|
|
|
|
State.CurrentTransition.TransitionLength |
|
|
= Vector3.Distance(currentZone.transform.position, target.transform.position) * lengthFactor; |
|
|
= Vector3.Distance(currentZone.transform.position, target.transform.position) * lengthFactor; |
|
|
state.CurrentTransition.IsCurved = isGroundTransition; |
|
|
|
|
|
|
|
|
State.CurrentTransition.IsCurved = isGroundTransition; |
|
|
|
|
|
|
|
|
CoveredDistance = 0; |
|
|
CoveredDistance = 0; |
|
|
currentZone = null; |
|
|
currentZone = null; |
|
|
state.IsInTransit = true; |
|
|
|
|
|
|
|
|
State.IsInTransit = true; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
BoltLog.Warn("Ignoring MoveFormationEvent on {0} (in transit: {1})", this, state.IsInTransit); |
|
|
|
|
|
|
|
|
BoltLog.Warn("Ignoring MoveFormationEvent on {0} (in transit: {1})", this, State.IsInTransit); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void OnTransitStateChanged() |
|
|
private void OnTransitStateChanged() |
|
|
{ |
|
|
{ |
|
|
animDistanceCovered = 0; |
|
|
animDistanceCovered = 0; |
|
|
if(state.IsInTransit) |
|
|
|
|
|
|
|
|
if(State.IsInTransit) |
|
|
{ |
|
|
{ |
|
|
var originZone = Zone.GetFromId(state.CurrentTransition.OriginZone); |
|
|
|
|
|
var targetZone = Zone.GetFromId(state.CurrentTransition.TargetZone); |
|
|
|
|
|
|
|
|
var originZone = Zone.GetFromId(State.CurrentTransition.OriginZone); |
|
|
|
|
|
var targetZone = Zone.GetFromId(State.CurrentTransition.TargetZone); |
|
|
|
|
|
|
|
|
if(state.CurrentTransition.IsCurved) { |
|
|
|
|
|
|
|
|
if(State.CurrentTransition.IsCurved) { |
|
|
movingArmyIcon = Instantiate(movingArmyPrefab); |
|
|
movingArmyIcon = Instantiate(movingArmyPrefab); |
|
|
movingArmyIcon.transform.SetParent(FindObjectOfType<IngameUI>().PlanetView.DistrictIcons); |
|
|
movingArmyIcon.transform.SetParent(FindObjectOfType<IngameUI>().PlanetView.DistrictIcons); |
|
|
movingArmyIcon.transform.localRotation = Quaternion.identity; |
|
|
movingArmyIcon.transform.localRotation = Quaternion.identity; |
|
@ -294,18 +294,18 @@ namespace GWConquest |
|
|
IsEmbarked = false; |
|
|
IsEmbarked = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(state.IsInTransit) |
|
|
|
|
|
|
|
|
if(State.IsInTransit) |
|
|
{ |
|
|
{ |
|
|
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; |
|
|
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; |
|
|
if (CoveredDistance >= state.CurrentTransition.TransitionLength) |
|
|
|
|
|
|
|
|
if (CoveredDistance >= State.CurrentTransition.TransitionLength) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
currentZone = Zone.GetFromId(state.CurrentTransition.TargetZone); |
|
|
|
|
|
state.CurrentTransition.OriginZone = -1; |
|
|
|
|
|
state.CurrentTransition.TargetZone = -1; |
|
|
|
|
|
state.CurrentTransition.TransitionLength = 0; |
|
|
|
|
|
|
|
|
currentZone = Zone.GetFromId(State.CurrentTransition.TargetZone); |
|
|
|
|
|
State.CurrentTransition.OriginZone = -1; |
|
|
|
|
|
State.CurrentTransition.TargetZone = -1; |
|
|
|
|
|
State.CurrentTransition.TransitionLength = 0; |
|
|
CoveredDistance = 0; |
|
|
CoveredDistance = 0; |
|
|
state.IsInTransit = false; |
|
|
|
|
|
|
|
|
State.IsInTransit = false; |
|
|
|
|
|
|
|
|
if(PathQueue.Count > 0) |
|
|
if(PathQueue.Count > 0) |
|
|
{ |
|
|
{ |
|
@ -354,24 +354,24 @@ namespace GWConquest |
|
|
private void Update() |
|
|
private void Update() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
//Debug.LogFormat("Current state: IsInTransit {0}; CurrentZone {1}; CoveredDistance {2}", state.IsInTransit, state.CurrentZone, CoveredDistance);
|
|
|
|
|
|
|
|
|
//Debug.LogFormat("Current state: IsInTransit {0}; CurrentZone {1}; CoveredDistance {2}", State.IsInTransit, State.CurrentZone, CoveredDistance);
|
|
|
|
|
|
|
|
|
if (state.IsInTransit) |
|
|
|
|
|
|
|
|
if (State.IsInTransit) |
|
|
{ |
|
|
{ |
|
|
animDistanceCovered += movementSpeed * Time.deltaTime; |
|
|
animDistanceCovered += movementSpeed * Time.deltaTime; |
|
|
Zone originZone = Zone.GetFromId(state.CurrentTransition.OriginZone); |
|
|
|
|
|
Zone targetZone = Zone.GetFromId(state.CurrentTransition.TargetZone); |
|
|
|
|
|
|
|
|
Zone originZone = Zone.GetFromId(State.CurrentTransition.OriginZone); |
|
|
|
|
|
Zone targetZone = Zone.GetFromId(State.CurrentTransition.TargetZone); |
|
|
Vector3 oldPos = transform.position; |
|
|
Vector3 oldPos = transform.position; |
|
|
Vector3 newPos; |
|
|
Vector3 newPos; |
|
|
Quaternion newRot; |
|
|
Quaternion newRot; |
|
|
//if(state.CurrentTransition.IsCurved)
|
|
|
|
|
|
|
|
|
//if(State.CurrentTransition.IsCurved)
|
|
|
//{
|
|
|
//{
|
|
|
|
|
|
|
|
|
Vector3 planetPos = targetZone.planet.transform.position; |
|
|
Vector3 planetPos = targetZone.planet.transform.position; |
|
|
Vector3 originPos = originZone.transform.position - planetPos; |
|
|
Vector3 originPos = originZone.transform.position - planetPos; |
|
|
Vector3 targetPos = targetZone.transform.position - planetPos; |
|
|
Vector3 targetPos = targetZone.transform.position - planetPos; |
|
|
newPos = Vector3.Slerp(originPos, targetPos, |
|
|
newPos = Vector3.Slerp(originPos, targetPos, |
|
|
animDistanceCovered / state.CurrentTransition.TransitionLength); |
|
|
|
|
|
|
|
|
animDistanceCovered / State.CurrentTransition.TransitionLength); |
|
|
newPos += planetPos; |
|
|
newPos += planetPos; |
|
|
newRot = Quaternion.LookRotation(newPos - oldPos, newPos - planetPos); |
|
|
newRot = Quaternion.LookRotation(newPos - oldPos, newPos - planetPos); |
|
|
//}
|
|
|
//}
|
|
@ -379,7 +379,7 @@ namespace GWConquest |
|
|
//{
|
|
|
//{
|
|
|
newPos = Vector3.Lerp(originZone.transform.position, |
|
|
newPos = Vector3.Lerp(originZone.transform.position, |
|
|
targetZone.transform.position, |
|
|
targetZone.transform.position, |
|
|
animDistanceCovered / state.CurrentTransition.TransitionLength); |
|
|
|
|
|
|
|
|
animDistanceCovered / State.CurrentTransition.TransitionLength); |
|
|
newRot = Quaternion.LookRotation(newPos - oldPos, Vector3.up); |
|
|
newRot = Quaternion.LookRotation(newPos - oldPos, Vector3.up); |
|
|
//}
|
|
|
//}
|
|
|
|
|
|
|
|
@ -396,23 +396,23 @@ namespace GWConquest |
|
|
public override void Attached() |
|
|
public override void Attached() |
|
|
{ |
|
|
{ |
|
|
BoltLog.Info("Formation attached: {0}", this); |
|
|
BoltLog.Info("Formation attached: {0}", this); |
|
|
UnitEntities = new EntityList(state, "Units"); |
|
|
|
|
|
SubFormationEntities = new EntityList(state, "SubFormations"); |
|
|
|
|
|
|
|
|
UnitEntities = new EntityList(State, "Units"); |
|
|
|
|
|
SubFormationEntities = new EntityList(State, "SubFormations"); |
|
|
|
|
|
|
|
|
PathQueue = new ZoneList(state, "PathQueue"); |
|
|
|
|
|
|
|
|
PathQueue = new ZoneList(State, "PathQueue"); |
|
|
|
|
|
|
|
|
if(entity.IsOwner) |
|
|
if(entity.IsOwner) |
|
|
{ |
|
|
{ |
|
|
state.CurrentZone = -1; |
|
|
|
|
|
state.IsInTransit = false; |
|
|
|
|
|
|
|
|
State.CurrentZone = -1; |
|
|
|
|
|
State.IsInTransit = false; |
|
|
CoveredDistance = 0; |
|
|
CoveredDistance = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
formationNumber = UnityEngine.Random.Range(1, 100); |
|
|
formationNumber = UnityEngine.Random.Range(1, 100); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.AddCallback("IsInTransit", OnTransitStateChanged); |
|
|
|
|
|
state.AddCallback("CurrentZone", OnZoneChanged); |
|
|
|
|
|
|
|
|
State.AddCallback("IsInTransit", OnTransitStateChanged); |
|
|
|
|
|
State.AddCallback("CurrentZone", OnZoneChanged); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -563,7 +563,7 @@ namespace GWConquest |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
state.FormationName = name; |
|
|
|
|
|
|
|
|
State.FormationName = name; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|