Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public bool FunctionExecute(Dynel Self, Dynel Caller, object Target, object[] Arguments)
        {
            Identity pfinstance = new Identity();
            Identity id2        = new Identity();
            Identity id3        = new Identity();
            Client   cli        = ((Character)Self).Client;

            if (Target is Statels.Statel)
            {
                pfinstance.Type     = Int32.Parse((string)Arguments[0]);
                pfinstance.Instance = Int32.Parse((string)Arguments[1]);
                id2.Type            = Int32.Parse((string)Arguments[2]);
                id2.Instance        = Int32.Parse((string)Arguments[3]);
                id3.Type            = Int32.Parse((string)Arguments[4]);
                id3.Instance        = Int32.Parse((string)Arguments[5]);
            }
            else
            {
                // Shouldnt happen ever, as far as i know only Statels do ProxyTeleports (perhaps GM's can too tho)
                pfinstance.Type     = (Int32)Arguments[0];
                pfinstance.Instance = (Int32)Arguments[1];
                id2.Type            = (Int32)Arguments[2];
                id2.Instance        = (Int32)Arguments[3];
                id3.Type            = (Int32)Arguments[4];
                id3.Instance        = (Int32)Arguments[5];
            }
            SqlWrapper ms = new SqlWrapper();
            DataTable  dt = ms.ReadDatatable("SELECT * from proxydestinations WHERE playfield=" + pfinstance.Instance);

            if (dt.Rows.Count == 0)
            {
#if DEBUG
                cli.SendChatText("No Destination found for playfield " + pfinstance.Instance);
                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];
                int instance = (Int32)((Statels.Statel)Target).Instance;
                // TODO: 1=GS need to change that later to a crowdbalancing system
                cli.TeleportProxy(a, q, pfinstance.Instance, pfinstance, 1, instance, id2, id3);
            }
            return(true);
        }
Beispiel #4
0
 public override void ExecuteCommand(Client client, Identity target, string[] args)
 {
     client.SendChatText("Looking up for statel in playfield " + client.Character.PlayField.ToString());
     Statels.Statel o = null;
     foreach (Statels.Statel s in Statels.Statelppf[client.Character.PlayField])
     {
         if (o == null)
         {
             o = s;
         }
         else
         {
             if (AOCoord.Distance2D(client.Character.Coordinates, s.Coordinates)
                 < AOCoord.Distance2D(client.Character.Coordinates, o.Coordinates))
             {
                 o = s;
             }
         }
     }
     if (o == null)
     {
         client.SendChatText("No statel on this playfield... Very odd, where exactly are you???");
         return;
     }
     client.SendChatText(o.Type + ":" + o.Instance);
     foreach (Statels.StatelEvent se in o.Events)
     {
         client.SendChatText(
             "Event: " + se.EventNumber.ToString() + " # of Functions: " + se.Functions.Count.ToString());
         foreach (Statels.Statel_Function sf in se.Functions)
         {
             string Fargs = "";
             foreach (string arg in sf.Arguments)
             {
                 if (Fargs.Length > 0)
                 {
                     Fargs = Fargs + ", ";
                 }
                 Fargs = Fargs + arg;
             }
             client.SendChatText(
                 "    Fn: " + sf.FunctionNumber.ToString() + ", # of Args: " + sf.Arguments.Count.ToString());
             client.SendChatText("    Args: " + Fargs);
             foreach (Statels.Statel_Function_Requirement sfr in sf.Requirements)
             {
                 string req;
                 req = "Attr: " + sfr.AttributeNumber.ToString() + " Value: " + sfr.AttributeValue.ToString()
                       + " Target: " + sfr.Target.ToString() + " Op: " + sfr.Operator.ToString();
                 client.SendChatText("    Req: " + req);
             }
         }
     }
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
 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);
 }
Beispiel #8
0
 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;
 }
Beispiel #9
0
 public bool onTargetinVicinity(Client cli)
 {
     foreach (Statel_Event e in Events)
     {
         if (e.EventNumber != ItemHandler.eventtype_ontargetinvicinity)
         {
             continue;
         }
         if ((AOCoord.distance2D(cli.Character.Coordinates, Coordinates) < 1.2f) && (Math.Abs(cli.Character.Coordinates.y - Coordinates.y) < 5))
         {
             foreach (Statel_Function f in e.Functions)
             {
                 f.Execute(cli, this, e.EventNumber);
             }
             return(true);
         }
     }
     return(false);
 }
