public bool FunctionExecute(Dynel self, Dynel caller, object target, object[] arguments)
        {
            Client cli = ((Character)self).Client;
            Quaternion q = new Quaternion(0, 1, 0, 0);
            AOCoord a = new AOCoord();
            Int32 pf;
            if (target is Statels.Statel)
            {
                a.x = Int32.Parse((string)arguments[0]);
                a.y = Int32.Parse((string)arguments[1]);
                a.z = Int32.Parse((string)arguments[2]);
                pf = Int32.Parse((string)arguments[3]);
            }
            else
            {
                a.x = (Int32)arguments[0];
                a.y = (Int32)arguments[1];
                a.z = (Int32)arguments[2];
                pf = (Int32)arguments[3];
            }

            // Same playfield teleport sometimes has 0 for pf argument
            if (pf == 0)
            {
                pf = cli.Character.PlayField;
            }

            cli.Teleport(a, q, pf);
            return true;
        }
Esempio n. 2
0
 public bool PushCoord(AOCoord _coord)
 {
     PushFloat(_coord.x);
     PushFloat(_coord.y);
     PushFloat(_coord.z);
     return(true);
 }
        public void readWaypointsfromSQL()
        {
            SqlWrapper ms = new SqlWrapper();
            AOCoord m_wp;

            DataTable dt = ms.ReadDT("SELECT * FROM " + getSQLTablefromDynelType() + "waypoints WHERE ID=" + ID.ToString());

            foreach (DataRow row in dt.Rows)
            {
                m_wp = new AOCoord((Single)row["X"], (Single)row["Y"], (Single)row["Z"]);
                Waypoints.Add(m_wp);
            }
             
        }
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            List<Type> check = new List<Type>();
            check.Add(typeof(float));
            check.Add(typeof(float));
            check.Add(typeof(int));

            AOCoord coord = new AOCoord();
            int pf = client.Character.PlayField;
            if (CheckArgumentHelper(check, args))
            {
                coord = new AOCoord(
                    float.Parse(args[1], NumberStyles.Any, CultureInfo.InvariantCulture),
                    client.Character.Coordinates.y,
                    float.Parse(args[2], NumberStyles.Any, CultureInfo.InvariantCulture));
                pf = int.Parse(args[3]);
            }

            check.Clear();
            check.Add(typeof(float));
            check.Add(typeof(float));
            check.Add(typeof(string));
            check.Add(typeof(float));
            check.Add(typeof(int));

            if (CheckArgumentHelper(check, args))
            {
                coord = new AOCoord(
                    float.Parse(args[1], NumberStyles.Any, CultureInfo.InvariantCulture),
                    float.Parse(args[4], NumberStyles.Any, CultureInfo.InvariantCulture),
                    float.Parse(args[2], NumberStyles.Any, CultureInfo.InvariantCulture));
                pf = int.Parse(args[5]);
            }

            if (!Playfields.ValidPlayfield(pf))
            {
                client.SendFeedback(110, 188845972);
                return;
            }

            Client mClient = null;
            if ((mClient = FindClient.FindClientById(target.Instance)) == null)
            {
                client.SendChatText("Target not found");
                return;
            }

            mClient.Teleport(coord, mClient.Character.Heading, pf);
        }
 public static Doors DoorinRange(int playfield, AOCoord coord, float range)
 {
     foreach (Doors door in Program.zoneServer.Doors)
     {
         int pf = door.ID & 0xffff;
         if (pf != playfield)
         {
             continue;
         }
         if ((coord.Distance2D(door.Coordinates) < range)
             && (Math.Abs(coord.coordinate.y - door.Coordinates.y) < 3))
         {
             return door;
         }
     }
     return null;
 }
        public VendingMachine(int _id, int _playfield, int template)
        {

            ID = _id;
            PlayField = _playfield;
            // Vending machines = type 51035
            Type = 51035;
            ourType = 3;
            rawCoord = new AOCoord();
            rawHeading = new Quaternion(0, 0, 0, 0);
            TemplateID = template;
            dontdotimers = true;
            Stats = new Character_Stats(this);
            if (ID != 0)
            {
                LoadTemplate(TemplateID); // All shops will have level 1
            }
            dontdotimers = false;
        }
Esempio n. 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="aoCoord">
 /// AOCoord coordinate is at
 /// </param>
 public AOCoord(AOCoord aoCoord)
 {
     this.Update(aoCoord);
 }
