Exemplo n.º 1
0
 public WowObject(Guid guid, ObjectType type, MovementInfo moves)
 {
     Guid = guid;
     Type = type;
     Movement = moves;
 }
Exemplo n.º 2
0
        public static void HandleUpdateFieldChangedValues(bool creating, Guid guid, ObjectType objType,
                    Dictionary<int, UpdateField> updates, MovementInfo moves)
        {
            bool shouldCommit;
            bool isIntValue;
            bool flags;
            string fieldName = null;

            if (objType == ObjectType.Unit && guid.GetHighType() != HighGuidType.Pet)
            {

                foreach (var upVal in updates)
                {
                    bool shouldOverride = false;
                    int overrideVal = -1;
                    Dictionary<string, string> overrideDict = new Dictionary<string, string>();
                    bool shouldOverrideDict = false;
                    bool isTemplate = false;
                    shouldCommit = true;
                    isIntValue = true;
                    flags = false;

                    var idx = (UnitField)upVal.Key;
                    var val = upVal.Value;

                    switch (idx)
                    {
                        case UnitField.UNIT_CREATED_BY_SPELL:
                        case UnitField.UNIT_FIELD_CREATEDBY:
                        case UnitField.UNIT_FIELD_SUMMONEDBY:
                            {
                                shouldCommit = false;
                                break;
                            }
                        case (UnitField)ObjectField.OBJECT_FIELD_SCALE_X:
                            {
                                fieldName = "scale";
                                isIntValue = false;
                                break;
                            }
                        case UnitField.UNIT_DYNAMIC_FLAGS:
                            {
                                fieldName = "dynamicflags";
                                flags = true;
                                break;
                            }
                        case UnitField.UNIT_NPC_FLAGS:
                            {
                                fieldName = "npcflag";
                                flags = true;
                                break;
                            }
                        case UnitField.UNIT_FIELD_FLAGS:
                            {
                                fieldName = "unit_flags";
                                flags = true;
                                break;
                            }
                        case UnitField.UNIT_FIELD_ATTACK_POWER:
                            {
                                fieldName = "attackpower";
                                break;
                            }
                        case UnitField.UNIT_FIELD_BASEATTACKTIME:
                            {
                                fieldName = "baseattacktime";
                                break;
                            }
                        case UnitField.UNIT_FIELD_LEVEL:
                            {
                                int lvl = val.Int32Value;
                                uint entry = guid.GetEntry();
                                bool addMin = true;
                                bool addMax = true;
                                isTemplate = true;
                                if (minLevels.ContainsKey(entry))
                                    if (lvl >= minLevels[entry])
                                        addMin = false;
                                if (maxLevels.ContainsKey(entry))
                                    if (lvl <= maxLevels[entry])
                                        addMax = false;

                                if (addMin)
                                {
                                    overrideDict.Add("minlevel", lvl.ToString());
                                    minLevels[entry] = lvl;
                                }
                                if (addMax)
                                {
                                    overrideDict.Add("maxlevel", lvl.ToString());
                                    maxLevels[entry] = lvl;
                                }

                                if (!addMin && !addMax)
                                    shouldCommit = false;

                                shouldOverrideDict = true;
                                break;
                            }
                        case UnitField.UNIT_FIELD_RANGED_ATTACK_POWER:
                            {
                                fieldName = "rangedattackpower";
                                break;
                            }
                        case UnitField.UNIT_FIELD_RANGEDATTACKTIME:
                            {
                                fieldName = "rangeattacktime";
                                break;
                            }
                        case UnitField.UNIT_FIELD_FACTIONTEMPLATE:
                            {
                                isTemplate = true;
                                fieldName = "faction_A=" + val.Int32Value + ", faction_H";
                                break;
                            }
                        case UnitField.UNIT_FIELD_BASE_HEALTH:
                            {
                                fieldName = "minhealth = " + val.Int32Value + ", maxhealth";
                                break;
                            }
                        case UnitField.UNIT_FIELD_BASE_MANA:
                            {
                                fieldName = "minmana = " + val.Int32Value + ", maxmana";
                                break;
                            }
                        case UnitField.UNIT_FIELD_BYTES_0:
                            {
                                fieldName = "unitclass";
                                overrideVal = ((val.Int32Value & 0x00FF0000) >> 16);
                                isTemplate = true;
                                shouldOverride = true;
                                break;
                            }
                        default:
                            {
                                shouldCommit = false;
                                break;
                            }
                    }

                    if (!shouldCommit)
                        continue;

                    var finalValue = shouldOverride ? (object) overrideVal : (isIntValue ? val.Int32Value : val.SingleValue);

                    if (flags && finalValue is int)
                        finalValue = "0x" + ((int)finalValue).ToString("X8");

                    if (isTemplate)
                    {
                        Dictionary<string, string> data;
                        if (shouldOverrideDict)
                            data = overrideDict;
                        else {
                            data = new Dictionary<string, string>();
                            data.Add(fieldName, finalValue.ToString());
                        }
                        CreatureTemplateUpdate update = new CreatureTemplateUpdate(guid.GetEntry(), data);
                        CreatureTemplateUpdateStorage.GetSingleton().Add(update);
                    }
                    else
                    {

                    }
                }
            }

            if (objType != ObjectType.GameObject)
                return;

            foreach (var upVal in updates)
            {
                shouldCommit = true;
                isIntValue = true;
                flags = false;

                var idx = (GameObjectField)upVal.Key;
                var val = upVal.Value;

                switch (idx)
                {
                    case GameObjectField.OBJECT_FIELD_CREATED_BY:
                        {
                            shouldCommit = false;
                            break;
                        }
                    case (GameObjectField)ObjectField.OBJECT_FIELD_SCALE_X:
                        {
                            fieldName = "size";
                            isIntValue = false;
                            break;
                        }
                    case GameObjectField.GAMEOBJECT_FACTION:
                        {
                            fieldName = "faction";
                            break;
                        }
                    case GameObjectField.GAMEOBJECT_FLAGS:
                        {
                            fieldName = "flags";
                            flags = true;
                            break;
                        }
                    default:
                        {
                            shouldCommit = false;
                            break;
                        }
                }

                if (!shouldCommit)
                    continue;

                var finalValue = isIntValue ? (object)val.Int32Value : val.SingleValue;

                if (flags)
                    finalValue = "0x" + ((int)finalValue).ToString("X8");
            }

            // add to storage
        }
