﻿using UnityEngine;
using RootMotion.FinalIK;

namespace HutongGames.PlayMaker.Actions
{
    // The base abstract class for all Interaction System related actions
    [ActionCategory("Final IK")]
    [Tooltip("Starts a recoil with the Recoil component.")]
    public class RecoilAction : FsmStateAction
    {

        [RequiredField]
        [CheckForComponent(typeof(Recoil))]
        [CheckForComponent(typeof(FullBodyBipedIK))]
        [Tooltip("The gameobject with the Recoil component")]
        public FsmOwnerDefault recoil;

        [Tooltip("The recoil magnitude")]
        public FsmFloat magnitude;

        public override void Reset()
        {
            recoil = null;
            magnitude = new FsmFloat() { UseVariable = true };
        }

        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(recoil);
            if (go == null) return;

            var r = go.GetComponent<Recoil>();
            if (r == null) return;

            r.Fire(magnitude.Value);

            Finish();
        }
    }
}
