示例#1
0
        public void MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint id = EventId.Jump, bool hasOrientation = false,
                             JumpArrivalCastArgs arrivalCast = null, SpellEffectExtraData spellEffectExtraData = null)
        {
            Log.outDebug(LogFilter.Server, "Unit ({0}) jump to point (X: {1} Y: {2} Z: {3})", _owner.GetGUID().ToString(), x, y, z);

            float moveTimeHalf = (float)(speedZ / gravity);
            float max_height   = -MoveSpline.computeFallElevation(moveTimeHalf, false, -speedZ);

            MoveSplineInit init = new MoveSplineInit(_owner);

            init.MoveTo(x, y, z, false);
            init.SetParabolic(max_height, 0);
            init.SetVelocity(speedXY);
            if (hasOrientation)
            {
                init.SetFacing(o);
            }
            if (spellEffectExtraData != null)
            {
                init.SetSpellEffectExtraData(spellEffectExtraData);
            }
            init.Launch();

            uint       arrivalSpellId         = 0;
            ObjectGuid arrivalSpellTargetGuid = ObjectGuid.Empty;

            if (arrivalCast != null)
            {
                arrivalSpellId         = arrivalCast.SpellId;
                arrivalSpellTargetGuid = arrivalCast.Target;
            }

            StartMovement(new EffectMovementGenerator(id, arrivalSpellId, arrivalSpellTargetGuid), MovementSlot.Controlled);
        }
示例#2
0
        public void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null)
        {
            //this function may make players fall below map
            if (_owner.IsTypeId(TypeId.Player))
            {
                return;
            }

            if (speedXY < 0.01f)
            {
                return;
            }

            float x, y, z;
            float moveTimeHalf = (float)(speedZ / gravity);
            float dist         = 2 * moveTimeHalf * speedXY;
            float max_height   = -MoveSpline.ComputeFallElevation(moveTimeHalf, false, -speedZ);

            _owner.GetNearPoint(_owner, out x, out y, out z, _owner.GetObjectSize(), dist, _owner.GetAngle(srcX, srcY) + MathFunctions.PI);

            MoveSplineInit init = new MoveSplineInit(_owner);

            init.MoveTo(x, y, z);
            init.SetParabolic(max_height, 0);
            init.SetOrientationFixed(true);
            init.SetVelocity(speedXY);
            if (spellEffectExtraData != null)
            {
                init.SetSpellEffectExtraData(spellEffectExtraData);
            }

            init.Launch();
            StartMovement(new EffectMovementGenerator(0), MovementSlot.Controlled);
        }
示例#3
0
        public void Stop()
        {
            MoveSpline move_spline = unit.moveSpline;

            // No need to stop if we are not moving
            if (move_spline.Finalized())
            {
                return;
            }

            bool    transport = !unit.GetTransGUID().IsEmpty();
            Vector4 loc       = new Vector4();

            if (move_spline.onTransport == transport)
            {
                loc = move_spline.ComputePosition();
            }
            else
            {
                Position pos;
                if (!transport)
                {
                    pos = unit;
                }
                else
                {
                    pos = unit.m_movementInfo.transport.pos;
                }

                loc.X = pos.GetPositionX();
                loc.Y = pos.GetPositionY();
                loc.Z = pos.GetPositionZ();
                loc.W = unit.GetOrientation();
            }

            args.flags.Flags = SplineFlag.Done;
            unit.m_movementInfo.RemoveMovementFlag(MovementFlag.Forward);
            move_spline.onTransport = transport;
            move_spline.Initialize(args);

            MonsterMove packet = new MonsterMove();

            packet.MoverGUID = unit.GetGUID();
            packet.Pos       = new Vector3(loc.X, loc.Y, loc.Z);
            packet.SplineData.StopDistanceTolerance = 2;
            packet.SplineData.ID = move_spline.GetId();

            if (transport)
            {
                packet.SplineData.Move.TransportGUID = unit.GetTransGUID();
                packet.SplineData.Move.VehicleSeat   = unit.GetTransSeat();
            }

            unit.SendMessageToSet(packet, true);
        }
