Browse Source

Bewegung auf Pfaden mit Zwischenstopps

bolt_update
laurids 4 years ago
parent
commit
da87853428
1 changed files with 29 additions and 14 deletions
  1. +29
    -14
      Assets/GWConquest/Scripts/Formation.cs

+ 29
- 14
Assets/GWConquest/Scripts/Formation.cs View File

@ -2,6 +2,7 @@
using System.Linq; using System.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections;
namespace GWConquest namespace GWConquest
{ {
@ -12,12 +13,12 @@ namespace GWConquest
[HideInInspector] [HideInInspector]
public GameObject unitIconPrefab; public GameObject unitIconPrefab;
private Zone _currentZone;
private Zone lastZone;
public Zone currentZone public Zone currentZone
{ {
get get
{ {
return _currentZone;
return Zone.GetFromId(state.CurrentZone);
} }
set set
{ {
@ -28,16 +29,16 @@ namespace GWConquest
private void OnZoneChanged() private void OnZoneChanged()
{ {
Zone newZone = Zone.GetFromId(state.CurrentZone); Zone newZone = Zone.GetFromId(state.CurrentZone);
if(_currentZone != null)
if(lastZone != null)
{ {
_currentZone.OnFormationDeparting(this);
lastZone.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}", _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 public Player Player
@ -102,18 +103,17 @@ namespace GWConquest
public void StartMovingOnPath(List<Zone> path) public void StartMovingOnPath(List<Zone> 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); MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer);
evnt.Formation = entity; evnt.Formation = entity;
evnt.TargetZone = Zone.GetZoneId(path[0]);
if(path.Count > 1)
evnt.TargetZone = Zone.GetZoneId(path[1]);
if(path.Count > 2)
{ {
BoltListToken<Zone> zoneListToken = new BoltListToken<Zone>( BoltListToken<Zone> zoneListToken = new BoltListToken<Zone>(
packet => Zone.GetFromId(packet.ReadInt()), (packet, zone) => packet.WriteInt(Zone.GetZoneId(zone)), 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; evnt.PathQueue = zoneListToken;
} }
@ -192,17 +192,32 @@ namespace GWConquest
{ {
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime;
if (CoveredDistance >= state.CurrentTransition.TransitionLength) if (CoveredDistance >= state.CurrentTransition.TransitionLength)
{
{
currentZone = Zone.GetFromId(state.CurrentTransition.TargetZone); currentZone = Zone.GetFromId(state.CurrentTransition.TargetZone);
state.CurrentTransition.OriginZone = -1; state.CurrentTransition.OriginZone = -1;
state.CurrentTransition.TargetZone = -1; state.CurrentTransition.TargetZone = -1;
state.CurrentTransition.TransitionLength = 0; state.CurrentTransition.TransitionLength = 0;
CoveredDistance = 0; CoveredDistance = 0;
state.IsInTransit = false; 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() private void OnEnable()
{ {


Loading…
Cancel
Save