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

public class PlayerController : MonoBehaviour
{
    
    [SerializeField] private float points;
    [SerializeField] private CannonScript cannon;
    //private FireRateUpgrade fireRateUpgrade;
    // Start is called before the first frame update
    void Start()
    {
        //fireRateUpgrade = new FireRateUpgrade("Fire rate 1", 10, 0.4f);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public bool OnUpgrade(Upgrade selectedUpgrade){
        if(points >= selectedUpgrade.GetCost()){
            points = points - selectedUpgrade.GetCost();
            return true;
        }
        return false;
    }

    public void UpgradeFireRate(FireRateUpgrade upgrade){
        cannon.SetFireRate(upgrade.GetFireRate());
    }

    public void UpgradeDamage(DamageUpgrade upgrade){
        cannon.SetDamage(upgrade.GetDamage());
    }

    public void UpgradeBullets(BulletsAmountUpgrade upgrade){
        cannon.SetBullets(upgrade.GetBullets());
    }
    
    public float GetPoints(){
        return points;
    }

    public void SetPoints(float nPoints){
        points = nPoints;
    }

    public void SpendPoints(float amount){
        if(amount <= points){
            points = points - amount;
        } 
    }

    public void GainPoints(float amount){
        points += amount;
    }
}
