using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using uTools;

public class Soul : MonoBehaviour
{
    public Rigidbody rb;
    public bool collected = false;
    public float lerpValue = 0.05f;
    public int addMp = 10;
    public uTweenPositionTarget tweenPos;
    public float flySpeed = 10f;
    public float upSpeed = 1;

    public void Burst(Vector3 velocity)
    {
        rb.isKinematic = false;
        rb.velocity = velocity;
        collected = false;
    }

    public async void BeCollect(int id)
    {
        rb.isKinematic = true;
        collected = true;
        tweenPos.from = transform;
        tweenPos.to = PlayersInput.instance[id].transform;
        tweenPos.duration = (tweenPos.from.position - tweenPos.to.position).magnitude / flySpeed;
        tweenPos.ResetToBeginning();
        tweenPos.PlayForward();
        await Task.Delay((int)(tweenPos.duration * 1000));
        BeGet(id);
        gameObject.SetActive(false);
    }

    public void BeGet(int id)
    {
        PlayersInput.instance[id].mp += addMp;
    }

    private void FixedUpdate()
    {
        Vector3 velocity = rb.velocity;
        velocity.y = upSpeed;
        rb.velocity = velocity;
    }
}
