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

101 lines
2.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class NetworkedProjectileAreaOfEffectOverTimeWithTickEvent : NetworkedAreaOfEffectOverTime
{
[Header("Visuals")]
[SerializeField] private GameObject hitParticlesPrefab;
public ProjectileAbility projectileAbility;
public UnityEvent<Taggable, List<Taggable>> onTickHappened = new UnityEvent<Taggable, List<Taggable>>();
public UnityEvent<Taggable, List<Taggable>> onTargetHitByProjectile = new UnityEvent<Taggable, List<Taggable>>();
NetworkedAntiProjectile possibleBlock;
protected List<Taggable> processedTargets = new List<Taggable>();
protected List<Taggable> projectileTargets = new List<Taggable>();
public void InitProjectileStats()
{
}
private void Update()
{
if (waitingForDestroy) return;
this.transform.position += this.transform.forward * projectileAbility.projectileSpeed * Time.deltaTime;
}
protected override void OnTickPerformed()
{
if (targets.Count > 0)
onTickHappened.Invoke(ownerTag, targets);
}
private void OnTriggerEnter(Collider other)
{
if (waitingForDestroy) return;
target = other.GetComponentInParent<Taggable>();
if (target == null) return;
if (target == ownerTag && !canHitSelf) return;
if (projectileAbility == null) return;
if (!target.IsValidTarget(projectileAbility.targettingTags)) return;
//Debug.Log($"TT[{Time.frameCount}] Past validation checks for {target.name}");
if (processedTargets.Contains(target)) return;
processedTargets.Add(target);
hitPositionCorrected = target.transform.position;
hitPositionCorrected.y = this.transform.position.y;
onTargetHit.Invoke(hitPositionCorrected);
possibleBlock = target.GetComponentInParent<NetworkedAntiProjectile>();
if (possibleBlock != null)
{
waitingForDestroy = true;
possibleBlock.SendBlockNotice();
StartCoroutine(DelayedDestroy());
return;
}
//Debug.Log($"TT[{Time.frameCount}] About to process effects");
projectileTargets.Clear();
projectileTargets.Add(target);
foreach (BaseEffect effect in projectileAbility.abilityEffects)
{
//Debug.Log($"TT[{Time.frameCount}] Applying effect: {effect.name}");
effect.ApplyEffect(ownerTag, projectileTargets);
}
if(projectileTargets.Count > 0)
{
//Debug.Log($"TT[{Time.frameCount}] OnProjectileHit {projectileTargets.Count}");
onTargetHitByProjectile.Invoke(ownerTag, projectileTargets);
}
if (!projectileAbility.canPierce)
{
waitingForDestroy = true;
StartCoroutine(DelayedDestroy());
}
}
}