- Channeled abilities now allow to aim during channel - Added spell casting channeled animation loop option - New Mage DragonBreath channeled ability
165 lines
4.3 KiB
C#
165 lines
4.3 KiB
C#
using Photon.Pun;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class NetworkedChanneling : MonoBehaviour
|
|
{
|
|
[Header("Visuals")]
|
|
[SerializeField] protected GameObject visuals;
|
|
[Header("Physics:")]
|
|
[SerializeField] protected LayerMask abilityHitLayer;
|
|
|
|
[Header("Set by Code")]
|
|
public PhotonView photonView;
|
|
public PhotonView owner;
|
|
public Taggable ownerTag;
|
|
public ChanneledAbility ability;
|
|
public float duration;
|
|
public bool canHitSelf;
|
|
public bool followUser;
|
|
public bool allowAiming;
|
|
public float radius;
|
|
|
|
public bool channeling = false;
|
|
|
|
private float endTime;
|
|
|
|
protected PhotonView possibleTarget;
|
|
protected Taggable target;
|
|
protected List<Taggable> targets = new List<Taggable>();
|
|
|
|
protected Collider[] hits;
|
|
|
|
public BoxCollider OptionalBoxOverlap;
|
|
|
|
ProjectileSpawnLocationController aimController;
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
photonView = GetComponent<PhotonView>();
|
|
}
|
|
|
|
public virtual void Init(ref Coroutine channelingCoroutine)
|
|
{
|
|
if (photonView.IsMine)
|
|
{
|
|
photonView.RPC(nameof(RPC_RemoteInit), RpcTarget.Others, AbilityIndexer.Instance.Abilities.IndexOf(ability));
|
|
|
|
channeling = true;
|
|
|
|
aimController = owner.GetComponentInChildren<ProjectileSpawnLocationController>();
|
|
|
|
channelingCoroutine = StartCoroutine(ExecuteChanneling());
|
|
|
|
if (followUser)
|
|
StartCoroutine(FollowUser());
|
|
|
|
StartCoroutine(SelfDestruct());
|
|
}
|
|
}
|
|
|
|
IEnumerator FollowUser()
|
|
{
|
|
while (Time.time < endTime)
|
|
{
|
|
this.transform.position = owner.transform.position;
|
|
if (allowAiming)
|
|
{
|
|
this.transform.forward = aimController.GetLookat();
|
|
}
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
visuals.SetActive(false);
|
|
}
|
|
|
|
[PunRPC]
|
|
protected virtual void RPC_RemoteInit(int abilityIndex)
|
|
{
|
|
ability = (ChanneledAbility)AbilityIndexer.Instance.Abilities[abilityIndex];
|
|
}
|
|
|
|
[PunRPC]
|
|
private void RPC_DisableVisuals()
|
|
{
|
|
visuals.SetActive(false);
|
|
}
|
|
|
|
IEnumerator ExecuteChanneling()
|
|
{
|
|
visuals.SetActive(true);
|
|
|
|
endTime = Time.time + duration;
|
|
while (Time.time < endTime)
|
|
{
|
|
yield return new WaitForSeconds(0.5f);
|
|
CheckSurroundings();
|
|
}
|
|
}
|
|
|
|
public void DisableVisuals()
|
|
{
|
|
if (photonView.IsMine)
|
|
photonView.RPC(nameof(RPC_DisableVisuals), RpcTarget.All);
|
|
}
|
|
|
|
protected virtual void CheckSurroundings()
|
|
{
|
|
if (!channeling) return;
|
|
|
|
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;
|
|
|
|
//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);
|
|
}
|
|
|
|
foreach (BaseEffect effect in ability.abilityEffects)
|
|
{
|
|
effect.ApplyEffect(ownerTag, targets);
|
|
}
|
|
}
|
|
|
|
protected IEnumerator SelfDestruct()
|
|
{
|
|
yield return new WaitForSeconds(duration + 1f);
|
|
|
|
PhotonNetwork.Destroy(photonView);
|
|
}
|
|
|
|
protected void OnDrawGizmos()
|
|
{
|
|
Gizmos.color = Color.red;
|
|
Gizmos.DrawWireSphere(this.transform.position, radius);
|
|
}
|
|
}
|