Exemplo n.º 1
0
        /// <summary>
        /// Return a Vector rotated around the Quaternion
        /// </summary>
        /// <param name="q1">
        /// Quaternion
        /// </param>
        /// <param name="v2">
        /// Vector
        /// </param>
        /// <returns>
        /// </returns>
        public static IVector3 RotateVector3(IQuaternion q1, IVector3 v2)
        {
            Quaternion QuatVect = new Quaternion(v2.x, v2.y, v2.z, 0);
            Quaternion QuatNorm = (Quaternion)q1.Normalize();
            Quaternion Result   = Hamilton(Hamilton(QuatNorm, QuatVect), QuatNorm.Conjugate());

            return(new Vector3(Result.x, Result.y, Result.z));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the Hamilton Product of two Quaternions
        /// </summary>
        /// <param name="vLeft">
        /// Quaternion 1
        /// </param>
        /// <param name="vRight">
        /// Quaternion 2
        /// </param>
        /// <returns>
        /// </returns>
        public static Quaternion Hamilton(IQuaternion vLeft, IQuaternion vRight)
        {
            double w = (vLeft.w * vRight.w) - (vLeft.x * vRight.x) - (vLeft.y * vRight.y) - (vLeft.z * vRight.z);
            double x = (vLeft.w * vRight.x) + (vLeft.x * vRight.w) + (vLeft.y * vRight.z) - (vLeft.z * vRight.y);
            double y = (vLeft.w * vRight.y) - (vLeft.x * vRight.z) + (vLeft.y * vRight.w) + (vLeft.z * vRight.x);
            double z = (vLeft.w * vRight.z) + (vLeft.x * vRight.y) - (vLeft.y * vRight.x) + (vLeft.z * vRight.w);

            return(new Quaternion(x, y, z, w));
        }
Exemplo n.º 3
0
        /// <summary>
        /// </summary>
        /// <param name="character">
        /// </param>
        /// <param name="destination">
        /// </param>
        /// <param name="heading">
        /// </param>
        /// <param name="playfield">
        /// </param>
        public void Teleport(Character character, Coordinate destination, IQuaternion heading, Identity playfield)
        {
            // Prevent client from entering this again
            if (character.DoNotDoTimers)
            {
                return;
            }

            character.DoNotDoTimers = true;

            // Teleport to another playfield
            ZoneEngine.Core.Packets.Teleport.Send(character, destination, heading, playfield);

            // Send packet, disconnect, and other playfield waits for connect

            DespawnMessage despawnMessage = ZoneEngine.Core.Packets.Despawn.Create(character.Identity);

            this.AnnounceOthers(despawnMessage, character.Identity);
            character.RawCoordinates = new Vector3()
            {
                X = destination.x, Y = destination.y, Z = destination.z
            };
            character.RawHeading = new Quaternion(heading.xf, heading.yf, heading.zf, heading.wf);
            character.Save();
            CharacterDao.SetPlayfield(character.Identity.Instance, (int)playfield.Type, playfield.Instance);

            // TODO: Get new server ip from chatengine (which has to log all zoneengine's playfields)
            // for now, just transmit our ip and port

            IPAddress tempIp;

            if (IPAddress.TryParse(Config.Instance.CurrentConfig.ZoneIP, out tempIp) == false)
            {
                IPHostEntry zoneHost = Dns.GetHostEntry(Config.Instance.CurrentConfig.ZoneIP);
                foreach (IPAddress ip in zoneHost.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        tempIp = ip;
                        break;
                    }
                }
            }

            var redirect = new ZoneRedirectionMessage
            {
                ServerIpAddress = tempIp,
                ServerPort      = (ushort)this.server.TcpEndPoint.Port
            };

            character.Client.SendCompressed(redirect);
            character.DoNotDoTimers = false;

            // character.Client.Server.DisconnectClient(character.Client);
        }
Exemplo n.º 4
0
 /// <summary>
 /// </summary>
 /// <param name="character">
 /// </param>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 /// <returns>
 /// </returns>
 public static N3TeleportMessage Create(
     ICharacter character, 
     Coordinate destination, 
     IQuaternion heading, 
     Identity playfield)
 {
     return new N3TeleportMessage()
            {
                Identity = character.Identity,
                Destination =
                    new Vector3()
                    {
                        X = destination.x,
                        Y = destination.y,
                        Z = destination.z
                    },
                Heading =
                    new Quaternion()
                    {
                        X = heading.xf,
                        Y = heading.yf,
                        Z = heading.zf,
                        W = heading.wf
                    },
                Unknown1 = 0x61,
                Playfield =
                    new Identity()
                    {
                        Type = IdentityType.Playfield1,
                        Instance = playfield.Instance
                    },
                ChangePlayfield =
                    ((playfield.Instance != character.Playfield.Identity.Instance)
                     || (playfield.Type != character.Playfield.Identity.Type))
                        ? new Identity
                          {
                              Type = IdentityType.Playfield2,
                              Instance = playfield.Instance
                          }
                        : Identity.None,
                Playfield2 =
                    new Identity
                    {
                        Type = IdentityType.Playfield3,
                        Instance = playfield.Instance
                    },
            };
 }
