RiftMayhem/Assets/Scripts/AbilitySystem/Effects/AbsorbEffectInstance.cs
2025-02-21 18:35:51 +00:00

125 lines
2.9 KiB
C#

using Kryz.CharacterStats;
using Kryz.CharacterStats.Examples;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class AbsorbEffectInstance : StatusEffectInstance
{
public float startingAmount;
public float currentAmount;
public UnityEvent OnAbsorbDamage = new UnityEvent();
float income;
protected override void Awake()
{
}
public float AbsorbDamage(float income)
{
this.income = income;
this.income += currentAmount;
if (this.income >= 0)
{
currentAmount = this.income;
}
else
{
StopCoroutine(effectStateCoroutine);
EffectStateEnded();
}
OnAbsorbDamage.Invoke();
return this.income;
}
public float GetHighestAmount(float value)
{
float highestAmount = value;
for (int i = activeStacks.Count - 1; i >= 0; i--)
{
if (((AbsorbEffect)activeStacks[i]).amount > highestAmount)
highestAmount = ((AbsorbEffect)activeStacks[i]).amount;
}
return highestAmount;
}
public override void ApplyEffect(StatusEffect effect, float value)
{
base.ApplyEffect(effect, value);
}
protected override void AddStack(StatusEffect addedEffect, float value)
{
if (activeStacks.Count <= 0)
{
startingAmount = value;
currentAmount = startingAmount;
}
else if (canStack)
{
currentAmount += value;
}
base.AddStack(addedEffect, value);
}
protected override void RefreshEffect(StatusEffect effect, float value)
{
base.RefreshEffect(effect, value);
startingAmount = GetHighestAmount(value);
currentAmount = startingAmount;
OnEffectStackAdded();
}
protected override IEnumerator EffectStateCoroutine()
{
return base.EffectStateCoroutine();
}
protected override void EffectStateStarted()
{
base.EffectStateStarted();
}
protected override void EffectStateEnded()
{
startingAmount = 0;
currentAmount = startingAmount;
base.EffectStateEnded();
}
/*
private CharacterStat GetCorrectStat(CharacterStats stats) //TODO: make it use multiple stats correctly
{
for (int i = 0; i < influencingStats.Count; i++)
{
if (stats.statsDictionary.ContainsKey(influencingStats[i].name.ToLower()))
{
Debug.Log($"Influencing effect using: {influencingStats[i].name.ToLower()}");
return stats.statsDictionary[influencingStats[i].name.ToLower()];
}
}
return null;
}
private void GetFinalValue(CharacterStat stat)
{
if (stat == null)
finalValue = baseValue;
else
finalValue = baseValue + stat.Value * percentStatInfluence;
}*/
}