50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Abilities/Channel Heal")]
|
|
public class ChannelHealAbility : Ability
|
|
{
|
|
public float channelTime = 5f; // seconds to wait
|
|
public float healAmount = 50f; // how much to heal
|
|
|
|
public override void Activate(AbilityUser user)
|
|
{
|
|
if (!user) return;
|
|
user.StartCoroutine(ChannelRoutine(user));
|
|
}
|
|
|
|
private IEnumerator ChannelRoutine(AbilityUser user)
|
|
{
|
|
float elapsed = 0f;
|
|
|
|
while (elapsed < channelTime)
|
|
{
|
|
// Cancel if player moves
|
|
if (IsPlayerMoving())
|
|
{
|
|
Debug.Log("Heal cancelled: player moved.");
|
|
yield break;
|
|
}
|
|
|
|
elapsed += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
|
|
// Heal and spend mana on completion
|
|
if (user.mana && !user.mana.Spend(manaCost))
|
|
{
|
|
Debug.Log("Not enough mana to complete heal.");
|
|
yield break;
|
|
}
|
|
|
|
if (user.health) user.health.Heal(healAmount);
|
|
Debug.Log($"Healed {healAmount} HP after channel.");
|
|
}
|
|
|
|
private bool IsPlayerMoving()
|
|
{
|
|
float h = Input.GetAxisRaw("Horizontal");
|
|
float v = Input.GetAxisRaw("Vertical");
|
|
return (Mathf.Abs(h) > 0.01f || Mathf.Abs(v) > 0.01f);
|
|
}
|
|
} |