RiftMayhem/Assets/Scripts/Networking/NetworkedBaseAbility.cs
2025-02-21 18:35:51 +00:00

81 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NetworkedBaseAbility : MonoBehaviour
{
[Header("Common Settings")]
public Taggable ownerTag;
public BaseAbility ability;
public float lifeSpan;
public bool canHitSelf;
[SerializeField] protected GameObject visuals;
[SerializeField] protected LayerMask abilityHitLayer;
protected bool waitingForDestroy = false;
protected List<Taggable> targets = new List<Taggable>();
protected Taggable possibleTarget;
protected virtual void Awake()
{
}
public virtual void Init()
{
StartCoroutine(SelfDestruct());
}
protected virtual IEnumerator SelfDestruct()
{
yield return new WaitForSeconds(lifeSpan);
waitingForDestroy = true;
StartCoroutine(DelayedDestroy());
}
protected virtual IEnumerator DelayedDestroy()
{
DisableVisuals();
yield return new WaitForSeconds(1.5f);
Destroy(this.gameObject);
}
protected virtual void DisableVisuals()
{
if (visuals != null)
{
visuals.SetActive(false);
}
}
protected virtual bool IsValidTarget(Taggable target)
{
if (target == null) return false;
if (!canHitSelf && target == ownerTag) return false;
return target.IsValidTarget(ability.targettingTags);
}
protected virtual bool IsValidTarget(Collider collider)
{
possibleTarget = collider.GetComponentInParent<Taggable>();
if (possibleTarget == null) return false;
if (!canHitSelf && possibleTarget == ownerTag) return false;
if (!possibleTarget.IsValidTarget(ability.targettingTags)) return false;
return true;
}
protected virtual void ApplyEffects(List<Taggable> targets)
{
foreach (BaseEffect effect in ability.abilityEffects)
{
effect.ApplyEffect(ownerTag, targets);
}
}
}