56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Core.Extensions;
|
|
using UnityEngine;
|
|
|
|
public class LunaticRedEyes : Ability
|
|
{
|
|
private List<Entity> entitiesInRange = new();
|
|
[SerializeField] private StunEffect stunEffect;
|
|
[Header("Effect Chances")]
|
|
[SerializeField] private float effectChance;
|
|
[SerializeField] private float hypnotismChance;
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
transform.Lookat2D(thisEntity.attackOriginPoint.position);
|
|
}
|
|
|
|
protected override void AbilityEffects()
|
|
{
|
|
base.AbilityEffects();
|
|
foreach (Entity entity in entitiesInRange.ToList())
|
|
{
|
|
float rolledEffectChance = Random.Range(0, 100);
|
|
if (rolledEffectChance > 100 - effectChance) //so if i made it 80 percent, it would need to be higher than 20
|
|
{
|
|
float rolledHypnotismChance = Random.Range(0, 100);
|
|
if (rolledHypnotismChance > 100 - hypnotismChance)
|
|
{
|
|
entity.tag = thisEntity.tag;
|
|
entity.entitiesInRange.Clear();
|
|
}
|
|
else
|
|
{
|
|
stunEffect.ApplyEffect(entity.stats);
|
|
}
|
|
entitiesInRange.Remove(entity);
|
|
}
|
|
}
|
|
|
|
}
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (!other.CompareTag(thisEntity.tag) && other.TryGetComponent(out Entity isEntity))
|
|
{
|
|
entitiesInRange.Add(isEntity);
|
|
}
|
|
}
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
{
|
|
if (!other.CompareTag(thisEntity.tag) && other.TryGetComponent(out Entity isEntity) && entitiesInRange.Contains(isEntity))
|
|
{
|
|
entitiesInRange.Remove(isEntity);
|
|
}
|
|
}
|
|
}
|