- 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.
109 lines
2.5 KiB
C#
109 lines
2.5 KiB
C#
using Kryz.CharacterStats.Examples;
|
|
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class Mana : Resource
|
|
{
|
|
CharacterStats character;
|
|
|
|
public UnityEvent<float> onMaxManaChanged = new UnityEvent<float>();
|
|
|
|
[HideInInspector]
|
|
public PhotonView photonView;
|
|
|
|
private bool noCost = false;
|
|
public bool NoCost => noCost;
|
|
|
|
public UnityEvent<bool> OnNoManaCostStateChanged = new UnityEvent<bool>();
|
|
|
|
private void Awake()
|
|
{
|
|
character = GetComponent<CharacterStats>();
|
|
photonView = GetComponent<PhotonView>();
|
|
|
|
baseMaxValue = maxValue;
|
|
baseFlatRegen = flatRegen;
|
|
|
|
character.onUpdateStatValues.AddListener(CalculateMaxValueBasedOnStat);
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
|
|
base.Start();
|
|
}
|
|
|
|
public void SetNoCostState(bool noManaCost)
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
|
|
photonView.RPC(nameof(RPC_SetNoCostState), RpcTarget.All, noManaCost);
|
|
}
|
|
|
|
[PunRPC]
|
|
public void RPC_SetNoCostState(bool noManaCost)
|
|
{
|
|
noCost = noManaCost;
|
|
OnNoManaCostStateChanged.Invoke(noCost);
|
|
}
|
|
|
|
public override void ChangeValue(float value)
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
|
|
if (noCost && value < 0) return;
|
|
|
|
currentValue += value;
|
|
|
|
currentValue = Mathf.Clamp(currentValue, 0, maxValue);
|
|
|
|
onResourceChanged.Invoke(currentValue);
|
|
}
|
|
|
|
[PunRPC]
|
|
public void RPC_ChangeValueMana (float value)
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
Debug.Log("Received ChangeValue from RPC from someone");
|
|
ChangeValue(value);
|
|
}
|
|
|
|
public override float GetMaxValue()
|
|
{
|
|
|
|
return base.GetMaxValue();
|
|
}
|
|
|
|
public bool EnoughMana(float cost)
|
|
{
|
|
if (noCost) return true;
|
|
|
|
return cost <= currentValue;
|
|
}
|
|
|
|
public void CalculateMaxValueBasedOnStat()
|
|
{
|
|
maxValue = baseMaxValue + character.Intelligence.Value * 10f;
|
|
|
|
CalculateRegenValueBasedOnStat();
|
|
|
|
onMaxManaChanged.Invoke(maxValue);
|
|
}
|
|
public void CalculateRegenValueBasedOnStat()
|
|
{
|
|
flatRegen = baseFlatRegen + (character.Spirit.Value - character.Spirit.BaseValue) * 0.5f;
|
|
percentRegen = (character.Spirit.Value - character.Spirit.BaseValue) * 0.01f;
|
|
}
|
|
|
|
public override void SetMaxValue(float value)
|
|
{
|
|
base.SetMaxValue(value);
|
|
|
|
onMaxManaChanged.Invoke(maxValue);
|
|
}
|
|
}
|