Esempio n. 8
0
        /// <summary>
        /// </summary>
        /// <param name="message">
        /// </param>
        /// <param name="client">
        /// </param>
        public static void Read(CharDCMoveMessage message, Client client)
        {
            byte moveType = message.MoveType;
            var heading = new Quaternion(message.Heading.X, message.Heading.Y, message.Heading.Z, message.Heading.W);
            var coordinates = new AOCoord(message.Coordinates);

            // TODO: Find out what these (tmpInt) are and name them
            int tmpInt1 = message.Unknown1;
            int tmpInt2 = message.Unknown2;
            int tmpInt3 = message.Unknown3;

            /*
            if (!client.Character.DoNotDoTimers)
            {
                var teleportPlayfield = WallCollision.WallCollisionCheck(
                    coordinates.x, coordinates.z, client.Character.PlayField);
                if (teleportPlayfield.ZoneToPlayfield >= 1)
                {
                    var coordHeading = WallCollision.GetCoord(
                        teleportPlayfield, coordinates.x, coordinates.z, coordinates);
                    if (teleportPlayfield.Flags != 1337 && client.Character.PlayField != 152
                        || Math.Abs(client.Character.Coordinates.y - teleportPlayfield.Y) <= 2
                        || teleportPlayfield.Flags == 1337
                        && Math.Abs(client.Character.Coordinates.y - teleportPlayfield.Y) <= 6)
                    {
                        client.Teleport(
                            coordHeading.Coordinates, coordHeading.Heading, teleportPlayfield.ZoneToPlayfield);
                        Program.zoneServer.Clients.Remove(client);
                    }

                    return;
                }

                if (client.Character.Stats.LastConcretePlayfieldInstance.Value != 0)
                {
                    var correspondingDoor = DoorHandler.DoorinRange(
                        client.Character.PlayField, client.Character.Coordinates, 1.0f);
                    if (correspondingDoor != null)
                    {
                        correspondingDoor = DoorHandler.FindCorrespondingDoor(correspondingDoor, client.Character);
                        client.Character.Stats.LastConcretePlayfieldInstance.Value = 0;
                        var aoc = correspondingDoor.Coordinates;
                        aoc.x += correspondingDoor.hX * 3;
                        aoc.y += correspondingDoor.hY * 3;
                        aoc.z += correspondingDoor.hZ * 3;
                        client.Teleport(aoc, client.Character.Heading, correspondingDoor.playfield);
                        Program.zoneServer.Clients.Remove(client);
                        return;
                    }
                }
            }
            */
            client.Character.RawCoordinates = coordinates.coordinate;
            client.Character.RawHeading = heading;
            client.Character.UpdateMoveType(moveType);

            /* Start NV Heading Testing Code
             * Yaw: 0 to 360 Degrees (North turning clockwise to a complete revolution)
             * Roll: Not sure, but is always 0 cause we can't roll in AO
             * Pitch: 90 to -90 Degrees (90 is nose in the air, 0 is level, -90 is nose to the ground)
             */
            /* Comment this line with a '//' to enable heading testing
            client.SendChatText("Raw Headings: X: " + client.Character.heading.x + " Y: " + client.Character.heading.y + " Z:" + client.Character.heading.z);

            client.SendChatText("Yaw:  " + Math.Round(180 * client.Character.heading.yaw / Math.PI) + " Degrees");
            client.SendChatText("Roll: " + Math.Round(180 * client.Character.heading.roll / Math.PI) + " Degrees");
            client.SendChatText("Pitch:   " + Math.Round(180 * client.Character.heading.pitch / Math.PI) + " Degrees");
            /* End NV Heading testing code */

            /* start of packet */
            var reply = new CharDCMoveMessage
                            {
                                Identity = client.Character.Identity,
                                Unknown = 0x00,
                                MoveType = moveType,
                                Heading =
                                    new SmokeLounge.AOtomation.Messaging.GameData.Quaternion
                                        {
                                            X =
                                                heading
                                                .xf,
                                            Y =
                                                heading
                                                .yf,
                                            Z =
                                                heading
                                                .zf,
                                            W =
                                                heading
                                                .wf
                                        },
                                Coordinates =
                                    new Vector3
                                        {
                                            X = coordinates.x,
                                            Y = coordinates.y,
                                            Z = coordinates.z
                                        },
                                Unknown1 = tmpInt1,
                                Unknown2 = tmpInt2,
                                Unknown3 = tmpInt3
                            };
            client.Playfield.Publish(new IMSendAOtMessageToPlayfield { Body = reply });

            // TODO: rewrite statelscheck
            /*
            if (Statels.StatelppfonEnter.ContainsKey(client.Character.PlayField))
            {
                foreach (var s in Statels.StatelppfonEnter[client.Character.PlayField])
                {
                    if (s.onEnter(client))
                    {
                        return;
                    }

                    if (s.onTargetinVicinity(client))
                    {
                        return;
                    }
                }
            }
             */
        }
