示例#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);
        }
示例#2
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 Deque <BoatStep> deque))
            {
                deque          = new Deque <BoatStep>();
                _steps[serial] = deque;
            }

            bool empty = deque.Count == 0;

            while (deque.Count > 5)
            {
                deque.RemoveFromFront();
            }

            //deque.Clear();


            //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 (empty)
            {
                item.LastStepTime = Time.Ticks;
            }

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

            BoatStep step = new BoatStep();

            step.Serial   = serial;
            step.TimeDiff = _timePacket == 0 || empty?GetVelocity(speed) : (int)(Time.Ticks - _timePacket);

            step.Speed     = speed;
            step.X         = x;
            step.Y         = y;
            step.Z         = z;
            step.MovingDir = movingDir;
            deque.AddToBack(step);

            ClearEntities(serial);
            _timePacket = Time.Ticks;
            Console.WriteLine("CURRENT PACKET TIME: {0}", _timePacket);
        }