using System.Collections.Generic;
using Sandbox.ModAPI.Ingame;

namespace IngameScript
{
    partial class Program
    {
        public class BlockActionPiston : BlockAction
        {
            private IMyPistonBase _piston;
            private float _position;
            private float _velocity;

            public BlockActionPiston(
                IMyPistonBase piston,
                float position,
                float velocity = 2f
            )
            {
                _piston = piston;
                _position = position;
                _velocity = velocity;
            }

            protected override IEnumerator<bool> onRun()
            {
                _piston.MoveToPosition(_position, _velocity);

                float lastValue = -1f;
                while (lastValue != _piston.CurrentPosition)
                {
                    lastValue = _piston.CurrentPosition;
                    yield return true;
                }
            }
        }
    }
}