Exemplo n.º 3
0
        public static MovementInfo ReadMovementUpdateBlock(Packet packet, Guid guid)
        {
            var moveInfo = new MovementInfo();

            var flags = packet.ReadEnum<UpdateFlag>("Update Flags");

            if (flags.HasFlag(UpdateFlag.Living))
            {
                moveInfo = MovementHandler.ReadMovementInfo(packet, guid);
                var moveFlags = moveInfo.Flags;

                for (var i = 0; i < 9; i++)
                {
                    var j = (SpeedType)i;
                    var speed = packet.ReadSingle();
                    Console.WriteLine(j + " Speed: " + speed);

                    switch (j)
                    {
                        case SpeedType.Walk:
                            {
                                moveInfo.WalkSpeed = speed / 2.5f;
                                break;
                            }
                        case SpeedType.Run:
                            {
                                moveInfo.RunSpeed = speed / 7.0f;
                                break;
                            }
                    }
                }

                if (moveFlags.HasFlag(MoveFlag.SplineEnabled))
                {
                    var splineFlags = packet.ReadEnum<SplineFlag>("Spline Flags");

                    if (splineFlags.HasFlag(SplineFlag.FinalPoint))
                        packet.ReadVector3("Final Spline Coords");

                    if (splineFlags.HasFlag(SplineFlag.FinalTarget))
                        packet.ReadGuid("Final Spline Target GUID");

                    if (splineFlags.HasFlag(SplineFlag.FinalOrientation))
                        packet.ReadSingle("Final Spline Orientation");

                    packet.ReadInt32("Spline Time");
                    packet.ReadInt32("Spline Full Time");
                    packet.ReadInt32("Spline Unk Int32 1");
                    packet.ReadSingle("Spline Duration Multiplier");
                    packet.ReadSingle("Spline Unit Interval");
                    packet.ReadSingle("Spline Unk Float 2");
                    packet.ReadInt32("Spline Height Time");

                    var splineCount = packet.ReadInt32("Spline Count");
                    for (var i = 0; i < splineCount; i++)
                        packet.ReadVector3("Spline Waypoint " + i);

                    packet.ReadEnum<SplineMode>("Spline Mode");
                    packet.ReadVector3("Spline Endpoint");
                }
            }
            else
            {
                if (flags.HasFlag(UpdateFlag.GOPosition))
                {
                    packet.ReadPackedGuid("GO Position GUID");
                    var gopos = packet.ReadVector3("GO Position");
                    packet.ReadVector3("GO Transport Position");
                    var goFacing = packet.ReadSingle("GO Orientation");
                    moveInfo.Position = gopos;
                    moveInfo.Orientation = goFacing;
                    packet.ReadSingle("GO Transport Orientation");
                }
                else if (flags.HasFlag(UpdateFlag.StationaryObject))
                    packet.ReadVector4("Stationary Position");
            }

            if (flags.HasFlag(UpdateFlag.LowGuid))
                packet.ReadInt32("Low GUID");

            if (flags.HasFlag(UpdateFlag.AttackingTarget))
                packet.ReadPackedGuid("Target GUID");

            if (flags.HasFlag(UpdateFlag.Transport))
                packet.ReadInt32("Transport Creation Time");

            if (flags.HasFlag(UpdateFlag.Vehicle))
            {
                packet.ReadInt32("Vehicle ID");
                packet.ReadSingle("Vehicle Orientation");
            }

            if (flags.HasFlag(UpdateFlag.GORotation))
                packet.ReadPackedQuaternion("GO Rotation");

            if (flags.HasFlag(UpdateFlag.Unknown2))
            {
                packet.ReadInt16("Unk Int16 1");
                packet.ReadInt16("Unk Int16 2");
                packet.ReadInt16("Unk Int16 3");
            }

            if (flags.HasFlag(UpdateFlag.Unknown3))
            {
                var count = packet.ReadByte("Unk count");
                packet.ReadBytes(count * 4);    // count ints
            }

            return moveInfo;
        }
