RiftMayhem/Assets/Scripts/Networking/ClassResourceSpender.cs

43 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClassResourceSpender : MonoBehaviour
{
protected RiftPlayer player;
protected Taggable playerTag;
protected ClassResource classResource;
protected ClassAbilityPriorityManager abilityPriorityManager;
protected AbilityCooldownTracker abilityCooldownTracker;
protected virtual void Awake()
{
player = GetComponentInParent<RiftPlayer>();
abilityPriorityManager = player.GetComponentInChildren<ClassAbilityPriorityManager>();
abilityCooldownTracker = player.GetComponentInChildren<AbilityCooldownTracker>();
playerTag = player.GetComponent<Taggable>();
classResource = player.GetComponent<ClassResource>();
classResource.onResourceChanged.AddListener(OnClassResourceValueChanged);
}
public virtual void OnClassResourceValueChanged(float value)
{
BaseAbility autocastAbility = abilityPriorityManager.GetHighestPriorityAvailableAbility();
if (autocastAbility == null)
{
Debug.Log("No abilities available for current conditional state");
return;
}
autocastAbility.Execute(player.photonView, playerTag);
if (autocastAbility.cooldown > 0)
abilityCooldownTracker.StartAbilityCooldown(autocastAbility);
}
}