Esempio n. 1
0
        public override bool Tick(Actor self)
        {
            if (!shouldCancel && (DockActor == null || DockActor.IsDead || !DockActor.IsInWorld || Dock.GetDockAction(DockableActor) == null))
            {
                shouldCancel = true;
            }

            if (ChildActivity != null)
            {
                if (shouldCancel)
                {
                    ChildActivity.Cancel(self);
                }

                if (ChildActivity != null)
                {
                    ChildActivity.Tick(self);
                }
            }

            switch (DockingState)
            {
            case DockingState.Approaching:
                if (shouldCancel)
                {
                    DockingState = DockingState.Undocked;
                    break;
                }

                // TODO does not null when target reached...?
                if (ChildActivity != null)
                {
                    break;
                }

                var distance = (DockableActor.CenterPosition - DockActor.CenterPosition).Length;

                if (distance > WDist.FromCells(Dock.Info.QueueDistance).Length)
                {
                    QueueChild(new Move(DockableActor, Target.FromActor(DockActor), WDist.FromCells(Dock.Info.QueueDistance)));
                }
                else
                {
                    DockingState = DockingState.Waiting;
                    Dock.Add(DockableActor);
                }

                break;

            case DockingState.Waiting:
                if (shouldCancel)
                {
                    DockingState = DockingState.Undocked;
                    Dock.Remove(DockableActor);
                }

                break;

            case DockingState.Docking:
                if (ChildActivity == null)
                {
                    if (shouldCancel)
                    {
                        DockingState = DockingState.Undocked;
                        Dock.Remove(DockableActor);
                    }
                    else
                    {
                        DockingState = DockingState.Docked;
                        Dock.OnDock();
                    }
                }

                break;

            case DockingState.Docked:
                if (shouldCancel)
                {
                    StartUndocking();
                }

                break;

            case DockingState.Undocking:
                if (ChildActivity == null)
                {
                    DockingState = DockingState.Undocked;
                    Dock.Remove(DockableActor);

                    if (!DockActor.IsDead && DockActor.IsInWorld)
                    {
                        var rallyPoint = DockActor.TraitOrDefault <RallyPoint>();
                        if (rallyPoint != null && rallyPoint.Path.Any())
                        {
                            DockableActor.QueueActivity(new Move(DockableActor, rallyPoint.Path.First()));
                        }
                    }
                }

                break;

            case DockingState.Undocked:
                break;
            }

            return(DockingState == DockingState.Undocked && ChildActivity == null);
        }
Esempio n. 2
0
        public override bool Tick(Actor self)
        {
            if ((DockActor.IsDead || !DockActor.IsInWorld || Dock.IsTraitDisabled) && !IsCanceling)
            {
                Cancel(self, true);
            }

            switch (DockingState)
            {
            case DockingState.Approaching:
                if (State == ActivityState.Canceling)
                {
                    return(true);
                }

                if (ChildActivity != null)
                {
                    break;
                }

                var distance = WDist.FromCells(Dock.Info.QueueDistance);

                if ((dockableActor.CenterPosition - DockActor.CenterPosition).Length > distance.Length)
                {
                    QueueChild(new Move(dockableActor, Target.FromActor(DockActor), distance));
                }
                else
                {
                    DockingState = DockingState.Waiting;
                    Dock.Add(dockableActor);
                }

                break;

            case DockingState.Waiting:
                if (State == ActivityState.Canceling)
                {
                    Dock.Remove(dockableActor);
                    return(true);
                }

                break;

            case DockingState.PrepareDocking:
                if (State == ActivityState.Canceling)
                {
                    Dock.Remove(dockableActor);
                    return(true);
                }

                if (ChildActivity != null)
                {
                    break;
                }

                var target = DockActor.World.Map.CellContaining(DockActor.CenterPosition + Dock.Info.Position + Dock.Info.DragOffset);

                if (dockableActor.Location != target)
                {
                    QueueChild(new Move(dockableActor, target));
                }
                else
                {
                    DockingState = DockingState.Docking;

                    QueueChild(new Turn(dockableActor, Dock.Info.Angle));
                    initialPosition = dockableActor.CenterPosition;
                    QueueChild(new Drag(dockableActor, dockableActor.CenterPosition, DockActor.CenterPosition + Dock.Info.Position, Dock.Info.DragLength));
                }

                break;

            case DockingState.Docking:
                if (State == ActivityState.Canceling)
                {
                    StartUndocking();
                    return(false);
                }

                if (ChildActivity == null)
                {
                    DockingState = DockingState.Docked;
                    Dock.OnDock();
                }

                break;

            case DockingState.Docked:
                if (State == ActivityState.Canceling)
                {
                    StartUndocking();
                    return(false);
                }

                break;

            case DockingState.Undocking:
                if (ChildActivity == null)
                {
                    DockingState = DockingState.None;
                    Dock.Remove(dockableActor);

                    if (!DockActor.IsDead && DockActor.IsInWorld)
                    {
                        var rallyPoint = DockActor.TraitOrDefault <RallyPoint>();
                        if (rallyPoint != null && rallyPoint.Path.Any())
                        {
                            foreach (var cell in rallyPoint.Path)
                            {
                                dockableActor.QueueActivity(new Move(dockableActor, cell));
                            }
                        }
                    }
                }

                break;

            case DockingState.None:
                return(true);
            }

            return(false);
        }