Exemplo n.º 5
0
 /// <summary>
 /// </summary>
 /// <param name="character">
 /// </param>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 /// <returns>
 /// </returns>
 public static N3TeleportMessage Create(
     ICharacter character,
     Coordinate destination,
     IQuaternion heading,
     Identity playfield)
 {
     return(new N3TeleportMessage()
     {
         Identity = character.Identity,
         Destination =
             new Vector3()
         {
             X = destination.x,
             Y = destination.y,
             Z = destination.z
         },
         Heading =
             new Quaternion()
         {
             X = heading.xf,
             Y = heading.yf,
             Z = heading.zf,
             W = heading.wf
         },
         Unknown1 = 0x61,
         Playfield =
             new Identity()
         {
             Type = IdentityType.Playfield1,
             Instance = playfield.Instance
         },
         ChangePlayfield =
             ((playfield.Instance != character.Playfield.Identity.Instance) ||
              (playfield.Type != character.Playfield.Identity.Type))
                        ? new Identity
         {
             Type = IdentityType.Playfield2,
             Instance = playfield.Instance
         }
                        : Identity.None,
         Playfield2 =
             new Identity
         {
             Type = IdentityType.Playfield3,
             Instance = playfield.Instance
         },
     });
 }
Exemplo n.º 6
0
 /// <summary>
 /// </summary>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public virtual void Teleport(Coordinate destination, IQuaternion heading, Identity playfield)
 {
     // TODO: Maybe write teleport code for dynels
 }
