Ejemplo n.º 1
0
        public static void AddStep(uint serial, byte speed, Direction movingDir, Direction facingDir, ushort x, ushort y, sbyte z)
        {
            Item item = World.Items.Get(serial);

            if (item == null || item.IsDestroyed)
            {
                return;
            }


            if (!_steps.TryGetValue(serial, out var deque))
            {
                deque          = new Deque <BoatStep>();
                _steps[serial] = deque;
            }

            while (deque.Count >= Constants.MAX_STEP_COUNT)
            {
                deque.RemoveFromFront();
            }


            GetEndPosition(
                item,
                deque,
                out ushort currX,
                out ushort currY,
                out sbyte currZ,
                out Direction endDir);

            if (currX == x && currY == y && currZ == z && endDir == movingDir)
            {
                return;
            }

            if (deque.Count == 0)
            {
                Console.WriteLine("SET TIMER");
                item.LastStepTime = Time.Ticks;
            }


            Direction moveDir = DirectionHelper.CalculateDirection(currX, currY, x, y);

            BoatStep step = new BoatStep();

            step.Serial = serial;
            step.Time   = Time.Ticks;
            step.Speed  = speed;

            if (moveDir != Direction.NONE)
            {
                if (moveDir != endDir)
                {
                    step.X         = currX;
                    step.Y         = currY;
                    step.Z         = currZ;
                    step.MovingDir = moveDir;
                    deque.AddToBack(step);
                }

                step.X         = x;
                step.Y         = y;
                step.Z         = z;
                step.MovingDir = moveDir;
                deque.AddToBack(step);
            }

            if (moveDir != movingDir)
            {
                step.X         = x;
                step.Y         = y;
                step.Z         = z;
                step.MovingDir = movingDir;
                deque.AddToBack(step);
            }

            Console.WriteLine(">>> STEP ADDED {0}", speed);
        }