Esempio n. 1
0
        public override IEnumerable <Status> Run()
        {
            InitializePath();
            if (TrajectoryTimer == null)
            {
                yield break;
            }
            while (!TrajectoryTimer.HasTriggered)
            {
                TrajectoryTimer.Update(DwarfTime.LastTime);
                ValidPathTimer.Update(DwarfTime.LastTime);
                foreach (Status status in PerformCurrentAction())
                {
                    if (status == Status.Fail)
                    {
                        yield return(Status.Fail);
                    }
                    else if (status == Status.Success)
                    {
                        break;
                    }
                    yield return(Status.Running);
                }

                if (Agent.DrawPath)
                {
                    List <Vector3> points =
                        Path.Select(
                            (v, i) => v.Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f) + RandomPositionOffsets[i])
                        .ToList();
                    Drawer3D.DrawLineList(points, Color.Red, 0.1f);
                }


                // Check if the path has been made invalid
                if (ValidPathTimer.HasTriggered && !IsPathValid(Path))
                {
                    Creature.OverrideCharacterMode = false;
                    Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                    yield return(Status.Fail);
                }
                yield return(Status.Running);
            }
            Creature.OverrideCharacterMode = false;
            SetPath(null);
            yield return(Status.Success);
        }
Esempio n. 2
0
        public override IEnumerable <Status> Run()
        {
            InitializePath();
            if (Path == null || Path.Count == 0)
            {
                yield return(Act.Status.Success);
            }
            if (TrajectoryTimer == null)
            {
                yield break;
            }
            while (!TrajectoryTimer.HasTriggered)
            {
                TrajectoryTimer.Update(DwarfTime.LastTime);
                ValidPathTimer.Update(DwarfTime.LastTime);
                foreach (Status status in PerformCurrentAction())
                {
                    if (status == Status.Fail)
                    {
                        yield return(Status.Fail);
                    }
                    else if (status == Status.Success)
                    {
                        break;
                    }
                    yield return(Status.Running);
                }

                if (Agent.DrawPath)
                {
                    List <Vector3> points =
                        Path.Select(
                            (v, i) => v.SourceVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f) + RandomPositionOffsets[i])
                        .ToList();
                    points.Add(Path[Path.Count - 1].DestinationVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f));

                    List <Color> colors =
                        Path.Select((v, i) =>
                    {
                        switch (v.MoveType)
                        {
                        case MoveType.Climb:
                            return(Color.Cyan);

                        case MoveType.ClimbWalls:
                            return(Color.DarkCyan);

                        case MoveType.DestroyObject:
                            return(Color.Orange);

                        case MoveType.Fall:
                            return(Color.LightBlue);

                        case MoveType.Fly:
                            return(Color.Green);

                        case MoveType.Jump:
                            return(Color.Yellow);

                        case MoveType.Swim:
                            return(Color.Blue);

                        case MoveType.Walk:
                            return(Color.Red);
                        }
                        return(Color.White);
                    })
                        .ToList();
                    colors.Add(Color.White);
                    Drawer3D.DrawLineList(points, colors, 0.1f);
                }


                // Check if the path has been made invalid
                if (ValidPathTimer.HasTriggered && !IsPathValid(Path))
                {
                    Creature.OverrideCharacterMode = false;
                    Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                    yield return(Status.Fail);
                }
                yield return(Status.Running);
            }
            Creature.OverrideCharacterMode = false;
            SetPath(null);
            yield return(Status.Success);
        }
Esempio n. 3
0
        public override IEnumerable <Status> Run()
        {
            InitializePath();
            if (Path == null || Path.Count == 0)
            {
                yield return(Act.Status.Success);
            }
            if (TrajectoryTimer == null)
            {
                yield break;
            }
            while (!TrajectoryTimer.HasTriggered)
            {
                Agent.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true);
                TrajectoryTimer.Update(DwarfTime.LastTime);
                ValidPathTimer.Update(DwarfTime.LastTime);
                foreach (Status status in PerformCurrentAction())
                {
                    if (status == Status.Fail)
                    {
                        CleanupMinecart();
                        yield return(Status.Fail);
                    }
                    else if (status == Status.Success)
                    {
                        break;
                    }
                    Creature.Physics.AnimationQueue.Clear();
                    yield return(Status.Running);
                }

                if (Debugger.Switches.DrawPaths)
                {
                    List <Vector3> points =
                        Path.Select(
                            (v, i) => v.SourceVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f) + RandomPositionOffsets[i])
                        .ToList();
                    points.Add(Path[Path.Count - 1].DestinationVoxel.WorldPosition + new Vector3(0.5f, 0.5f, 0.5f));

                    List <Color> colors =
                        Path.Select((v, i) =>
                    {
                        switch (v.MoveType)
                        {
                        case MoveType.Climb:
                            return(Color.Cyan);

                        case MoveType.ClimbWalls:
                            return(Color.DarkCyan);

                        case MoveType.DestroyObject:
                            return(Color.Orange);

                        case MoveType.Fall:
                            return(Color.LightBlue);

                        case MoveType.Fly:
                            return(Color.Green);

                        case MoveType.Jump:
                            return(Color.Yellow);

                        case MoveType.Swim:
                            return(Color.Blue);

                        case MoveType.Walk:
                            return(Color.Red);
                        }
                        return(Color.White);
                    })
                        .ToList();
                    colors.Add(Color.White);
                    Drawer3D.DrawLineList(points, colors, 0.1f);
                }

                float      t            = 0;
                int        currentIndex = 0;
                MoveAction action       = new MoveAction();
                if (GetCurrentAction(ref action, ref t, ref currentIndex))
                {
                    // Check if the path has been made invalid
                    if (ValidPathTimer.HasTriggered && !IsPathValid(Path, currentIndex))
                    {
                        Creature.OverrideCharacterMode = false;
                        Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                        CleanupMinecart();
                        Agent.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true);
                        yield return(Status.Fail);
                    }
                }
                Creature.Physics.AnimationQueue.Clear();
                yield return(Status.Running);
            }
            Creature.OverrideCharacterMode = false;
            SetPath(null);
            Agent.GetRoot().SetFlagRecursive(GameComponent.Flag.Visible, true);
            CleanupMinecart();
            yield return(Status.Success);
        }