RiftMayhem/Assets/Scripts/Player/AbilityKeyBinder.cs
Pedro Gomes 2773ef7d6e Player Death Update
- Players can now die (finally)
- Solo players have a single cheat death per scene (reviving automatically after the first death)
- group players have revive mechanic, where a player faints when his health gets to 0, creating a revive circle around him, other players can stand on it to revive him. if after x seconds they don't get revived they bleed out and stay perma death until scene changes or all players die
- Multiple VFX added using post processing for cheat death, fainting, reviving, and perma death events.
- stopped players from moving and pressing keys when dead
- enemies now change target if they try to attack a dead/fainted target.
2024-07-20 19:49:14 +01:00

115 lines
3.3 KiB
C#

using Kryz.CharacterStats.Examples;
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AbilityKeyBinder : MonoBehaviour
{
[Header("Listeners:")]
[SerializeField] private GameEventListener onLocalPlayerFainted;
[SerializeField] private GameEventListener onLocalPlayerPermaDeath;
[SerializeField] private GameEventListener onLocalPlayerRevived;
[Space]
[SerializeField] private BaseAbility ability;
[SerializeField] private GameKey key;
[SerializeField] private CastingStateController castingStateController;
[SerializeField] private GameEvent_AbilityKeyBinder onAbilityKeyBinderSpawned;
private PhotonView user;
private Taggable userTag;
private Mana mana;
public BaseAbility Ability => ability;
public GameKey GameKey => key;
Coroutine currentChanneling;
NetworkedChanneling networkedChanneling;
AbilityBindInstance abilityBindInstance;
bool isDead = false;
private void Awake()
{
user = GetComponentInParent<PhotonView>();
userTag = GetComponentInParent<Taggable>();
mana = GetComponentInParent<Mana>();
}
private void Start()
{
if (!user.IsMine)
{
this.enabled = false;
return;
}
onLocalPlayerFainted.Response.AddListener(() =>
{
isDead = true;
});
onLocalPlayerPermaDeath.Response.AddListener(() =>
{
isDead = true;
});
onLocalPlayerRevived.Response.AddListener(() =>
{
isDead = false;
});
onAbilityKeyBinderSpawned.Raise(this);
}
// Update is called once per frame
void Update()
{
if (isDead) return;
if (Input.GetKeyDown(key.keyCode))
{
if (abilityBindInstance != null)
abilityBindInstance.pressed.SetActive(true);
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 (abilityBindInstance != null)
abilityBindInstance.pressed.SetActive(false);
if (currentChanneling != null)
{
StopCoroutine(currentChanneling);
castingStateController.ResetChannelingCast();
CastBarHandler.Instance.CancelChannelingOnButtonReleased();
}
if (networkedChanneling != null)
{
networkedChanneling.channeling = false;
networkedChanneling.DisableVisuals();
}
}
}
public void SetupAbilityBindInstance(AbilityBindInstance abilityBindInstance)
{
this.abilityBindInstance = abilityBindInstance;
mana.onResourceChanged.AddListener(OnManaChanged);
}
public void OnManaChanged(float currentMana)
{
abilityBindInstance.noMana.SetActive(!mana.EnoughMana(ability.manaCost));
}
}