- new Projectile + Area of effect over time with tick event implemented - New Tornado projectile+AoEOverTime ability for Barb/Naturalist
179 lines
5.1 KiB
C#
179 lines
5.1 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class NetworkedAreaOfEffectOverTime : NetworkedAreaOfEffect
|
|
{
|
|
public float duration;
|
|
public bool followUser;
|
|
public bool followTarget;
|
|
public bool damageFollowingTarget;
|
|
|
|
protected float endTime;
|
|
protected float startTime;
|
|
|
|
protected Taggable followingTargetTaggable;
|
|
|
|
public BoxCollider OptionalBoxOverlap;
|
|
|
|
public override void Init()
|
|
{
|
|
if (photonView.IsMine)
|
|
{
|
|
//resizedByAbility.x = radius * 2;
|
|
//resizedByAbility.y = radius * 2;
|
|
//resizedByAbility.z = radius * 2;
|
|
//
|
|
////telegraph.transform.localScale = resizedByAbility;
|
|
//effectVisual.transform.localScale = resizedByAbility;
|
|
|
|
photonView.RPC(nameof(RPC_RemoteInit), RpcTarget.Others, AbilityIndexer.Instance.Abilities.IndexOf(ability));
|
|
|
|
ApplyArea();
|
|
|
|
if (followUser)
|
|
StartCoroutine(FollowTransform(owner.transform));
|
|
}
|
|
}
|
|
|
|
public void Init(Transform target)
|
|
{
|
|
if (photonView.IsMine)
|
|
{
|
|
photonView.RPC(nameof(RPC_RemoteInit), RpcTarget.Others, AbilityIndexer.Instance.Abilities.IndexOf(ability));
|
|
|
|
ApplyArea();
|
|
|
|
if (followTarget)
|
|
{
|
|
followingTargetTaggable = target.GetComponentInParent<Taggable>();
|
|
StartCoroutine(FollowTransform(target));
|
|
}
|
|
}
|
|
}
|
|
|
|
protected IEnumerator FollowTransform(Transform target)
|
|
{
|
|
endTime = Time.time + duration;
|
|
while (Time.time < endTime)
|
|
{
|
|
if (this.transform == null || target == null) break;
|
|
this.transform.position = target.position;
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
effectVisual.SetActive(false);
|
|
}
|
|
|
|
[PunRPC]
|
|
protected override void RPC_RemoteInit(int abilityIndex)
|
|
{
|
|
ability = (AreaOfEffectOverTimeAbility)AbilityIndexer.Instance.Abilities[abilityIndex]; // TODO: change casting to areaofeffectovertimeability
|
|
}
|
|
|
|
protected override IEnumerator ApplyTelegraphDelay(float delay)
|
|
{
|
|
return base.ApplyTelegraphDelay(delay);
|
|
}
|
|
|
|
protected override void ApplyArea()
|
|
{
|
|
effectVisual.SetActive(true);
|
|
|
|
StartCoroutine(ApplyAreaOverTime());
|
|
}
|
|
|
|
protected IEnumerator ApplyAreaOverTime()
|
|
{
|
|
startTime = Time.time;
|
|
endTime = Time.time + duration;
|
|
while (Time.time < endTime)
|
|
{
|
|
yield return new WaitForSeconds(0.5f);
|
|
CheckSurroundings();
|
|
}
|
|
|
|
effectVisual.SetActive(false);
|
|
StartCoroutine(SelfDestruct());
|
|
}
|
|
|
|
protected override void OnDrawGizmos()
|
|
{
|
|
base.OnDrawGizmos();
|
|
|
|
if (OptionalBoxOverlap != null)
|
|
Gizmos.DrawWireCube(OptionalBoxOverlap.transform.position, OptionalBoxOverlap.size / 2);
|
|
}
|
|
|
|
protected override void CheckSurroundings()
|
|
{
|
|
if (waitingForDestroy) return;
|
|
//TODO: spread the total value over ticks, for now just apply the instant effect every tick, manage tick values on effect applied
|
|
if (OptionalBoxOverlap != null)
|
|
{
|
|
hits = Physics.OverlapBox(OptionalBoxOverlap.transform.position, OptionalBoxOverlap.size / 2f, OptionalBoxOverlap.transform.rotation, abilityHitLayer);
|
|
}
|
|
else
|
|
{
|
|
hits = Physics.OverlapSphere(this.transform.position, radius, abilityHitLayer);
|
|
}
|
|
targets.Clear();
|
|
foreach (Collider collider in hits)
|
|
{
|
|
// Debug.Log("hit collider " + collider.name);
|
|
|
|
possibleTarget = collider.GetComponentInParent<PhotonView>();
|
|
if (possibleTarget != null)
|
|
if (possibleTarget == owner && !canHitSelf) continue;
|
|
|
|
target = collider.GetComponentInParent<Taggable>();
|
|
|
|
//Debug.Log("hit collider, Got taggable: " + target.name);
|
|
|
|
if (target == null) continue;
|
|
|
|
if (followTarget && (!damageFollowingTarget && target == followingTargetTaggable)) continue;
|
|
|
|
//Debug.Log("hit collider, targetTag: " + target.targetTag.name);
|
|
|
|
/*foreach (TargetTag tag in ability.targettingTags)
|
|
{
|
|
Debug.Log("hit collider, ability.Tags: " + tag);
|
|
}*/
|
|
if (!target.IsValidTarget(ability.targettingTags)) continue;
|
|
|
|
//Debug.Log("hit collider, added target: " + target.name);
|
|
targets.Add(target);
|
|
|
|
}
|
|
|
|
photonView.RPC(nameof(RPC_CheckSurroundings), RpcTarget.Others);
|
|
|
|
for (int i = 0; i < targets.Count; i++)
|
|
{
|
|
OnTargetHit(i);
|
|
}
|
|
|
|
foreach (BaseEffect effect in ability.abilityEffects)
|
|
{
|
|
effect.ApplyEffect(ownerTag, targets);
|
|
}
|
|
|
|
OnTickPerformed();
|
|
}
|
|
|
|
protected virtual void OnTargetHit(int i)
|
|
{
|
|
hitPositionCorrected = targets[i].transform.position;
|
|
hitPositionCorrected.y = 0.5f;
|
|
|
|
onTargetHit.Invoke(hitPositionCorrected);
|
|
}
|
|
|
|
protected virtual void OnTickPerformed()
|
|
{
|
|
|
|
}
|
|
}
|