Esempio n. 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="heading"></param>
        /// <param name="playfield"></param>
        /// <returns></returns>
        public bool TeleportProxy(
            AOCoord destination,
            Quaternion heading,
            int playfield,
            Identity pfinstance,
            int GS,
            int SG,
            Identity R,
            Identity dest)
        {
            PacketWriter writer = new PacketWriter();
            // header starts
            writer.PushByte(0xDF);
            writer.PushByte(0xDF);
            writer.PushShort(10);
            writer.PushShort(1);
            writer.PushShort(0);
            writer.PushInt(3086);
            writer.PushInt(this.Character.Id);
            writer.PushInt(0x43197D22);
            writer.PushIdentity(50000, this.Character.Id);
            writer.PushByte(0);
            // Header ends
            writer.PushCoord(this.Character.RawCoord);
            writer.PushQuat(this.Character.RawHeading);
            writer.PushByte(97);
            writer.PushIdentity(pfinstance.Type, pfinstance.Instance);
            writer.PushInt(GS);
            writer.PushInt(SG);
            writer.PushIdentity(40016, playfield);
            // Dont know for sure if its correct to only transfer the playfield here
            writer.PushInt(0);
            writer.PushInt(0);
            writer.PushIdentity(dest.Type, dest.Instance);
            writer.PushInt(0);
            byte[] tpreply = writer.Finish();
            this.Character.DoNotDoTimers = true;
            Despawn.DespawnPacket(this.Character.Id);
            this.SendCompressed(tpreply);
            this.Character.DoNotDoTimers = true;
            this.Character.Stats.LastConcretePlayfieldInstance.Value = this.Character.PlayField;
            this.Character.Stats.ExtenalDoorInstance.Value = SG;

            this.Character.StopMovement();
            this.Character.RawCoord = destination;
            this.Character.RawHeading = heading;
            this.Character.PlayField = playfield;
            this.Character.Resource = 0x3c000;
            this.Character.Purge(); // Purge character information to DB before client reconnect

            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;
                    }
                }
            }
            int zoneIP = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(tempIP.GetAddressBytes(), 0));
            short zonePort = Convert.ToInt16(Config.Instance.CurrentConfig.ZonePort);

            Thread.Sleep(1000);

            PacketWriter writer2 = new PacketWriter();
            writer2.PushByte(0xDF);
            writer2.PushByte(0xDF);
            writer2.PushShort(1);
            writer2.PushShort(1);
            writer2.PushShort(0);
            writer2.PushInt(3086);
            writer2.PushInt(this.Character.Id);
            writer2.PushInt(60);
            writer2.PushInt(zoneIP);
            writer2.PushShort(zonePort);
            byte[] connect = writer2.Finish();
            this.SendCompressed(connect);
            return true;
        }
Esempio n. 10
0
 /// <summary>
 /// Calculate the Distance between two Coordinates in 2 Dimensions
 /// </summary>
 /// <param name="c1">Other Coordinate</param>
 public double Distance2D(AOCoord c1)
 {
     return(Distance2D(this, c1));
 }
Esempio n. 11
0
        /// <summary>
        /// Calculate the Distance between two Coordinates in 3 Dimensions
        /// </summary>
        /// <param name="c1">Coordinate 1</param>
        /// <param name="c2">Coordinate 2</param>
        public static double Distance3D(AOCoord c1, AOCoord c2)
        {
            Vector3 difference = c1.coordinate - c2.coordinate;

            return(difference.Magnitude);
        }
