RiftMayhem/Assets/Scripts/Player/AbilityKeyBinder.cs
Pedro Gomes 8e18305573 Spells update
- shield wall (second knight ability) added
- ragestorm (ultimate barbarian ability) added
- anti projectile type of spell
- channeled ability type
- small balance changes on abilities and statpoints per level
2024-07-05 19:37:02 +01:00

65 lines
1.9 KiB
C#

using Kryz.CharacterStats.Examples;
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AbilityKeyBinder : MonoBehaviour
{
[SerializeField] private BaseAbility ability;
[SerializeField] private GameKey key;
[SerializeField] private CastingStateController castingStateController;
private PhotonView user;
private Taggable userTag;
private Mana mana;
Coroutine currentChanneling;
NetworkedChanneling networkedChanneling;
private void Awake()
{
user = GetComponentInParent<PhotonView>();
userTag = GetComponentInParent<Taggable>();
mana = GetComponentInParent<Mana>();
}
private void Start()
{
if (!user.IsMine) this.enabled = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(key.keyCode))
{
if (mana.EnoughMana(ability.manaCost))
{
if(ability is ChanneledAbility)
{
castingStateController.RequestAbilityChannel(ability, () => networkedChanneling = ((ChanneledAbility)ability).ExecuteChannel(user, userTag, ref currentChanneling));
}
else
castingStateController.RequestAbilityCast(ability, () => ability.Execute(user, userTag));
}
}
if(Input.GetKeyUp(key.keyCode))
{
if (currentChanneling != null)
{
StopCoroutine(currentChanneling);
castingStateController.ResetChannelingCast();
CastBarHandler.Instance.CancelChannelingOnButtonReleased();
}
if(networkedChanneling != null)
{
networkedChanneling.channeling = false;
networkedChanneling.DisableVisuals();
}
}
}
}