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

108 lines
4.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "AoEAbility", menuName = "RiftMayhem/AbilitySystem/Abilities/Area of Effect Ability", order = 0)]
public class AreaOfEffectAbility : BaseAbility
{
public GameObject aoePrefab;
public LayerMask movementMask;
public float lifeSpan;
public float radius;
public bool shouldResizeVisuals;
public float telegraphDelay;
public bool canHitSelf;
public bool spawnUnderUser;
protected GameObject instantiatedArea;
private NetworkedAreaOfEffect networkedAreaOfEffect;
public bool rotateOnSpawn = false;
protected Quaternion rot;
protected Camera cam;
protected Ray ray;
protected RaycastHit hit;
protected void Awake()
{
cam = Camera.main;
}
public override void Execute(Taggable user)
{
SpendResourcesNecessary(user);
if (spawnUnderUser)
{
rot = Quaternion.LookRotation(user.GetComponentInChildren<AoERayHitLocationSnapshotController>().aoeRayHitLocationSnapshot.position - user.transform.position);
instantiatedArea = Instantiate(aoePrefab, user.transform.position, rotateOnSpawn ? rot : Quaternion.identity);
networkedAreaOfEffect = instantiatedArea.GetComponent<NetworkedAreaOfEffect>();
networkedAreaOfEffect.ownerTag = user;
networkedAreaOfEffect.ability = this;
networkedAreaOfEffect.radius = radius;
networkedAreaOfEffect.shouldResizeVisuals = shouldResizeVisuals;
networkedAreaOfEffect.telegraphDelay = telegraphDelay;
networkedAreaOfEffect.lifeSpan = lifeSpan;
networkedAreaOfEffect.canHitSelf = canHitSelf;
networkedAreaOfEffect.Init();
return;
}
rot = Quaternion.LookRotation(user.GetComponentInChildren<AoERayHitLocationSnapshotController>().aoeRayHitLocationSnapshot.position - user.transform.position);
instantiatedArea = Instantiate(aoePrefab, user.GetComponentInChildren<AoERayHitLocationSnapshotController>().aoeRayHitLocationSnapshot.position, rotateOnSpawn ? rot : Quaternion.identity);
networkedAreaOfEffect = instantiatedArea.GetComponent<NetworkedAreaOfEffect>();
networkedAreaOfEffect.ownerTag = user;
networkedAreaOfEffect.ability = this;
networkedAreaOfEffect.radius = radius;
networkedAreaOfEffect.telegraphDelay = telegraphDelay;
networkedAreaOfEffect.lifeSpan = lifeSpan;
networkedAreaOfEffect.canHitSelf = canHitSelf;
networkedAreaOfEffect.Init();
}
public override void Execute(Taggable user, Vector3 point)
{
SpendResourcesNecessary(user);
rot = Quaternion.LookRotation(user.GetComponentInChildren<AoERayHitLocationSnapshotController>().aoeRayHitLocationSnapshot.position - user.transform.position);
instantiatedArea = Instantiate(aoePrefab, point, rotateOnSpawn ? rot : Quaternion.identity);
networkedAreaOfEffect = instantiatedArea.GetComponent<NetworkedAreaOfEffect>();
networkedAreaOfEffect.ownerTag = user;
networkedAreaOfEffect.ability = this;
networkedAreaOfEffect.radius = radius;
networkedAreaOfEffect.telegraphDelay = telegraphDelay;
networkedAreaOfEffect.lifeSpan = lifeSpan;
networkedAreaOfEffect.canHitSelf = canHitSelf;
networkedAreaOfEffect.Init();
}
public override void Execute(Taggable user, Transform target)
{
SpendResourcesNecessary(user);
instantiatedArea = Instantiate(aoePrefab, target.position, Quaternion.identity);
networkedAreaOfEffect = instantiatedArea.GetComponent<NetworkedAreaOfEffect>();
networkedAreaOfEffect.ownerTag = user;
networkedAreaOfEffect.ability = this;
networkedAreaOfEffect.radius = radius;
networkedAreaOfEffect.telegraphDelay = telegraphDelay;
networkedAreaOfEffect.lifeSpan = lifeSpan;
networkedAreaOfEffect.canHitSelf = canHitSelf;
networkedAreaOfEffect.Init();
}
}