Exemplo n.º 4
0
        public static MovementInfo ReadMovementInfo(Packet packet, Guid guid)
        {
            bool HaveTransportData = false,
                 HaveTransportTime2 = false,
                 HaveTransportTime3 = false,
                 HavePitch = false,
                 HaveFallData = false,
                 HaveFallDirection = false,
                 HaveSplineElevation = false,
                 UnknownBool = false;
            var info = new MovementInfo();

            info.Flags = packet.ReadEnum<MoveFlag>("Movement Flags", 30);

            var flags2 = packet.ReadEnum<MoveFlagExtra>("Extra Movement Flags", 12);

            if (HaveTransportData = packet.ReadBit())
            {
                HaveTransportTime2 = packet.ReadBit();
                HaveTransportTime3 = packet.ReadBit();
            }

            HavePitch = packet.ReadBit();

            if (HaveFallData = packet.ReadBit())
                HaveFallDirection = packet.ReadBit();

            HaveSplineElevation = packet.ReadBit();
            UnknownBool = packet.ReadBit();

            packet.ReadGuid("GUID");
            packet.ReadInt32("Time");
            var pos = packet.ReadVector4("Position");
            info.Position = new Vector3(pos.X, pos.Y, pos.Z);
            info.Orientation = pos.O;

            if (HaveTransportData)//info.Flags.HasFlag(MoveFlag.OnTransport))
            {
                packet.ReadGuid("Transport GUID");
                packet.ReadVector4("Transport Position");
                packet.ReadByte("Transport Seat");
                packet.ReadInt32("Transport Time");

                if (HaveTransportTime2)//flags2.HasFlag(MoveFlagExtra.InterpolatedPlayerMovement))
                    packet.ReadInt32("Transport Time 2");

                if (HaveTransportTime3)
                    packet.ReadInt32("Transport Time 3");
            }

            if (HavePitch)//info.Flags.HasAnyFlag(MoveFlag.Swimming | MoveFlag.Flying) ||
                //flags2.HasFlag(MoveFlagExtra.AlwaysAllowPitching))
                packet.ReadSingle("Swim Pitch");

            if (HaveFallData) // info.Flags.HasFlag(MoveFlag.Falling)
            {
                packet.ReadInt32("Fall Time");
                packet.ReadSingle("Jump Velocity");
                if (HaveFallDirection)
                {
                    packet.ReadSingle("Jump Sin");
                    packet.ReadSingle("Jump Cos");
                    packet.ReadSingle("Jump XY Speed");
                }
            }

            if (HaveSplineElevation) //info.Flags.HasFlag(MoveFlag.SplineElevation))
                packet.ReadSingle("Spline Elevation");

            return info;
        }
Exemplo n.º 5
0
        public static MovementInfo ReadMovementInfo(Packet packet, Guid guid)
        {
            var info = new MovementInfo();

            info.Flags = packet.ReadEnum<MoveFlag>("Movement Flags");

            var flags2 = packet.ReadEnum<MoveFlagExtra>("Extra Movement Flags");

            packet.ReadInt32("Time");
            var pos = packet.ReadVector4("Position");
            info.Position = new Vector3(pos.X, pos.Y, pos.Z);
            info.Orientation = pos.O;

            if (info.Flags.HasFlag(MoveFlag.OnTransport))
            {
                packet.ReadPackedGuid("Transport GUID");
                packet.ReadVector4("Transport Position");
                packet.ReadInt32("Transport Time");
                packet.ReadByte("Transport Seat");

                if (flags2.HasFlag(MoveFlagExtra.InterpolatedPlayerMovement))
                    packet.ReadInt32("Transport Time 2");
            }

            if (info.Flags.HasAnyFlag(MoveFlag.Swimming | MoveFlag.Flying) ||
                flags2.HasFlag(MoveFlagExtra.AlwaysAllowPitching))
                packet.ReadSingle("Swim Pitch");

            packet.ReadInt32("Fall Time");

            if (info.Flags.HasFlag(MoveFlag.Falling))
            {
                packet.ReadSingle("Jump Velocity");
                packet.ReadSingle("Jump Sin");
                packet.ReadSingle("Jump Cos");
                packet.ReadSingle("Jump XY Speed");
            }

            if (info.Flags.HasFlag(MoveFlag.SplineElevation))
                packet.ReadSingle("Spline Elevation");

            return info;
        }
Exemplo n.º 6
0
 public WowObject(Guid guid, ObjectType type, MovementInfo moves)
 {
     Guid     = guid;
     Type     = type;
     Movement = moves;
 }