Ejemplo n.º 1
0
        public void SetPlayerFacing(Location destination, float threshold = 0.2f, bool forceMemoryWrite = false)
        {
            if (destination == null)
            {
                return;
            }

            const float memoryWriteThreshold = 1.5f;

            var radian   = Radian.GetFaceRadian(destination, ObjectManager.Me.Location);
            var nudgeKey = MappedKeys.Left;

            var difference         = ObjectManager.Me.Rotation - radian.Angle;
            var absoluteDifference = Math.Abs(difference);

            if (absoluteDifference < threshold)
            {
                return;
            }

            if (absoluteDifference > memoryWriteThreshold || forceMemoryWrite)
            {
                _logger.Information("Set player facing using memory write");
                InternalSetPlayerFacing(radian, nudgeKey);
                return;
            }

            var direction = difference > 0 ? MappedKeys.Right : MappedKeys.Left;

            while (absoluteDifference > threshold)
            {
                SendKeyDown(direction);

                radian             = Radian.GetFaceRadian(destination, ObjectManager.Me.Location);
                absoluteDifference = Math.Abs(ObjectManager.Me.Rotation - radian.Angle);

                if (absoluteDifference > memoryWriteThreshold)
                {
                    _logger.Information("Set player facing using memory write");
                    InternalSetPlayerFacing(radian, nudgeKey);
                    break;
                }
            }

            SendKeyUp(direction);
        }