Esempio n. 12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="heading"></param>
        /// <param name="playfield"></param>
        /// <returns></returns>
        public bool Teleport(AOCoord destination, Quaternion heading, int playfield)
        {
            PacketWriter writer = new PacketWriter();
            // header starts
            writer.PushByte(0xDF); writer.PushByte(0xDF);
            writer.PushShort(10);
            writer.PushShort(1);
            writer.PushShort(0);
            writer.PushInt(3086);
            writer.PushInt(Character.ID);
            writer.PushInt(0x43197D22);
            writer.PushIdentity(50000, Character.ID);
            writer.PushByte(0);
            // Header ends
            writer.PushCoord(destination);
            writer.PushQuat(heading);
            writer.PushByte(97);
            writer.PushIdentity(51100, playfield);
            writer.PushInt(0);
            writer.PushInt(0);
            writer.PushIdentity(40016, playfield);
            writer.PushInt(0);
            writer.PushInt(0);
            writer.PushIdentity(100001, playfield);
            writer.PushInt(0);
            writer.PushInt(0);
            writer.PushInt(0);
            byte[] tpreply = writer.Finish();
            Misc.Announce.Playfield(this.Character.PlayField, ref tpreply);

            Character.stopMovement();
            Character.rawCoord = destination;
            Character.rawHeading = heading;
            Character.PlayField = playfield;
            Character.Purge(); // Purge character information to DB before client reconnect

            IPAddress tempIP;
            if (IPAddress.TryParse(ConfigReadWrite.Instance.CurrentConfig.ZoneIP, out tempIP) == false)
            {
                IPHostEntry zoneHost = Dns.GetHostEntry(ConfigReadWrite.Instance.CurrentConfig.ZoneIP);
                foreach (IPAddress ip in zoneHost.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        tempIP = ip;
                        break;
                    }
                }
            }
            int zoneIP = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(tempIP.GetAddressBytes(), 0));
            short zonePort = Convert.ToInt16(ConfigReadWrite.Instance.CurrentConfig.ZonePort);

            Thread.Sleep(1000);
            PacketWriter writer2 = new PacketWriter();
            writer2.PushByte(0xDF); writer2.PushByte(0xDF);
            writer2.PushShort(1);
            writer2.PushShort(1);
            writer2.PushShort(0);
            writer2.PushInt(3086);
            writer2.PushInt(Character.ID);
            writer2.PushInt(60);
            writer2.PushInt(zoneIP);
            writer2.PushShort(zonePort);
            byte[] connect = writer2.Finish();
            SendCompressed(connect);
            return true;
        }
 public static void UpdateDoorHeading(Client cli)
 {
     SqlWrapper ms = new SqlWrapper();
     Doors door = DoorinRange(cli.Character.PlayField, cli.Character.Coordinates, 4.0f);
     if (door == null)
     {
         cli.SendChatText("No door in range to align");
         return;
     }
     cli.SendChatText(
         string.Format("Door {0} Heading before: {1} {2} {3} {4}", door.ID, door.hX, door.hY, door.hZ, door.hW));
     AOCoord a = new AOCoord
         {
             x = cli.Character.Coordinates.x - door.Coordinates.x,
             y = cli.Character.Coordinates.y - door.Coordinates.y,
             z = cli.Character.Coordinates.z - door.Coordinates.z
         };
     Quaternion q = new Quaternion(a.x, a.y, a.z, 0);
     cli.SendChatText(string.Format("Door {0} Heading now: {1} {2} {3} {4}", door.ID, q.x, q.y, q.z, q.w));
     ms.SqlUpdate(
         "UPDATE doors SET HX=" + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.x) + ", HY="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.y) + ", HZ="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.z) + ", HW="
         + String.Format(CultureInfo.InvariantCulture, "'{0}'", q.w) + " WHERE ID=" + door.ID + ";");
     door.hX = (float)q.x;
     door.hY = (float)q.y;
     door.hZ = (float)q.z;
     door.hW = (float)q.w;
 }
