Hi, i was actually trying to implement HOTs and DOTs,
i missed the other topic and just saw it when it got closed.
I saved those scripts for now, in my ever growing “made by Brian” folder xD
What would we do without him!
I did it like this, with a coroutine in the existing HealthEffect we already had,
just enable the bool, and set the amount of ticks and the interval.
have not found any problems with it so far, is this an acceptable way of doing it?
using RPG.Attributes;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RPG.Abilities.Effects
{
[CreateAssetMenu(fileName = "Health Effect", menuName = "RPG/Abilities/Effects/Health")]
public class HealthEffect : EffectStrategy
{
[SerializeField] float healthChange;
//Only when Hot or Dot
[SerializeField] bool healthChangeOverTime = false;
[SerializeField] int numberOfTicks = 5;
[SerializeField] float timeBetweenTicks = 2f;
float healthPerTick;
float ticksRemaining;
public override void StartEffect(AbilityData data, Action finished)
{
foreach(var target in data.GetTargets())
{
var health = target.GetComponent<Health>();
if (health)
{
if (healthChangeOverTime)
{
data.StartCoroutine(HealthChangeOverTime(data.GetUser(), health, finished));
}
else
{
if (healthChange < 0)
{
health.TakeDamage(data.GetUser(), -healthChange);
}
else
{
health.Heal(healthChange);
}
}
}
}
if(healthChangeOverTime) { return; }
finished();
}
public IEnumerator HealthChangeOverTime(GameObject user, Health health, Action finished)
{
healthPerTick = healthChange / numberOfTicks;
ticksRemaining = numberOfTicks;
while (ticksRemaining > 0 && !health.IsDead())
{
if(healthPerTick < 0)
{
health.TakeDamage(user, -healthPerTick);
}
else
{
health.Heal(healthPerTick);
}
yield return new WaitForSeconds(timeBetweenTicks);
ticksRemaining--;
}
finished();
yield break;
}
}
}