using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PillMoving : MonoBehaviour
{
    private Controller controller;
    private DrawAbilityDescription drawDescription;

    private GameObject people;
    public string ability;
    public float impact, time;
    // Update is called once per frame
    void Awake() 
    {
        controller = GameObject.Find("Controller").GetComponent<Controller>();
        drawDescription = controller.drawDescription;
        people = GameObject.Find("People");
    }

    void Start() 
    {
        if (ability == "Ability02")
        {
            controller.pill02Objects.Add(gameObject);
        }
    }
    void Update()
    {
        //transform.localPosition += new Vector3(,0f,0f);
        if (people)
        {transform.position = Vector2.MoveTowards(transform.localPosition, people.transform.position,Time.deltaTime * (2f));}
        else
        {Destroy(this);}
    }

    void OnCollisionEnter2D(Collision2D other) 
    {
        switch(ability)
        {
            case "Ability01": 
                controller.ChangeImmunity( (impact * (100-controller.medImpact)/100) );
                Destroy(gameObject);
            break;

            case "Ability02": 
                GetComponent<SpriteRenderer>().enabled = false;
                GetComponent<CircleCollider2D>().enabled = false;
                gameObject.AddComponent<GiveImpact02>();
                GetComponent<GiveImpact02>().valueImpact = impact;
                GetComponent<GiveImpact02>().timeImpact = time;
                GetComponent<GiveImpact02>().parent = gameObject;
            break;

            case "Ability03": 
                controller.virusImpact = impact;
                Destroy(gameObject);

            break;

            case "Ability04": 
                for (int i=0; i<controller.virus02Objects.Count; i++) 
                {
                    Destroy(controller.virus02Objects[i]);
                }
                controller.medImpact = 0;
                Destroy(gameObject);
            break;

            case "Ability05": 
                controller.virusImpact = 100;
                GetComponent<SpriteRenderer>().enabled = false;
                GetComponent<CircleCollider2D>().enabled = false;
                gameObject.AddComponent<GiveImpact05>();
                GetComponent<GiveImpact05>().timeImpact = impact;
                GetComponent<GiveImpact05>().parent = gameObject;
            break;

            case "Ability06":
                controller.immunity = 100 - controller.immunity;
                controller.ChangeImmunity(0);
                Destroy(gameObject);
            break;
        }
    }
}