Exemplo n.º 7
0
 /// <summary>
 /// Returns the Hamilton Product of two Quaternions
 /// </summary>
 /// <param name="vRight">
 /// Other Quaternion
 /// </param>
 /// <returns>
 /// </returns>
 public IQuaternion Hamilton(IQuaternion vRight)
 {
     return Hamilton(this, vRight);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Return a Vector rotated around the Quaternion
 /// </summary>
 /// <param name="q1">
 /// Quaternion
 /// </param>
 /// <param name="v2">
 /// Vector
 /// </param>
 /// <returns>
 /// </returns>
 public static IVector3 RotateVector3(IQuaternion q1, IVector3 v2)
 {
     Quaternion QuatVect = new Quaternion(v2.x, v2.y, v2.z, 0);
     Quaternion QuatNorm = (Quaternion)q1.Normalize();
     Quaternion Result = Hamilton(Hamilton(QuatNorm, QuatVect), QuatNorm.Conjugate());
     return new Vector3(Result.x, Result.y, Result.z);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Return a Normalized Quaternion
        /// </summary>
        /// <param name="q1">
        /// Quaternion
        /// </param>
        /// <returns>
        /// </returns>
        public static IQuaternion Normalize(IQuaternion q1)
        {
            double mag = q1.magnitude;

            return new Quaternion(q1.x / mag, q1.y / mag, q1.z / mag, q1.w / mag);
        }
Exemplo n.º 10
0
        /// <summary>
        /// </summary>
        /// <param name="dynel">
        /// </param>
        /// <param name="destination">
        /// </param>
        /// <param name="heading">
        /// </param>
        /// <param name="playfield">
        /// </param>
        public void Teleport(Dynel dynel, Coordinate destination, IQuaternion heading, Identity playfield)
        {
            // Prevent client from entering this again
            if (dynel.DoNotDoTimers)
            {
                return;
            }
            Thread.Sleep(200);
            int dynelId = dynel.Identity.Instance;

            // Disable sending stat changes and wait a bit to clear the queue
            dynel.DoNotDoTimers = true;
            Thread.Sleep(1000);

            // Teleport to another playfield
            TeleportMessageHandler.Default.Send(
                dynel as ICharacter,
                destination.coordinate,
                (Vector.Quaternion)heading,
                playfield);

            // Send packet, disconnect, and other playfield waits for connect

            DespawnMessage despawnMessage = DespawnMessageHandler.Default.Create(dynel.Identity);

            this.AnnounceOthers(despawnMessage, dynel.Identity);
            dynel.RawCoordinates = new Vector3()
            {
                X = destination.x, Y = destination.y, Z = destination.z
            };
            dynel.RawHeading = new Vector.Quaternion(heading.xf, heading.yf, heading.zf, heading.wf);

            // IMPORTANT!!
            // Dispose the character object, save new playfield data and then recreate it
            // else you would end up at weird coordinates in the same playfield

            // Save client object
            ZoneClient client = (ZoneClient)dynel.Controller.Client;

            // Set client=null so dynel can really dispose

            IPlayfield newPlayfield = this.server.PlayfieldById(playfield);

            Pool.Instance.GetObject <Playfield>(
                Identity.None,
                new Identity()
            {
                Type = playfield.Type, Instance = playfield.Instance
            });

            if (newPlayfield == null)
            {
                newPlayfield = new Playfield(this.server, playfield);
            }

            dynel.Playfield         = newPlayfield;
            dynel.Controller.Client = null;
            dynel.Dispose();

            LogUtil.Debug(DebugInfoDetail.Database, "Saving to pf " + playfield.Instance);

            // TODO: Get new server ip from chatengine (which has to log all zoneengine's playfields)
            // for now, just transmit our ip and port

            IPAddress tempIp;

            if (IPAddress.TryParse(Config.Instance.CurrentConfig.ZoneIP, out tempIp) == false)
            {
                IPHostEntry zoneHost = Dns.GetHostEntry(Config.Instance.CurrentConfig.ZoneIP);
                foreach (IPAddress ip in zoneHost.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        tempIp = ip;
                        break;
                    }
                }
            }

            var redirect = new ZoneRedirectionMessage
            {
                ServerIpAddress = tempIp,
                ServerPort      = (ushort)this.server.TcpEndPoint.Port
            };

            if (client != null)
            {
                client.SendCompressed(redirect);
            }
            // client.Server.DisconnectClient(client);
        }
Exemplo n.º 11
0
 /// <summary>
 /// </summary>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public override void Teleport(Coordinate destination, IQuaternion heading, Identity playfield)
 {
     this.Playfield.Teleport(this, destination, heading, playfield);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Return a Normalized Quaternion
        /// </summary>
        /// <param name="q1">
        /// Quaternion
        /// </param>
        /// <returns>
        /// </returns>
        public static IQuaternion Normalize(IQuaternion q1)
        {
            double mag = q1.magnitude;

            return(new Quaternion(q1.x / mag, q1.y / mag, q1.z / mag, q1.w / mag));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Returns the Hamilton Product of two Quaternions
 /// </summary>
 /// <param name="vRight">
 /// Other Quaternion
 /// </param>
 /// <returns>
 /// </returns>
 public IQuaternion Hamilton(IQuaternion vRight)
 {
     return(Hamilton(this, vRight));
 }
Exemplo n.º 14
0
 public static IFloat Dot(IQuaternion a, IQuaternion b)
 {
     return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
 }
Exemplo n.º 15
0
 /// <summary>
 /// </summary>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public override void Teleport(Coordinate destination, IQuaternion heading, Identity playfield)
 {
     this.Playfield.Teleport(this, destination, heading, playfield);
 }
Exemplo n.º 16
0
 /// <summary>
 /// </summary>
 /// <param name="character">
 /// </param>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public static void Send(ICharacter character, Coordinate destination, IQuaternion heading, Identity playfield)
 {
     // This needs to be sent immediately!
     character.Client.SendCompressed(Create(character, destination, heading, playfield));
 }
Exemplo n.º 17
0
 /// <summary>
 /// </summary>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public void Teleport(Coordinate destination, IQuaternion heading, Identity playfield)
 {
     this.IsTeleporting = false;
     this.Playfield.Teleport(this, destination, heading, playfield);
 }
Exemplo n.º 18
0
 public void FromEuler(Vector3 euler)
 {
     quaternion = factory.FromEuler(euler);
     Debug.Log(dummyName + ":\t" + quaternion + "\n" + quaternion.ToEuler());
 }
Exemplo n.º 19
0
 /// <summary>
 /// </summary>
 /// <param name="character">
 /// </param>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public static void Send(ICharacter character, Coordinate destination, IQuaternion heading, Identity playfield)
 {
     // This needs to be sent immediately!
     character.Client.SendCompressed(Create(character, destination, heading, playfield));
 }
Exemplo n.º 20
0
        /// <summary>
        /// Returns the Hamilton Product of two Quaternions
        /// </summary>
        /// <param name="vLeft">
        /// Quaternion 1
        /// </param>
        /// <param name="vRight">
        /// Quaternion 2
        /// </param>
        /// <returns>
        /// </returns>
        public static Quaternion Hamilton(IQuaternion vLeft, IQuaternion vRight)
        {
            double w = (vLeft.w * vRight.w) - (vLeft.x * vRight.x) - (vLeft.y * vRight.y) - (vLeft.z * vRight.z);
            double x = (vLeft.w * vRight.x) + (vLeft.x * vRight.w) + (vLeft.y * vRight.z) - (vLeft.z * vRight.y);
            double y = (vLeft.w * vRight.y) - (vLeft.x * vRight.z) + (vLeft.y * vRight.w) + (vLeft.z * vRight.x);
            double z = (vLeft.w * vRight.z) + (vLeft.x * vRight.y) - (vLeft.y * vRight.x) + (vLeft.z * vRight.w);

            return new Quaternion(x, y, z, w);
        }
Exemplo n.º 21
0
 /// <summary>
 /// </summary>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public void Teleport(Coordinate destination, IQuaternion heading, Identity playfield)
 {
     this.IsTeleporting = false;
     this.Playfield.Teleport(this, destination, heading, playfield);
 }
Exemplo n.º 22
0
 /// <summary>
 /// </summary>
 /// <param name="destination">
 /// </param>
 /// <param name="heading">
 /// </param>
 /// <param name="playfield">
 /// </param>
 public virtual void Teleport(Coordinate destination, IQuaternion heading, Identity playfield)
 {
     // TODO: Maybe write teleport code for dynels
 }