Esempio n. 14
0
 public void AddWaypoint(AOCoord coord)
 {
     Waypoints.Add(coord);
     writeWaypointstoSQL();
 }
        // Call this _only_ on server startup!
        /// <summary>
        /// Reads all NPCs from database and adds them to servers list.
        /// </summary>
        /// <returns>Number of NPCs loaded</returns>
        public static int CacheAllFromDB()
        {
            int npcCount = 0;
            SqlWrapper sqlWrapper = new SqlWrapper();

            // TODO:COUNT
            string sql = "SELECT count(*) FROM `mobspawns`";
            int numberOfNpc = sqlWrapper.SqlCount(sql);

            Console.Write("Reading spawns: 0/" + numberOfNpc.ToString());
            sql = "SELECT * FROM `mobspawns`";
            DataTable dt = sqlWrapper.ReadDatatable(sql);
            sqlWrapper = new SqlWrapper();
            DataTable dtstats = sqlWrapper.ReadDatatable("SELECT * from mobspawns_stats ORDER BY id, stat ASC");
            sqlWrapper = new SqlWrapper();
            DataTable dtinventory =
                sqlWrapper.ReadDatatable("SELECT * from mobspawnsinventory order by id, placement ASC");
            int statcount = 0;
            int invcount = 0;
            foreach (DataRow row in dt.Rows)
            {
                NonPlayerCharacterClass monster = new NonPlayerCharacterClass(0, 0)
                    { Starting = true, Id = (Int32)row["ID"], PlayField = (Int32)row["Playfield"] };

                monster.Name = (string)row["Name"]
#if DEBUG
                               + " " + monster.Id.ToString() // ID is for debug purpose only
#endif
                    ;
                monster.readcoordsheadingfast(row);
                statcount = monster.ReadStatsfast(dtstats, statcount);
                invcount = monster.readInventoryfromSqlfast(dtinventory, invcount);
                //                mMonster.readMeshsfromSql();
                //                mMonster.readNanosfromSql();
                //                mMonster.readTimersfromSql();
                //                mMonster.readWaypointsfromSql();
                //                mMonster.readWeaponpairsfromSql();

                monster.readTexturesfromSqlfast(row);
                byte[] bytes;
                long counter;
                if (!(row[15] is DBNull))
                {
                    bytes = (byte[])row[15]; // Waypoints
                    counter = 0;
                    while (counter < bytes.Length)
                    {
                        AOCoord aoCoord = new AOCoord();
                        aoCoord.x = BitConverter.ToSingle(bytes, (int)counter);
                        counter += 4;
                        aoCoord.y = BitConverter.ToSingle(bytes, (int)counter);
                        counter += 4;
                        aoCoord.z = BitConverter.ToSingle(bytes, (int)counter);
                        counter += 4;
                        monster.Waypoints.Add(aoCoord);
                    }
                }

                if (!(row[16] is DBNull))
                {
                    bytes = (byte[])row[16]; // Weaponpairs
                    counter = 0;
                    while (counter < bytes.Length)
                    {
                        AOWeaponpairs tempWeaponpairs = new AOWeaponpairs();
                        tempWeaponpairs.value1 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempWeaponpairs.value2 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempWeaponpairs.value3 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempWeaponpairs.value4 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        monster.Weaponpairs.Add(tempWeaponpairs);
                    }
                }

                if (!(row[17] is DBNull))
                {
                    bytes = (byte[])row[17]; // Running Nanos
                    counter = 0;
                    while (counter < bytes.Length)
                    {
                        AONano tempNano = new AONano();

                        tempNano.Nanotype = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempNano.Instance = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempNano.Value3 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempNano.Time1 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempNano.Time2 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        monster.ActiveNanos.Add(tempNano);
                    }
                }

                if (!(row[18] is DBNull))
                {
                    counter = 0;
                    bytes = (byte[])row[18]; // Meshs
                    while (counter < bytes.Length)
                    {
                        AOMeshs tempMeshs = new AOMeshs();
                        tempMeshs.Position = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempMeshs.Mesh = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempMeshs.OverrideTexture = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;

                        monster.Meshs.Add(tempMeshs);
                    }
                }

                if (!(row[19] is DBNull))
                {
                    counter = 0;
                    bytes = (byte[])row[19]; // Additional Meshs
                    while (counter < bytes.Length)
                    {
                        AOAddMeshs tempAdditionalMeshs = new AOAddMeshs();
                        tempAdditionalMeshs.position = bytes[counter++];
                        tempAdditionalMeshs.meshvalue1 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempAdditionalMeshs.meshvalue2 = BitConverter.ToInt32(bytes, (int)counter);
                        counter += 4;
                        tempAdditionalMeshs.priority = bytes[counter++];

                        monster.AdditionalMeshs.Add(tempAdditionalMeshs);
                    }
                }
                monster.Starting = false;

                Program.zoneServer.Monsters.Add(monster);
                npcCount += 1;
                if ((npcCount % 100) == 0)
                {
                    Console.Write("\rReading spawns: " + npcCount.ToString() + "/" + numberOfNpc.ToString());
                }
            }

            Console.Write("\r                                                    \r");
            return npcCount;
        }
            public void Execute(Client cli, Statel parent, int Eventnumber)
            {
                switch (FunctionNumber)
                {
                    // Hit
                    case 53002:
                        {
                            int statnum = Int32.Parse(Arguments.ElementAt(0));
                            int min = Int32.Parse(Arguments.ElementAt(1));
                            int max = Int32.Parse(Arguments.ElementAt(2));
                            if (min > max)
                            {
                                min = max;
                                max = Int32.Parse(Arguments.ElementAt(1));
                            }
                            Random rnd = new Random();
                            cli.Character.Stats.Set(statnum, (uint)(cli.Character.Stats.Get(statnum) + rnd.Next(min, max)));
                            break;
                        }
                    // Lineteleport
                    //
                    case 53059:
                        {
#if DEBUG
                            Console.WriteLine("Function 53059 (LineTeleport)");
                            Console.WriteLine("Object: " + parent.Type + ":" + parent.Instance);
#endif
                            uint arg2 = UInt32.Parse(Arguments.ElementAt(1)); // Linesegment and playfield (lower word)
                            arg2 = arg2 >> 16;
                            int to_pf = Int32.Parse(Arguments.ElementAt(2));
                            coordheading a = FindEntry(to_pf, (Int32)arg2);
                            if (a.Coordinates.x != -1)
                            {
                                cli.Teleport(a.Coordinates, a.Heading, to_pf);
                                break;
                            }
                            break;
                        }
                    case 53082: // Teleport Proxy
                        {
                            Identity pfinstance = new Identity();
                            pfinstance.Type = Int32.Parse(Arguments.ElementAt(0));
                            pfinstance.Instance = Int32.Parse(Arguments.ElementAt(1));
                            Identity id2 = new Identity();
                            id2.Type = Int32.Parse(Arguments.ElementAt(2));
                            id2.Instance = Int32.Parse(Arguments.ElementAt(3));
                            Identity id3 = new Identity();
                            id3.Type = Int32.Parse(Arguments.ElementAt(4));
                            id3.Instance = Int32.Parse(Arguments.ElementAt(5));

                            SqlWrapper ms = new SqlWrapper();
                            DataTable dt = ms.ReadDT("SELECT * from proxydestinations WHERE playfield=" + pfinstance.Instance);
                            if (dt.Rows.Count == 0)
                            {
#if DEBUG
                                cli.SendChatText("No Destination found for playfield " + pfinstance.Instance);
                                cli.SendChatText("Statel " + parent.Type.ToString() + ":" + parent.Instance.ToString() + " handling " + Eventnumber.ToString() + " Function " + FunctionNumber.ToString() + " " + cli.Character.Coordinates.ToString());
                                foreach (string arg in Arguments)
                                {
                                    cli.SendChatText("Argument: " + arg);
                                }
#endif
                            }
                            else
                            {
                                AOCoord a = new AOCoord();
                                a.x= (Single)dt.Rows[0][1];
                                a.y= (Single)dt.Rows[0][2];
                                a.z = (Single)dt.Rows[0][3];
                                Quaternion q = new Quaternion(0, 0, 0, 0);
                                q.x = (Single)dt.Rows[0][4];
                                q.y = (Single)dt.Rows[0][5];
                                q.z = (Single)dt.Rows[0][6];
                                q.w = (Single)dt.Rows[0][7];
                                cli.TeleportProxy(a, q, pfinstance.Instance, pfinstance, 1, (Int32)parent.Instance, id2, id3);
                            }
                            break;
                        }
                    case 53092: // Bank
                        {
                            Packets.BankOpen.Send(cli);
                            break;
                        }

                    case 53083: // Teleport Proxy 2
                        {

                            Identity pfinstance = new Identity();
                            pfinstance.Type = Int32.Parse(Arguments.ElementAt(0));
                            pfinstance.Instance = Int32.Parse(Arguments.ElementAt(1));
                            int gs = 1;
                            int sg = 0;
                            Identity R = new Identity();
                            R.Type = Int32.Parse(Arguments.ElementAt(2));
                            R.Instance = Int32.Parse(Arguments.ElementAt(3));
                            Identity dest = new Identity();
                            dest.Type = Int32.Parse(Arguments.ElementAt(4));
                            dest.Instance = Int32.Parse(Arguments.ElementAt(5));
                            int to_pf = (Int32)((UInt32)(dest.Instance & 0xffff));
                            int arg2 = (Int32)((UInt32)(dest.Instance >> 16));
                            coordheading a = FindEntry(to_pf, arg2);

                            if (a.Coordinates.x != -1)
                            {
                                cli.TeleportProxy(a.Coordinates, a.Heading, to_pf, pfinstance, gs, sg, R, dest);
                                break;
                            }
                            break;
                        }
                        // Teleport
                    case 53016:
                        {
                            Quaternion q = new Quaternion(0, 1, 0, 0);
                            AOCoord a = new AOCoord();
                            a.x = Int32.Parse(Arguments.ElementAt(0));
                            a.y = Int32.Parse(Arguments.ElementAt(1));
                            a.z = Int32.Parse(Arguments.ElementAt(2));
                            cli.Teleport(a, q, Int32.Parse(Arguments.ElementAt(3)));
                            break;
                        }

                    case 53044:
                        {
                            string text = Arguments.ElementAt(0);
                            Packets.SystemText.Send(cli, text, 0);
                            break;
                        }
                    default:
                        {
#if DEBUG
                            cli.SendChatText("Statel " + parent.Type.ToString() + ":" + parent.Instance.ToString() + " handling " + Eventnumber.ToString() + " Function " + FunctionNumber.ToString() + " " + cli.Character.Coordinates.ToString());
                            foreach (string arg in Arguments)
                            {
                                cli.SendChatText("Argument: " + arg);
                            }
#endif
                            break;
                        }

                }
            }
        public static CoordHeading GetCoord(LineSegment lineSegment, float x, float z, AOCoord coordinates)
        {
            CoordHeading coordHeading = new CoordHeading();
            foreach (Line line in Destinations[lineSegment.ZoneToPlayfield].Playfield.Lines)
            {
                if (line.ID == lineSegment.ZoneToIndex)
                {
                    int incX = 0;
                    int incZ = 0;

                    Vector3 temp = new Vector3(
                        line.LineEndPoint.X - line.LineStartPoint.X, 0, line.LineEndPoint.Z - line.LineStartPoint.Z);

                    double factor = 1.0 / Math.Sqrt(Math.Pow(temp.x, 2) + Math.Pow(temp.z, 2));
                    temp.x = temp.x * factor;
                    temp.z = temp.z * factor;

                    if (line.LineStartPoint.X >= line.LineEndPoint.X)
                    {
                        coordHeading.Coordinates.x = line.LineEndPoint.X;
                        if (Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X) >= 1)
                        {
                            if (lineSegment.VectorA.X > lineSegment.VectorB.X)
                            {
                                coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X)
                                                              *
                                                              (Math.Abs(x - lineSegment.VectorB.X)
                                                               / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X));
                                incZ = 1;
                            }
                            else
                            {
                                coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X)
                                                              *
                                                              (Math.Abs(x - lineSegment.VectorA.X)
                                                               / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X));
                                incZ = -1;
                            }
                        }
                    }
                    else
                    {
                        coordHeading.Coordinates.x = line.LineStartPoint.X;
                        if (Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X) >= 1)
                        {
                            if (lineSegment.VectorA.X > lineSegment.VectorB.X)
                            {
                                coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X)
                                                              *
                                                              (Math.Abs(x - lineSegment.VectorB.X)
                                                               / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X));
                                incZ = -1;
                            }
                            else
                            {
                                coordHeading.Coordinates.x += Math.Abs(line.LineEndPoint.X - line.LineStartPoint.X)
                                                              *
                                                              (Math.Abs(x - lineSegment.VectorA.X)
                                                               / Math.Abs(lineSegment.VectorA.X - lineSegment.VectorB.X));
                                incZ = 1;
                            }
                        }
                    }
                    if (line.LineStartPoint.Z >= line.LineEndPoint.Z)
                    {
                        coordHeading.Coordinates.z = line.LineEndPoint.Z;
                        if (Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z) >= 1)
                        {
                            if (lineSegment.VectorA.Z > lineSegment.VectorB.Z)
                            {
                                coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z)
                                                              *
                                                              (Math.Abs(z - lineSegment.VectorB.Z)
                                                               / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z));
                                incX = -1;
                            }
                            else
                            {
                                coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z)
                                                              *
                                                              (Math.Abs(z - lineSegment.VectorA.Z)
                                                               / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z));
                                incX = 1;
                            }
                        }
                    }
                    else
                    {
                        coordHeading.Coordinates.z = line.LineStartPoint.Z;
                        if (Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z) >= 1)
                        {
                            if (lineSegment.VectorA.Z > lineSegment.VectorB.Z)
                            {
                                coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z)
                                                              *
                                                              (Math.Abs(z - lineSegment.VectorB.Z)
                                                               / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z));
                                incX = 1;
                            }
                            else
                            {
                                coordHeading.Coordinates.z += Math.Abs(line.LineStartPoint.Z - line.LineEndPoint.Z)
                                                              *
                                                              (Math.Abs(z - lineSegment.VectorA.Z)
                                                               / Math.Abs(lineSegment.VectorA.Z - lineSegment.VectorB.Z));
                                incX = -1;
                            }
                        }
                    }
                    if ((coordHeading.Coordinates.y < line.LineStartPoint.Y) || (coordinates.y < line.LineEndPoint.Y))
                    {
                        if (line.LineStartPoint.Y >= line.LineEndPoint.Y)
                        {
                            coordHeading.Coordinates.y = line.LineStartPoint.Y;
                        }
                        else
                        {
                            coordHeading.Coordinates.y = line.LineEndPoint.Y;
                        }
                    }
                    temp.x = temp.x * incZ * 4;
                    temp.z = temp.z * incX * 4;

                    coordHeading.Coordinates.x += Convert.ToSingle(temp.z);
                    coordHeading.Coordinates.z += Convert.ToSingle(temp.x);

                    temp.y = temp.x;
                    temp.x = -temp.z;
                    temp.z = temp.y;
                    temp.y = 0;
                    temp = temp.Normalize();
                    coordHeading.Heading = coordHeading.Heading.GenerateRotationFromDirectionVector(temp);
                    break;
                }
            }
            return coordHeading;
        }
