예제 #1
0
        protected override void StartJob(Living living)
        {
            Point2D start = living.MapLocation;

            if (start != this.Destination)
            {
                List <PathLink> pth;

                //Handle reroute
                if (living.QueuedMovement.Count > 0)
                {
                    //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                    PathLink previous = living.QueuedMovement.Peek();
                    living.QueuedMovement.Clear();
                    living.QueuedMovement.Enqueue(previous);
                    pth = MainPathFinder.GetRoute(living.Dimension, previous.Destination, this.Destination);
                }
                //No reroute
                else
                {
                    pth = MainPathFinder.GetRoute(living.Dimension, living.MapLocation, this.Destination);
                }

                MagicalLifeAPI.Util.Extensions.EnqueueCollection(living.QueuedMovement, pth);
                ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension));
            }
        }
예제 #2
0
        public override void MakePreparations(Living living)
        {
            ComponentSelectable entityData = living.GetExactComponent <ComponentSelectable>();
            Point2D             start      = entityData.MapLocation;

            if (start != this.Destination)
            {
                List <PathLink>   pth;
                ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>();

                //Handle reroute
                if (movementComponent.QueuedMovement.Count > 0)
                {
                    //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                    PathLink previous = movementComponent.QueuedMovement.Peek();
                    movementComponent.QueuedMovement.Clear();
                    movementComponent.QueuedMovement.Enqueue(previous);
                    pth = MainPathFinder.GetRoute(living.Dimension, previous.Destination, this.Destination);
                }
                //No reroute
                else
                {
                    pth = MainPathFinder.GetRoute(living.Dimension, start, this.Destination);
                }

                MagicalLifeAPI.Util.Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth);
                ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension));
            }
        }
예제 #3
0
        private void Move(Selectable selectable, Microsoft.Xna.Framework.Point target)
        {
            if (World.Dimensions[RenderingPipe.Dimension][target.X, target.Y].IsWalkable)
            {
                switch (selectable)
                {
                case Living living:

                    Microsoft.Xna.Framework.Point start = selectable.MapLocation;
                    if (start != target)
                    {
                        List <PathLink> pth;

                        //Handle reroute
                        if (living.QueuedMovement.Count > 0)
                        {
                            //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                            PathLink previous = living.QueuedMovement.Peek();
                            living.QueuedMovement.Clear();
                            living.QueuedMovement.Enqueue(previous);
                            pth = MainPathFinder.GetRoute(RenderingPipe.Dimension, previous.Destination, target);
                        }
                        //No reroute
                        else
                        {
                            pth = MainPathFinder.GetRoute(RenderingPipe.Dimension, living.MapLocation, target);
                        }

                        Extensions.EnqueueCollection(living.QueuedMovement, pth);
                        ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension));
                    }
                    break;
                }
            }
        }
예제 #4
0
        protected override void StartJob(Living living)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, living.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(living.Dimension, x.X, x.Y).IsWalkable);

            int closestIndex = Algorithms.GetClosestPoint2D(result, living.MapLocation);

            this.AdjacentLocation = result[closestIndex];
            List <PathLink> path = MainPathFinder.GetRoute(living.Dimension, living.MapLocation, result[closestIndex]);

            living.QueuedMovement.Clear();
            Extensions.EnqueueCollection(living.QueuedMovement, path);
        }
예제 #5
0
        public override void MakePreparations(Living l)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, l.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(l.Dimension, x.X, x.Y).IsWalkable);

            int closestIndex = Algorithms.GetClosestPoint2D(result, l.MapLocation);

            this.AdjacentLocation = result[closestIndex];
            List <PathLink> path = MainPathFinder.GetRoute(l.Dimension, l.MapLocation, result[closestIndex]);

            if (World.Data.World.Mode == Networking.EngineMode.ClientOnly)
            {
                ClientSendRecieve.Send(new RouteCreatedMessage(path, l.ID, l.Dimension));
            }

            l.QueuedMovement.Clear();
            Extensions.EnqueueCollection(l.QueuedMovement, path);
        }
예제 #6
0
        private void Move(HasComponents selectable, Point2D target)
        {
            if (World.Dimensions[RenderInfo.Dimension][target.X, target.Y].IsWalkable)
            {
                switch (selectable)
                {
                case Living living:
                    ComponentSelectable positionData = living.GetExactComponent <ComponentSelectable>();
                    Point2D             start        = positionData.MapLocation;
                    if (start != target)
                    {
                        List <PathLink>   pth;
                        ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>();

                        //Handle reroute
                        if (movementComponent.QueuedMovement.Count > 0)
                        {
                            //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                            PathLink previous = movementComponent.QueuedMovement.Peek();
                            movementComponent.QueuedMovement.Clear();
                            movementComponent.QueuedMovement.Enqueue(previous);
                            pth = MainPathFinder.GetRoute(RenderInfo.Dimension, previous.Destination, target);
                        }
                        //No reroute
                        else
                        {
                            pth = MainPathFinder.GetRoute(RenderInfo.Dimension, positionData.MapLocation, target);
                        }

                        Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth);
                    }
                    break;

                default:
                    break;
                }
            }
        }