Beispiel #10
0
 public bool onTargetinVicinity(Client cli)
 {
     foreach (StatelEvent e in this.Events)
     {
         if (e.EventNumber != Constants.EventtypeOnTargetInVicinity)
         {
             continue;
         }
         if ((AOCoord.Distance2D(cli.Character.Coordinates, this.Coordinates) < 1.2f) &&
             (Math.Abs(cli.Character.Coordinates.y - this.Coordinates.y) < 5))
         {
             foreach (Statel_Function f in e.Functions)
             {
                 f.Execute(cli, this, e.EventNumber);
             }
             return(true);
         }
     }
     return(false);
 }
Beispiel #11
0
 public void AddWaypoint(AOCoord coord)
 {
     Waypoints.Add(coord);
     writeWaypointstoSQL();
 }
Beispiel #12
0
        // 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);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="packet">
        /// The packet.
        /// </param>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="dynel">
        /// The dynel.
        /// </param>
        public static void Read(byte[] packet, Client client, Dynel dynel)
        {
            sender = client;
            PacketReader packetReader = new PacketReader(packet);

            packetReader.PopHeader();
            packetReader.PopByte();
            temp1  = packetReader.PopInt();
            count  = packetReader.PopInt(); // Count of commands sent
            action = packetReader.PopInt();
            temp4  = packetReader.PopInt();
            user   = packetReader.PopIdentity();
            target = packetReader.PopIdentity();
            packetReader.Finish();
            bool feedback = true;

            switch (action)
            {
            case 1:

                // Get
                break;

            case 2:

                // Drop
                break;

            case 3:

                // Use
                OnUse();
                AOCoord newcoord = client.Character.Coordinates;
                feedback = false;

                if (Statels.StatelppfonUse.ContainsKey(client.Character.PlayField))
                {
                    foreach (Statels.Statel s in Statels.StatelppfonUse[client.Character.PlayField])
                    {
                        if (s.onUse(client, target))
                        {
                            return;
                        }
                    }
                }

                bool teleport  = false;
                int  playfield = 152;
                switch (target.Instance)
                {
                // Need to add feedback to the character
                // Are the Newer Grid points in this list???
                // No newer Grid points in list, will be replaced by a check against a list of statels read from rdb anyway
                // - Algorithman
                case -1073605919:         // Teleport Tower(noobisland)(right)
                    if (client.Character.Stats.Side.Value != 2)
                    {
                        client.SendChatText("You need to be omni to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 202;
                        newcoord.z = 878;
                        newcoord.y = 16;
                        playfield  = 687;
                    }

                    break;

                case -1073736991:         // Teleport Tower(noobisland)(left)
                    if (client.Character.Stats.Side.Value != 1)
                    {
                        client.SendChatText("You need to be clan to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 390;
                        newcoord.z = 340;
                        newcoord.y = 0;
                        playfield  = 545;
                    }

                    break;

                case -1073671455:         // Teleport Tower(noobisland)(middle)
                    if (client.Character.Stats.Side.Value != 0)
                    {
                        client.SendChatText("You need to be neutral to use this teleporter!");
                        teleport = false;
                    }
                    else
                    {
                        newcoord.x = 685;
                        newcoord.z = 480;
                        newcoord.y = 73;
                        playfield  = 800;
                    }

                    break;

                case -1073741189:         // 2ho -> Stret west
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 1143;
                        newcoord.z = 541;
                        newcoord.y = 8;
                        playfield  = 790;
                    }

                    break;

                case -1073478890:         // Stret West -> 2ho
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 760;
                        newcoord.z = 1982;
                        newcoord.y = 7;
                        playfield  = 635;
                    }

                    break;

                case -1073216841:         // Harry's -> Plesant Meadows
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 370;
                        newcoord.z = 1564;
                        newcoord.y = 7;
                        playfield  = 630;
                    }

                    break;

                case -1073216906:         // Plesant Meadows -> Harry's
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 3196;
                        newcoord.z = 3172;
                        newcoord.y = 7;
                        playfield  = 695;
                    }

                    break;

                case -1073282442:         // Pleasant Meadows -> Omni-Tek outpost in Lush Fields
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 3389;
                        newcoord.z = 800;
                        newcoord.y = 8;
                        playfield  = 695;
                    }

                    break;

                case -1073413449:         // Omni-Tek outpost in Lush Fields -> Pleasant Meadows
                    if (client.Character.Stats.Cash.Value < 50)
                    {
                        // check if you got enough credits to use the ferry
                        client.SendChatText("You need atleast 50 credits to board this ferry!");
                        teleport = false;
                    }
                    else
                    {
                        client.Character.Stats.Cash.Set(client.Character.Stats.Cash.Value - 50);
                        newcoord.x = 370;
                        newcoord.z = 1562;
                        newcoord.y = 7;
                        playfield  = 630;
                    }

                    break;

                case -1073347913:         // Harry's trading outpost -> Omni-1 Trade (free)
                    newcoord.x = 3569;
                    newcoord.z = 912;
                    newcoord.y = 9;
                    playfield  = 695;
                    break;

                case -1073282377:         // Omni-1 Trade -> Harry's trading outpost (free)
                    newcoord.x = 3290;
                    newcoord.z = 2922;
                    newcoord.y = 7;
                    playfield  = 695;
                    break;

                default:
                    feedback = true;
                    teleport = false;
                    break;
                }

                if (teleport)
                {
                    client.Teleport(newcoord, client.Character.Heading, playfield);
                }

                // Use item in inventory
                if (target.Type == 104)
                {
                    InventoryEntries ie = client.Character.GetInventoryAt(target.Instance);
                    AOItem           mi = ItemHandler.GetItemTemplate(ie.Item.LowID);

                    // TODO mi.applyon(client.Character, ItemHandler.eventtype_onuse, true, false, ie.Placement);
                    TemplateAction.Send(client.Character, ie);
                    if (mi.isConsumable())
                    {
                        ie.Item.MultipleCount--;
                        if (ie.Item.MultipleCount <= 0)
                        {
                            client.Character.Inventory.Remove(ie);
                            DeleteItem.Send(client.Character, ie.Container, ie.Placement);

                            // Packets.Stat.Set(client, 0, client.Character.Stats.GetStat(0),false);
                        }
                    }

                    foreach (AOEvents aoe in mi.Events)
                    {
                        if (aoe.EventType == Constants.EventtypeOnUse)
                        {
                            sender.Character.ExecuteEvent(
                                sender.Character, sender.Character, aoe, true, false, 0, CheckReqs.doCheckReqs);
                            SkillUpdate.SendStat(client, 0x209, client.Character.Stats.SocialStatus.Value, false);

                            // Social Status
                            return;
                        }
                    }

                    int    le    = packet[7] + packet[6] * 256;
                    byte[] reply = new byte[le];
                    Array.Copy(packet, reply, le);
                    reply[0]    = 0xdf;
                    reply[1]    = 0xdf;
                    reply[8]    = 0x00;
                    reply[9]    = 0x00;
                    reply[10]   = 0x0C;
                    reply[11]   = 0x0E;
                    reply[12]   = (byte)(client.Character.Id >> 24);
                    reply[13]   = (byte)(client.Character.Id >> 16);
                    reply[14]   = (byte)(client.Character.Id >> 8);
                    reply[15]   = (byte)client.Character.Id;
                    reply[0x1c] = 0;
                    reply[32]   = 1;
                    reply[36]   = 3;

                    PacketWriter pw = new PacketWriter();
                    pw.PushBytes(reply);
                    byte[] rep = pw.Finish();
                    client.SendCompressed(rep);
                    SkillUpdate.SendStat(client, 0x209, client.Character.Stats.SocialStatus.Value, false);

                    // Social Status
                    return;
                }
                else if (target.Type == 51035)
                {
                    // Shops
                    VendingMachine vm = VendorHandler.GetVendorById(target.Instance);
                    ShopInventory.Send(client, vm);
                    Trade.Send(client, client.Character, vm);
                    Trade.Send(client, vm, client.Character);
                    Trade.Send(client, vm, client.Character);
                    int    le    = packet[7] + packet[6] * 256;
                    byte[] reply = new byte[le];
                    Array.Copy(packet, reply, le);
                    reply[0]    = 0xdf;
                    reply[1]    = 0xdf;
                    reply[8]    = 0x00;
                    reply[9]    = 0x00;
                    reply[10]   = 0x0C;
                    reply[11]   = 0x0E;
                    reply[12]   = (byte)(client.Character.Id >> 24);
                    reply[13]   = (byte)(client.Character.Id >> 16);
                    reply[14]   = (byte)(client.Character.Id >> 8);
                    reply[15]   = (byte)client.Character.Id;
                    reply[0x1c] = 0;
                    reply[0x20] = 1;

                    client.Character.LastTrade = target;

                    PacketWriter pw = new PacketWriter();
                    pw.PushBytes(reply);
                    byte[] rep = pw.Finish();
                    client.SendCompressed(rep);
                }
                else if (target.Type == 51050)
                {
                    // Open corpse
                }

                break;

            case 4:

                // Repair
                break;

            case 5:

                // UseItemOnItem