Esempio n. 18
0
        /// <summary>
        /// Calculate the Distance between two Coordinates in 2 Dimensions
        /// </summary>
        /// <param name="c1">
        /// Coordinate 1
        /// </param>
        /// <param name="c2">
        /// Coordinate 2
        /// </param>
        /// <returns>
        /// </returns>
        public static double Distance2D(AOCoord c1, AOCoord c2)
        {
            Vector3 difference = c1.coordinate - c2.coordinate;

            return Math.Sqrt((difference.x * difference.x) + (difference.z * difference.z));
        }
Esempio n. 19
0
 /// <summary>
 /// Update the Coordinate using a AOCoord
 /// </summary>
 /// <param name="aoCoord">AOCoord coordinate is at</param>
 public void Update(AOCoord aoCoord)
 {
     coordinate = aoCoord.coordinate;
 }
Esempio n. 20
0
        /// <summary>
        /// Calculate the Distance between two Coordinates in 3 Dimensions
        /// </summary>
        /// <param name="c1">
        /// Coordinate 1
        /// </param>
        /// <param name="c2">
        /// Coordinate 2
        /// </param>
        /// <returns>
        /// </returns>
        public static double Distance3D(AOCoord c1, AOCoord c2)
        {
            Vector3 difference = c1.coordinate - c2.coordinate;

            return difference.Magnitude;
        }
