Example #1
0
 public static string GetCommand(Waypoint wp)
 {
     var builder = new SQLCommandBuilder("waypoints");
     builder.AddColumnValue("entry",wp.NpcEntry);
     builder.AddColumnValue("pointid", wp.Id);
     builder.AddColumnValue("position_x", wp.X);
     builder.AddColumnValue("position_y", wp.Y);
     builder.AddColumnValue("position_z", wp.Z);
     return builder.BuildInsert();
 }
Example #2
0
        public static void HandleMonsterMove(Packet packet)
        {
            var guid = packet.ReadPackedGuid("GUID");

            if (packet.Opcode == Opcodes.GetOpcode(Opcode.SMSG_MONSTER_MOVE_TRANSPORT))
            {
                packet.ReadPackedGuid("Transport GUID");

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767)) // no idea when this was added exactly
                    packet.ReadByte("Transport Seat");
            }

            if (ClientVersion.AddedInVersion(ClientVersionBuild.V3_1_0_9767)) // no idea when this was added exactly
                packet.ReadBoolean("Unk Boolean"); // Something to do with IsVehicleExitVoluntary ?

            var pos = packet.ReadVector3("Position");

            packet.ReadInt32("Move Ticks");

            var type = packet.ReadEnum<SplineType>("Spline Type", TypeCode.Byte);

            switch (type)
            {
                case SplineType.FacingSpot:
                {
                    packet.ReadVector3("Facing Spot");
                    break;
                }
                case SplineType.FacingTarget:
                {
                    packet.ReadGuid("Facing GUID");
                    break;
                }
                case SplineType.FacingAngle:
                {
                    packet.ReadSingle("Facing Angle");
                    break;
                }
                case SplineType.Stop:
                    return;
            }

            var flags = packet.ReadEnum<SplineFlag>("Spline Flags", TypeCode.Int32);

            if (flags.HasAnyFlag(SplineFlag.AnimationTier))
            {
                packet.ReadEnum<MovementAnimationState>("Animation State", TypeCode.Byte);
                packet.ReadInt32("Asynctime in ms"); // Async-time in ms
            }

            // Cannot find anything similar to this in 4.2.2 client
            if (ClientVersion.RemovedInVersion(ClientVersionBuild.V4_2_2_14545))
            {
                if (flags.HasAnyFlag(SplineFlag.Falling)) // Could be SplineFlag.UsePathSmoothing
                {
                    packet.ReadInt32("Unknown");
                    packet.ReadInt16("Unknown");
                    packet.ReadInt16("Unknown");
                }
            }

            packet.ReadInt32("Move Time");

            if (flags.HasAnyFlag(SplineFlag.Trajectory))
            {
                packet.ReadSingle("Vertical Speed");
                packet.ReadInt32("Unk Int32 2");
            }

            var waypoints = packet.ReadInt32("Waypoints");

            if (flags.HasAnyFlag(SplineFlag.Flying | SplineFlag.CatmullRom))
            {
                var wp1 = packet.ReadVector3("Waypoint", 0);

                if (waypoints >= 4)
                {
                    Waypoint wp = new Waypoint
                    {
                        X = wp1.X,
                        Y = wp1.Y,
                        Z = wp1.Z,
                        NpcEntry = guid.GetEntry(),
                        Id = 0
                    };

                    Stuffing.Waypoints.TryAdd(Tuple.Create<uint, uint>(guid.GetEntry(), wp.Id), wp);
                    SQL.SQLStore.WriteData(SQL.Stores.WaypointStore.GetCommand(wp));
                }

                for (var i = 1; i < waypoints; i++)
                {
                    var wpi = packet.ReadVector3("Waypoint", i);
                    if (waypoints >= 4)
                    {
                        Waypoint wp = new Waypoint
                        {
                            X = wpi.X,
                            Y = wpi.Y,
                            Z = wpi.Z,
                            NpcEntry = guid.GetEntry(),
                            Id = (uint)i
                        };

                        Stuffing.Waypoints.TryAdd(Tuple.Create<uint, uint>(guid.GetEntry(), wp.Id), wp);
                        SQL.SQLStore.WriteData(SQL.Stores.WaypointStore.GetCommand(wp));
                    }
                }
            }
            else
            {
                var newpos = packet.ReadVector3("Waypoint Endpoint");

                if (waypoints >= 4)
                {
                    Waypoint wp = new Waypoint
                    {
                        X = newpos.X,
                        Y = newpos.Y,
                        Z = newpos.Z,
                        NpcEntry = guid.GetEntry(),
                        Id = 0
                    };

                    Stuffing.Waypoints.TryAdd(Tuple.Create<uint, uint>(guid.GetEntry(), wp.Id), wp);
                    SQL.SQLStore.WriteData(SQL.Stores.WaypointStore.GetCommand(wp));
                }

                var mid = new Vector3();
                mid.X = (pos.X + newpos.X) * 0.5f;
                mid.Y = (pos.Y + newpos.Y) * 0.5f;
                mid.Z = (pos.Z + newpos.Z) * 0.5f;

                for (var i = 1; i < waypoints; i++)
                {
                    var vec = packet.ReadPackedVector3();
                    vec.X += mid.X;
                    vec.Y += mid.Y;
                    vec.Z += mid.Z;

                    packet.Writer.WriteLine("Waypoint " + (i + 1) + ": " + vec);

                    if (waypoints >= 4)
                    {
                        Waypoint wp = new Waypoint
                        {
                            X = vec.X,
                            Y = vec.Y,
                            Z = vec.Z,
                            NpcEntry = guid.GetEntry(),
                            Id = (uint)(i + 1)
                        };

                        Stuffing.Waypoints.TryAdd(Tuple.Create<uint,uint>(guid.GetEntry(),wp.Id), wp);
                        SQL.SQLStore.WriteData(SQL.Stores.WaypointStore.GetCommand(wp));
                    }
                }
            }
        }