RiftMayhem/Assets/Scripts/AbilitySystem/AreaOfEffectAbility.cs

134 lines
4.9 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 AoERayHitLocationSnapshotController snapshotController;
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)
{
snapshotController = user.GetComponentInChildren<AoERayHitLocationSnapshotController>();
if(snapshotController == null)
{
rot = Quaternion.LookRotation(user.transform.forward);
}
else
{
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;
}
snapshotController = user.GetComponentInChildren<AoERayHitLocationSnapshotController>();
if (snapshotController == null)
{
rot = Quaternion.LookRotation(user.transform.forward);
}
else
{
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);
snapshotController = user.GetComponentInChildren<AoERayHitLocationSnapshotController>();
if (snapshotController == null)
{
rot = Quaternion.LookRotation(user.transform.forward);
}
else
{
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();
}
}