Ejemplo n.º 1
0
        public Vector2S GetMove(short distance, Vector2S towards)
        {
            Vector2S ret = new Vector2S(x, z);

            ret.Move(distance, towards);
            return(ret);
        }
Ejemplo n.º 2
0
        public void Move(short distance, Vector2S towards)
        {
            Vector2S way    = towards - this;
            double   length = way.Length;

            x += (short)Math.Round(((way.x / length) * distance));
            z += (short)Math.Round(((way.z / length) * distance));
        }
Ejemplo n.º 3
0
 public void Move(short distance, Vector2S towards)
 {
     Vector2S way = towards - this;
     double length = way.Length;
     x += (short)Math.Round(((way.x / length) * distance));
     z += (short)Math.Round(((way.z / length) * distance));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the position of the spawn point.
 /// </summary>
 /// <param name="manualPosition">The position.</param>
 /// <param name="angleRot">The angle rotation.</param>
 public void SetPosition(Vector3S manualPosition, Vector2S angleRot)
 {
     Level.CWMap.SpawnPos = manualPosition;
     Level.CWMap.SpawnRotation = angleRot;
 }
Ejemplo n.º 5
0
 public Vector2S GetMove(short distance, Vector2S towards)
 {
     Vector2S ret = new Vector2S(x, z);
     ret.Move(distance, towards);
     return ret;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets a vector where every indices has been Math.Absoluted.
 /// </summary>
 /// <param name="Vector">The vector.</param>
 /// <returns>A absoluted Vector</returns>
 public static Vector2S AbsVector(Vector2S Vector) {
     return new Vector2S(Math.Abs(Vector.x),
                         Math.Abs(Vector.z));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets a vector where every indices has been Math.Sined.
 /// </summary>
 /// <param name="Vector">The vector.</param>
 /// <returns>A sined Vector</returns>
 public static Vector2S SinVector(Vector2S Vector) {
     return new Vector2S((short)Math.Sin(Vector.x),
                         (short)Math.Sin(Vector.z));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets the position of the spawn point.
 /// </summary>
 /// <param name="manualPosition">The position.</param>
 /// <param name="angleRot">The angle rotation.</param>
 public void SetPosition(Vector3S manualPosition, Vector2S angleRot) {
     Level.SpawnPos = manualPosition;
     Level.SpawnRot = new[] { (byte)angleRot.x, (byte)angleRot.z };
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets a vector where every indices has been Math.Cosined.
 /// </summary>
 /// <param name="Vector">The vector.</param>
 /// <returns>A cosined Vector</returns>
 public static Vector2S CosVector(Vector2S Vector) {
     return new Vector2S((short)Math.Cos(Vector.x),
                         (short)Math.Cos(Vector.z));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Gets a vector where every indices has been Math.Sined.
 /// </summary>
 /// <param name="Vector">The vector.</param>
 /// <returns>A sined Vector</returns>
 public static Vector2S SinVector(Vector2S Vector)
 {
     return(new Vector2S((short)Math.Sin(Vector.x),
                         (short)Math.Sin(Vector.z)));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets a vector where every indices has been Math.Absoluted.
 /// </summary>
 /// <param name="Vector">The vector.</param>
 /// <returns>A absoluted Vector</returns>
 public static Vector2S AbsVector(Vector2S Vector)
 {
     return(new Vector2S(Math.Abs(Vector.x),
                         Math.Abs(Vector.z)));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets a vector where every indices has been Math.Cosined.
 /// </summary>
 /// <param name="Vector">The vector.</param>
 /// <returns>A cosined Vector</returns>
 public static Vector2S CosVector(Vector2S Vector)
 {
     return(new Vector2S((short)Math.Cos(Vector.x),
                         (short)Math.Cos(Vector.z)));
 }
Ejemplo n.º 13
0
        internal void UpdatePosition(bool ForceTp)
        {
            Vector3S tempOldPos = new Vector3S(oldPos);
            Vector3S tempPos = new Vector3S(Pos);
            Vector2S tempRot = Rot;
            Vector2S tempOldRot = oldRot;
            if (tempOldRot == null) tempOldRot = new Vector2S();
            if (IsHeadFlipped)
                tempRot.z = 125;

            oldPos = tempPos;
            oldRot = tempRot;

            short diffX = (short)(tempPos.x - tempOldPos.x);
            short diffZ = (short)(tempPos.z - tempOldPos.z);
            short diffY = (short)(tempPos.y - tempOldPos.y);
            int diffR0 = tempRot.x - tempOldRot.x;
            int diffR1 = tempRot.z - tempOldRot.z;

            //TODO rewrite local pos change code
            if (diffX == 0 && diffY == 0 && diffZ == 0 && diffR0 == 0 && diffR1 == 0)
            {
                return; //No changes
            }
            bool teleport = ForceTp || (Math.Abs(diffX) >= 127 || Math.Abs(diffY) >= 127 || Math.Abs(diffZ) >= 127) || true; //Leave true untill issue 38 is fixed!

            Packet pa = new Packet();
            if (teleport)
            {
                pa.Add(Packet.Types.SendTeleport);
                pa.Add(ID);
                pa.Add(tempPos.x);
                pa.Add((short)(tempPos.y + 3));
                pa.Add(tempPos.z);
                pa.Add(new byte[2] { (byte)tempRot.x, (byte)tempRot.z });
            }
            else
            {
                bool rotupdate = diffR0 != 0 || diffR1 != 0;
                bool posupdate = diffX != 0 || diffY != 0 || diffZ != 0;
                if (rotupdate && posupdate)
                {
                    pa.Add(Packet.Types.SendPosANDRotChange);
                    pa.Add(ID);
                    pa.Add((sbyte)diffX);
                    pa.Add((sbyte)diffY);
                    pa.Add((sbyte)diffZ);
                    pa.Add(new byte[2] { (byte)tempRot.x, (byte)tempRot.z });
                }
                else if (rotupdate)
                {
                    pa.Add(Packet.Types.SendRotChange);
                    pa.Add(ID);
                    pa.Add(new byte[2] { (byte)tempRot.x, (byte)tempRot.z });
                }
                else if (posupdate)
                {
                    pa.Add(Packet.Types.SendPosChange);
                    pa.Add(ID);
                    pa.Add((sbyte)(diffX));
                    pa.Add((sbyte)(diffY));
                    pa.Add((sbyte)(diffZ));
                }
                else return;
            }

            Server.ForeachPlayer(delegate(Player p)
            {
                if (p != this && p.Level == Level && p.IsLoggedIn && !p.IsLoading)
                {
                    p.SendPacket(pa);
                }
            });
        }
Ejemplo n.º 14
0
        private void HandleIncomingPos(byte[] message)
        {
            if (!IsLoggedIn)
                return;

            byte thisid = message[0];

            ushort x = Packet.NTHO(message, 1);
            ushort y = Packet.NTHO(message, 3);
            ushort z = Packet.NTHO(message, 5);
            byte rotx = message[7];
            byte roty = message[8];
            oldPos = new Vector3S(Pos);
            Vector3S fromPosition = new Vector3S(oldPos.x, oldPos.z, oldPos.y);
            Pos.x = (short)x;
            Pos.y = (short)y;
            Pos.z = (short)z;
            oldRot = Rot;
            Rot = new Vector2S(rotx, roty);
            bool needsOwnPos = false;
            if (!(fromPosition.x == Pos.x && fromPosition.y == Pos.y && fromPosition.z == Pos.z))
            {
                MoveEventArgs eargs = new MoveEventArgs(new Vector3S(fromPosition), new Vector3S(Pos));
                eargs = OnPlayerMove.Call(this, eargs, OnAllPlayersMove);
                if (eargs.Canceled)
                {
                    Pos = fromPosition;
                    oldPos = fromPosition;
                    needsOwnPos = true;
                }
                else
                {
                    if (eargs.ToPosition / 32 != eargs.FromPosition / 32)
                    {
                        eargs = OnPlayerBigMove.Call(this, eargs, OnAllPlayersBigMove);
                        if (eargs.Canceled)
                        {
                            Pos = fromPosition;
                            oldPos = fromPosition;
                            needsOwnPos = true;
                        }
                        else
                        {
                            Pos = eargs.ToPosition;
                            oldPos = eargs.FromPosition;
                        }
                    }
                    else
                    {
                        Pos = eargs.ToPosition;
                        oldPos = eargs.FromPosition;
                    }
                }
            }
            if (oldRot.x != Rot.x || oldRot.z != Rot.z)
            {
                RotateEventArgs eargs = new RotateEventArgs((byte)Rot.x, (byte)Rot.z);
                eargs = OnPlayerRotate.Call(this, eargs, OnAllPlayersRotate);
                if (eargs.Canceled)
                {
                    Rot = new Vector2S(eargs.Rot[0], eargs.Rot[1]);
                    needsOwnPos = true;
                }
                else
                {
                    Rot = new Vector2S(eargs.Rot[0], eargs.Rot[1]);
                }
            }
            if (needsOwnPos)
                SendThisPlayerTheirOwnPos();
            UpdatePosition(false);
        }