108 lines
2.6 KiB
C#
108 lines
2.6 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>();
|
|
|
|
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 * GameConstants.CharacterStatsBalancing.IntelligenceToManaRate;
|
|
|
|
CalculateRegenValueBasedOnStat();
|
|
|
|
onMaxManaChanged.Invoke(maxValue);
|
|
}
|
|
public void CalculateRegenValueBasedOnStat()
|
|
{
|
|
flatRegen = baseFlatRegen + (character.Spirit.Value - character.Spirit.BaseValue) * GameConstants.CharacterStatsBalancing.BonusSpiritToFlatRegenRate;
|
|
//percentRegen = (character.Spirit.Value - character.Spirit.BaseValue) * GameConstants.CharacterBalancing.BonusSpiritToPercentRegenRate;
|
|
}
|
|
|
|
public override void SetMaxValue(float value)
|
|
{
|
|
base.SetMaxValue(value);
|
|
|
|
onMaxManaChanged.Invoke(maxValue);
|
|
}
|
|
}
|