To add a cooldown time to your card so that it cannot activate until the cooldown is finished, you would need to implement a cooldown mechanism within the CombatCard class. The following changes involve setting the Disabled field to true when the card is activated and then waiting for the cooldown time to elapse before setting Disabled back to false. During this cooldown, we wouldn't allow card activation. I've added comments in the code to help guide you through the changes:
using System.Collections;
using System.Threading.Tasks;
using Game.Systems;
using UnityEngine;
namespace Cards
{
public class CombatCard : CardBase
{
[SerializeField] private GameObject disabledPanel;
[SerializeField] private float coolDownTime = 5f;
public bool Disabled { get; private set; } // Ensure proper encapsulation
private CombatPlacer objectPlacer;
private BattleHandController handController;
private GameManager gameManager;
private bool isCooldownActive; // Flag to indicate whether cooldown is currently active
public override void Init(int turn)
{
base.Init(turn);
this.objectPlacer = GameManager.Instance.BattleCardController.CombatPlacer;
this.handController = GameManager.Instance.BattleCardController.battleHandController;
}
private void Start()
{
Disabled = false;
isCooldownActive = false; // Initialize cooldown flag
disabledPanel.SetActive(Disabled);
}
// Removed Update() as it's empty and not used
public override async Task ActivateCard()
{
if (Disabled || isCooldownActive)
{
// If the card is disabled or cooldown is active, don't activate the card
return;
}
// Implement the cooldown mechanism
Disabled = true; // Disable the card before activating
isCooldownActive = true; // Cooldown starts
disabledPanel.SetActive(true);
await base.ActivateCard();
GameManager.Instance.BattleCardController.battleHandController.Active = true;
objectPlacer.Setup(prefab, this);
// Wait for cooldown time to finish
await Task.Delay((int)(coolDownTime * 1000));
// Cooldown finished, enable the card
isCooldownActive = false;
Disabled = false;
disabledPanel.SetActive(false);
}
// Make sure to reset cooldown when discarding the card
public override void Discard()
{
Disabled = false; // Reset disabled state
isCooldownActive = false; // Ensure cooldown is not active
disabledPanel.SetActive(false);
}
}
}
These modifications add a cooldown system that prevents the card from being activated again until the cooldown has finished. Disabled is initially set to false, and when ActivateCard is called, it will check if the card is currently disabled or if a cooldown is active before proceeding. If the card isn't on cooldown and isn't disabled, ActivateCard will commence its actions, subsequently initiating a cooldown period during which the card is set to disabled.
Remember that depending on the rest of your game's architecture, you might need to adjust where and how Discard is called to ensure that the cooldown is properly reset when needed.