|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Unity.Netcode;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class AbilitySystem : MonoBehaviour
|
|
|
|
@ -10,37 +10,39 @@ public class AbilitySystem : MonoBehaviour
|
|
|
|
|
private Ability activeAbility; // Tracks the currently active ability in "spawn mode"
|
|
|
|
|
private bool isAbilityActive = false;
|
|
|
|
|
|
|
|
|
|
private HashSet<Ability> abilitiesOnCooldown = new HashSet<Ability>();
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
// If ability mode is active, listen for mouse input to activate ability
|
|
|
|
|
if (isAbilityActive && Input.GetMouseButtonDown(0))
|
|
|
|
|
{
|
|
|
|
|
UseActiveAbility();
|
|
|
|
|
ToggleAbilityMode(activeAbility);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Activates ability by key (called externally).
|
|
|
|
|
/// Activates an ability by its keybind.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">The key assigned to an ability.</param>
|
|
|
|
|
public void ActivateAbilityByKey(string key)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ability in abilities)
|
|
|
|
|
{
|
|
|
|
|
if (ability.abilityKey == key)
|
|
|
|
|
{
|
|
|
|
|
if (!abilitiesOnCooldown.Contains(ability))
|
|
|
|
|
{
|
|
|
|
|
ToggleAbilityMode(ability);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"{ability.abilityName} is on cooldown.");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Debug.LogWarning($"No ability assigned to key {key}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggles the ability activation mode.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ability">The ability to toggle.</param>
|
|
|
|
|
private void ToggleAbilityMode(Ability ability)
|
|
|
|
|
{
|
|
|
|
|
if (isAbilityActive && activeAbility == ability)
|
|
|
|
@ -57,7 +59,7 @@ public class AbilitySystem : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
isAbilityActive = true;
|
|
|
|
|
activeAbility = ability;
|
|
|
|
|
Debug.Log($"Ability {ability.name} activated! Click to use.");
|
|
|
|
|
Debug.Log($"Ability {ability.abilityName} activated! Click to use.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeactivateAbilityMode()
|
|
|
|
@ -71,8 +73,23 @@ public class AbilitySystem : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
if (activeAbility != null)
|
|
|
|
|
{
|
|
|
|
|
activeAbility.TryActivate(gameObject);
|
|
|
|
|
DeactivateAbilityMode(); // Ability used, deactivate mode
|
|
|
|
|
activeAbility.ActivateAbility(gameObject);
|
|
|
|
|
StartCoroutine(StartCooldown(activeAbility));
|
|
|
|
|
DeactivateAbilityMode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Starts the cooldown coroutine for the ability.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IEnumerator StartCooldown(Ability ability)
|
|
|
|
|
{
|
|
|
|
|
abilitiesOnCooldown.Add(ability);
|
|
|
|
|
Debug.Log($"{ability.abilityName} is now on cooldown for {ability.cooldownTime} seconds.");
|
|
|
|
|
|
|
|
|
|
yield return new WaitForSeconds(ability.cooldownTime);
|
|
|
|
|
|
|
|
|
|
abilitiesOnCooldown.Remove(ability);
|
|
|
|
|
Debug.Log($"{ability.abilityName} is off cooldown.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|