#if DEBUG
                Console.WriteLine("Use Item on Item not defined yet");
                Console.WriteLine("Packet data:");
                string line   = string.Empty;
                int    count2 = 0;
                foreach (byte packbyte in packet)
                {
                    if ((count2 % 16) == 0)
                    {
                        Console.WriteLine(line);
                        line = string.Empty;
                    }

                    line = line + packbyte.ToString("X2") + " ";
                    count2++;
                }

                if (line != string.Empty)
                {
                    Console.WriteLine();
                }

                Console.WriteLine(line);
#endif
                break;

            default:
                break;
            }

            if (feedback)
            {
#if DEBUG
                string Feedback1 = string.Format("T1 {0}, Count {1}, Action {2}, T4 {3}", temp1, count, action, temp4);
                string Feedback2 = string.Format(
                    "User {0}:{1}, Target {2}:{3} ({4}:{5})",
                    user.Type,
                    user.Instance,
                    target.Type,
                    (uint)target.Instance,
                    target.Type.ToString("X4"),
                    ((uint)target.Instance).ToString("X8"));
                Statels.Statel b = null;
                if (Statels.Statelppf.ContainsKey(client.Character.PlayField))
                {
                    foreach (Statels.Statel z in Statels.Statelppf[client.Character.PlayField])
                    {
                        if ((z.Type == target.Type) && ((Int32)z.Instance == target.Instance))
                        {
                            b = z;
                            break;
                        }
                    }
                }

                if (b != null)
                {
                    foreach (Statels.StatelEvent e in b.Events)
                    {
                        Console.WriteLine("DebugOutput: \r\n" + e);
                    }

                    Console.WriteLine(b.Coordinates.ToString());
                }
                else
                {
                    Console.WriteLine(
                        "No Statel defined in database for #" + target.Type + ":" + (UInt32)target.Instance + " ("
                        + target.Type.ToString("X4") + ":" + target.Instance.ToString("X8") + ")");
                }

                client.SendChatText(Feedback1);
                client.SendChatText(Feedback2);
#endif
            }
        }
