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

/// <summary>
/// Manages the resetting of game attributes and player properties.
/// </summary>
public class Reset : MonoBehaviour
{
    public GameObject player; // Reference to the player GameObject
    private PlayerController controller; // Reference to our player controller

    public static Reset instance; // Singleton instance of Reset

    private float defaultSpeed;
    private float defaultRotation;
    private float defaultBoost;
    private int defaultShield;
    private int defaultDamage;
    private float defaultFireRate;

    /// <summary>
    /// Initializes the singleton instance.
    /// </summary>
    private void Awake()
    {
        instance = this;

        // Instantiate a player
        player = ShapeSelect.selectedShape;
        controller = player.GetComponent<PlayerController>();

        // Set the default player stats
        defaultSpeed = controller.maxSpeed;
        defaultRotation = controller.rotateSpeed;
        defaultBoost = controller.dashSpeedBoost;
        defaultShield = player.GetComponentInChildren<Shield>().maxShieldHealth;
        defaultDamage = player.GetComponentInChildren<Weapon>().bulletDamage;
        defaultFireRate = player.GetComponentInChildren<Weapon>().shootCooldown;
    }


    /// <summary>
    /// Resets game attributes and player properties to default values.
    /// </summary>
    public void ResetGame()
    {
        controller.maxSpeed = defaultSpeed; // Reset maximum speed of the player
        controller.rotateSpeed = defaultRotation; // Reset rotation speed of the player
        controller.dashSpeedBoost = defaultBoost; // Reset dash speed boost of the player

        // Reset shield properties
        Shield shield = player.GetComponentInChildren<Shield>();
        shield.maxShieldHealth = defaultShield; // Reset maximum shield health of the player

        // Reset weapon properties
        Weapon weapon = player.GetComponentInChildren<Weapon>();
        weapon.bulletDamage = defaultDamage; // Reset bullet damage of the player's weapon
        weapon.shootCooldown = defaultFireRate; // Reset shoot cooldown of the player's weapon
    }
}
