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

[System.Serializable]
public class PoweredObject:MonoBehaviour
{
    public CommandList.Command command;
    int maxPower = 1;
    int power;
    public Slider Display;
    HeadControl head;
    private void Start()
    {
        head = GetComponentInParent<HeadControl>();
        Display.maxValue = maxPower * 100;
        Display.value = power * 100;
    }
    private void Update()
    {
        //Display.gameObject.transform.position = Camera.main.WorldToViewportPoint(transform.position);
    }
    private void OnMouseDown()
    {
        if(Input.GetKeyDown(KeyCode.Mouse0))
        {
            IncreasePower();
        }
        if (Input.GetKeyDown(KeyCode.Mouse1))
        {
            DecreasePower();
        }
    }
    public int GetPower()
    {
        return power;
    }
    public int GetMaxPower()
    {
        return maxPower;
    }

    public void Upgrade()
    {
        maxPower++;
        Display.maxValue = maxPower*100;
    }
    public bool IncreasePower()
    {
        if (power < maxPower)
        {
            power++;
            print("Increasing Power");
            Display.value = power*100;
            return true;
        }
        return false;
    }
    public bool DecreasePower()
    {
        if (power > 0)
        {
            power--;
            print("Decreasing Power");
            Display.value = power*100;
            return true;
        }
        return false;
    }

    public void AddCommand()
    {
        head.AddCommand(command);
        print(command);
    }
}