Esempio n. 21
0
        /// <summary>
        /// Calculate the Distance between two Coordinates in 2 Dimensions
        /// </summary>
        /// <param name="c1">Coordinate 1</param>
        /// <param name="c2">Coordinate 2</param>
        public static double Distance2D(AOCoord c1, AOCoord c2)
        {
            Vector3 difference = c1.coordinate - c2.coordinate;

            return(Math.Sqrt((difference.x * difference.x) + (difference.z * difference.z)));
        }
Esempio n. 22
0
 /// <summary>
 /// Calculate the Distance between two Coordinates in 3 Dimensions
 /// </summary>
 /// <param name="c1">
 /// Other Coordinate
 /// </param>
 /// <returns>
 /// </returns>
 public double Distance3D(AOCoord c1)
 {
     return Distance3D(this, c1);
 }
Esempio n. 23
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="aoCoord">AOCoord coordinate is at</param>
 public AOCoord(AOCoord aoCoord)
 {
     this.Update(aoCoord);
 }
Esempio n. 24
0
 /// <summary>
 /// Update the Coordinate using a AOCoord
 /// </summary>
 /// <param name="aoCoord">
 /// AOCoord coordinate is at
 /// </param>
 public void Update(AOCoord aoCoord)
 {
     this.coordinate = aoCoord.coordinate;
 }
 public bool PushCoord(AOCoord _coord)
 {
     PushFloat(_coord.x);
     PushFloat(_coord.y);
     PushFloat(_coord.z);
     return true;
 }
 /// <summary>
 /// Add a waypoint and save all waypoints to database
 /// </summary>
 /// <param name="coord"></param>
 public void AddWaypoint(AOCoord coord)
 {
     this.Waypoints.Add(coord);
     this.writeWaypointstoSql();
 }