Beispiel #15
0
        /// <summary>
        /// TODO: Add a Description of what this Class does.. -Looks at someone else-
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="client"></param>
        public static void Read(ref byte[] packet, Client client)
        {
            PacketWriter _writer = new PacketWriter();
            PacketReader _reader = new PacketReader(ref packet);

            Header header = _reader.PopHeader();

            _reader.PopByte();
            byte       _movetype = _reader.PopByte();
            Quaternion _heading  = _reader.PopQuat();
            AOCoord    _coord    = _reader.PopCoord();
            // TODO: Find out what these (tmpInt) are and name them
            int tmpInt1 = _reader.PopInt();
            int tmpInt2 = _reader.PopInt();
            int tmpInt3 = _reader.PopInt();

            _reader.Finish();

            Collision.WallCollision.LineSegment teleportPF = Collision.WallCollision.WallCollisionCheck(_coord.x, _coord.z, client.Character.PlayField);
            if (teleportPF.ZoneToPF >= 1)
            {
                _coord = Collision.WallCollision.GetCoord(teleportPF, _coord.x, _coord.z, _coord);
                if (teleportPF.Flags != 1337 && client.Character.PlayField != 152 || Math.Abs(client.Character.Coordinates.y - teleportPF.Y) <= 2 || teleportPF.Flags == 1337 && Math.Abs(client.Character.Coordinates.y - teleportPF.Y) <= 6)
                {
                    client.Teleport(_coord, _heading, teleportPF.ZoneToPF);
                    ZoneEngine.Program.zoneServer.Clients.Remove(client);
                }
                return;
            }


            client.Character.rawCoord   = _coord;
            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 */
            _writer.PushByte(0xDF); _writer.PushByte(0xDF);
            /* packet type */
            _writer.PushShort(10);
            /* unknown */
            _writer.PushShort(1);
            /* packet length (writer takes care of this) */
            _writer.PushShort(0);
            /* server ID */
            _writer.PushInt(3086);
            /* receiver (Announce takes care of this) */
            _writer.PushInt(0);
            /* packet ID */
            _writer.PushInt(0x54111123);
            /* affected dynel identity */
            _writer.PushIdentity(50000, client.Character.ID);
            /* ? */
            _writer.PushByte(0);
            /* movement type */
            _writer.PushByte(_movetype);
            /* Heading */
            _writer.PushQuat(_heading);
            /* Coordinates */
            _writer.PushCoord(_coord);
            // see reading part for comment
            _writer.PushInt(tmpInt1);
            _writer.PushInt(tmpInt2);
            _writer.PushInt(tmpInt3);
            byte[] reply = _writer.Finish();
            Misc.Announce.Playfield(client.Character.PlayField, ref reply);

            if (Statels.StatelppfonEnter.ContainsKey(client.Character.PlayField))
            {
                foreach (Statels.Statel s in Statels.StatelppfonEnter[client.Character.PlayField])
                {
                    if (s.onEnter(client))
                    {
                        return;
                    }
                    if (s.onTargetinVicinity(client))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #16
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;
             *      }
             *  }
             * }
             */
        }