示例#4
0
        public int Launch()
        {
            MoveSpline move_spline = unit.moveSpline;

            bool    transport     = !unit.GetTransGUID().IsEmpty();
            Vector4 real_position = new Vector4();

            // there is a big chance that current position is unknown if current state is not finalized, need compute it
            // this also allows calculate spline position and update map position in much greater intervals
            // Don't compute for transport movement if the unit is in a motion between two transports
            if (!move_spline.Finalized() && move_spline.onTransport == transport)
            {
                real_position = move_spline.ComputePosition();
            }
            else
            {
                Position pos;
                if (!transport)
                {
                    pos = unit;
                }
                else
                {
                    pos = unit.m_movementInfo.transport.pos;
                }

                real_position.X = pos.GetPositionX();
                real_position.Y = pos.GetPositionY();
                real_position.Z = pos.GetPositionZ();
                real_position.W = unit.GetOrientation();
            }

            // should i do the things that user should do? - no.
            if (args.path.Length == 0)
            {
                return(0);
            }

            // correct first vertex
            args.path[0]            = new Vector3(real_position.X, real_position.Y, real_position.Z);
            args.initialOrientation = real_position.W;
            move_spline.onTransport = !unit.GetTransGUID().IsEmpty();

            MovementFlag moveFlags = unit.m_movementInfo.GetMovementFlags();

            if (!args.flags.hasFlag(SplineFlag.Backward))
            {
                moveFlags = (moveFlags & ~MovementFlag.Backward) | MovementFlag.Forward;
            }
            else
            {
                moveFlags = (moveFlags & ~MovementFlag.Forward) | MovementFlag.Backward;
            }

            if (Convert.ToBoolean(moveFlags & MovementFlag.Root))
            {
                moveFlags &= ~MovementFlag.MaskMoving;
            }

            if (!args.HasVelocity)
            {
                // If spline is initialized with SetWalk method it only means we need to select
                // walk move speed for it but not add walk flag to unit
                var moveFlagsForSpeed = moveFlags;
                if (args.walk)
                {
                    moveFlagsForSpeed |= MovementFlag.Walking;
                }
                else
                {
                    moveFlagsForSpeed &= ~MovementFlag.Walking;
                }

                args.velocity = unit.GetSpeed(SelectSpeedType(moveFlagsForSpeed));
            }

            if (!args.Validate(unit))
            {
                return(0);
            }

            unit.m_movementInfo.SetMovementFlags(moveFlags);
            move_spline.Initialize(args);

            MonsterMove packet = new MonsterMove();

            packet.MoverGUID = unit.GetGUID();
            packet.Pos       = new Vector3(real_position.X, real_position.Y, real_position.Z);
            packet.InitializeSplineData(move_spline);
            if (transport)
            {
                packet.SplineData.Move.TransportGUID = unit.GetTransGUID();
                packet.SplineData.Move.VehicleSeat   = unit.GetTransSeat();
            }
            unit.SendMessageToSet(packet, true);

            return(move_spline.Duration());
        }
示例#5
0
        public int Launch()
        {
            MoveSpline move_spline = unit.MoveSpline;

            bool    transport     = !unit.GetTransGUID().IsEmpty();
            Vector4 real_position = new();

            // there is a big chance that current position is unknown if current state is not finalized, need compute it
            // this also allows calculate spline position and update map position in much greater intervals
            // Don't compute for transport movement if the unit is in a motion between two transports
            if (!move_spline.Finalized() && move_spline.onTransport == transport)
            {
                real_position = move_spline.ComputePosition();
            }
            else
            {
                Position pos;
                if (!transport)
                {
                    pos = unit;
                }
                else
                {
                    pos = unit.m_movementInfo.transport.pos;
                }

                real_position.X = pos.GetPositionX();
                real_position.Y = pos.GetPositionY();
                real_position.Z = pos.GetPositionZ();
                real_position.W = unit.GetOrientation();
            }

            // should i do the things that user should do? - no.
            if (args.path.Length == 0)
            {
                return(0);
            }

            // correct first vertex
            args.path[0]            = new Vector3(real_position.X, real_position.Y, real_position.Z);
            args.initialOrientation = real_position.W;
            args.flags.SetUnsetFlag(SplineFlag.EnterCycle, args.flags.HasFlag(SplineFlag.Cyclic));
            move_spline.onTransport = transport;

            MovementFlag moveFlags = unit.m_movementInfo.GetMovementFlags();

            if (!args.flags.HasFlag(SplineFlag.Backward))
            {
                moveFlags = (moveFlags & ~MovementFlag.Backward) | MovementFlag.Forward;
            }
            else
            {
                moveFlags = (moveFlags & ~MovementFlag.Forward) | MovementFlag.Backward;
            }

            if (Convert.ToBoolean(moveFlags & MovementFlag.Root))
            {
                moveFlags &= ~MovementFlag.MaskMoving;
            }

            if (!args.HasVelocity)
            {
                // If spline is initialized with SetWalk method it only means we need to select
                // walk move speed for it but not add walk flag to unit
                var moveFlagsForSpeed = moveFlags;
                if (args.walk)
                {
                    moveFlagsForSpeed |= MovementFlag.Walking;
                }
                else
                {
                    moveFlagsForSpeed &= ~MovementFlag.Walking;
                }

                args.velocity = unit.GetSpeed(SelectSpeedType(moveFlagsForSpeed));
                Creature creature = unit.ToCreature();
                if (creature != null)
                {
                    if (creature.HasSearchedAssistance())
                    {
                        args.velocity *= 0.66f;
                    }
                }
            }

            // limit the speed in the same way the client does
            float speedLimit()
            {
                if (args.flags.HasFlag(SplineFlag.UnlimitedSpeed))
                {
                    return(float.MaxValue);
                }

                if (args.flags.HasFlag(SplineFlag.Falling) || args.flags.HasFlag(SplineFlag.Catmullrom) || args.flags.HasFlag(SplineFlag.Flying) || args.flags.HasFlag(SplineFlag.Parabolic))
                {
                    return(50.0f);
                }

                return(Math.Max(28.0f, unit.GetSpeed(UnitMoveType.Run) * 4.0f));
            };

            args.velocity = Math.Min(args.velocity, speedLimit());

            if (!args.Validate(unit))
            {
                return(0);
            }

            unit.m_movementInfo.SetMovementFlags(moveFlags);
            move_spline.Initialize(args);

            MonsterMove packet = new();

            packet.MoverGUID = unit.GetGUID();
            packet.Pos       = new Vector3(real_position.X, real_position.Y, real_position.Z);
            packet.InitializeSplineData(move_spline);
            if (transport)
            {
                packet.SplineData.Move.TransportGUID = unit.GetTransGUID();
                packet.SplineData.Move.VehicleSeat   = unit.GetTransSeat();
            }
            unit.SendMessageToSet(packet, true);

            return(move_spline.Duration());
        }