From da87853428ac22056d53a909ab8a016f6cdff3ef Mon Sep 17 00:00:00 2001 From: laurids Date: Sun, 20 Sep 2020 18:43:10 +0200 Subject: [PATCH] Bewegung auf Pfaden mit Zwischenstopps --- Assets/GWConquest/Scripts/Formation.cs | 43 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Assets/GWConquest/Scripts/Formation.cs b/Assets/GWConquest/Scripts/Formation.cs index 63e7d61..04201d8 100644 --- a/Assets/GWConquest/Scripts/Formation.cs +++ b/Assets/GWConquest/Scripts/Formation.cs @@ -2,6 +2,7 @@ using System.Linq; using System; using System.Collections.Generic; +using System.Collections; namespace GWConquest { @@ -12,12 +13,12 @@ namespace GWConquest [HideInInspector] public GameObject unitIconPrefab; - private Zone _currentZone; + private Zone lastZone; public Zone currentZone { get { - return _currentZone; + return Zone.GetFromId(state.CurrentZone); } set { @@ -28,16 +29,16 @@ namespace GWConquest private void OnZoneChanged() { Zone newZone = Zone.GetFromId(state.CurrentZone); - if(_currentZone != null) + if(lastZone != null) { - _currentZone.OnFormationDeparting(this); + lastZone.OnFormationDeparting(this); } if(newZone != null) { newZone.OnFormationArrived(this); } - BoltLog.Info("Current zone changed from {0} to {1} on formation {2}", _currentZone, newZone, this); - _currentZone = newZone; + BoltLog.Info("Current zone changed from {0} to {1} on formation {2}", lastZone, newZone, this); + lastZone = newZone; } public Player Player @@ -102,18 +103,17 @@ namespace GWConquest public void StartMovingOnPath(List path) { - if (path.Count > 0 && entity.IsControlled && !state.IsInTransit) + if (path.Count > 1 && entity.IsControlled && !state.IsInTransit) { - path.Reverse(); + MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); evnt.Formation = entity; - evnt.TargetZone = Zone.GetZoneId(path[0]); - if(path.Count > 1) + evnt.TargetZone = Zone.GetZoneId(path[1]); + if(path.Count > 2) { - BoltListToken zoneListToken = new BoltListToken( packet => Zone.GetFromId(packet.ReadInt()), (packet, zone) => packet.WriteInt(Zone.GetZoneId(zone)), - path.GetRange(1, path.Count-1).ToArray()); + path.GetRange(2, path.Count-2).ToArray()); evnt.PathQueue = zoneListToken; } @@ -192,17 +192,32 @@ namespace GWConquest { CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; if (CoveredDistance >= state.CurrentTransition.TransitionLength) - { + { + currentZone = Zone.GetFromId(state.CurrentTransition.TargetZone); state.CurrentTransition.OriginZone = -1; state.CurrentTransition.TargetZone = -1; state.CurrentTransition.TransitionLength = 0; CoveredDistance = 0; state.IsInTransit = false; + + if(PathQueue.Count > 0) + { + StartCoroutine(ContinueMovingOnPath()); + + } } } } - + + + private IEnumerator ContinueMovingOnPath() + { + yield return new WaitForSeconds(0.1f); + Zone z = PathQueue.First(); + PathQueue.RemoveAt(0); + MoveToZone(z); + } private void OnEnable() {