Beispiel #17
0
            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;
                }
                }
            }
Beispiel #18
0
 /// <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();
 }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        /// <summary>
        /// TODO: Add a Description of what this Class does.. -Looks at someone else-
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="client"></param>
        public static void Read(byte[] packet, Client client)
        {
            PacketWriter packetWriter = new PacketWriter();
            PacketReader packetReader = new PacketReader(packet);

            Header header = packetReader.PopHeader();

            packetReader.PopByte();
            byte       moveType    = packetReader.PopByte();
            Quaternion heading     = packetReader.PopQuat();
            AOCoord    coordinates = packetReader.PopCoord();
            // TODO: Find out what these (tmpInt) are and name them
            int tmpInt1 = packetReader.PopInt();
            int tmpInt2 = packetReader.PopInt();
            int tmpInt3 = packetReader.PopInt();

            packetReader.Finish();

            if (!client.Character.DoNotDoTimers)
            {
                WallCollision.LineSegment teleportPlayfield = WallCollision.WallCollisionCheck(
                    coordinates.x, coordinates.z, client.Character.PlayField);
                if (teleportPlayfield.ZoneToPlayfield >= 1)
                {
                    Quaternion   newHeading;
                    CoordHeading 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)
                {
                    Doors 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;
                        AOCoord 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.RawCoord   = coordinates;
            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 */
            packetWriter.PushByte(0xDF);
            packetWriter.PushByte(0xDF);
            /* packet type */
            packetWriter.PushShort(10);
            /* unknown */
            packetWriter.PushShort(1);
            /* packet length (writer takes care of this) */
            packetWriter.PushShort(0);
            /* server ID */
            packetWriter.PushInt(3086);
            /* receiver (Announce takes care of this) */
            packetWriter.PushInt(0);
            /* packet ID */
            packetWriter.PushInt(0x54111123);
            /* affected dynel identity */
            packetWriter.PushIdentity(50000, client.Character.Id);
            /* ? */
            packetWriter.PushByte(0);
            /* movement type */
            packetWriter.PushByte(moveType);
            /* Heading */
            packetWriter.PushQuat(heading);
            /* Coordinates */
            packetWriter.PushCoord(coordinates);
            // see reading part for comment
            packetWriter.PushInt(tmpInt1);
            packetWriter.PushInt(tmpInt2);
            packetWriter.PushInt(tmpInt3);
            byte[] reply = packetWriter.Finish();
            Announce.Playfield(client.Character.PlayField, reply);

            if (Statels.StatelppfonEnter.ContainsKey(client.Character.PlayField))
            {
                foreach (Statels.Statel s in Statels.StatelppfonEnter[client.Character.PlayField])
                {
                    if (s.onEnter(client))
                    {
                        return;
                    }
                    if (s.onTargetinVicinity(client))
                    {
                        return;
                    }
                }
            }
        }