using Photon.Pun; using System.Collections; using System.Collections.Generic; using UnityEngine; public class NetworkedBaseAbility : MonoBehaviour { [Header("Common Settings")] public PhotonView photonView; public PhotonView owner; public Taggable ownerTag; public BaseAbility ability; public float lifeSpan; public bool canHitSelf; [SerializeField] protected GameObject visuals; [SerializeField] protected LayerMask abilityHitLayer; protected bool waitingForDestroy = false; protected List targets = new List(); protected PhotonView possibleTargetView; protected Taggable possibleTarget; protected virtual void Awake() { photonView = GetComponent(); } public virtual void Init() { if (photonView.IsMine) { photonView.RPC(nameof(RPC_RemoteInit), RpcTarget.Others, AbilityIndexer.Instance.Abilities.IndexOf(ability)); StartCoroutine(SelfDestruct()); } } [PunRPC] protected virtual void RPC_RemoteInit(int abilityIndex) { ability = AbilityIndexer.Instance.Abilities[abilityIndex]; } protected virtual IEnumerator SelfDestruct() { yield return new WaitForSeconds(lifeSpan); waitingForDestroy = true; StartCoroutine(DelayedDestroy()); } protected virtual IEnumerator DelayedDestroy() { DisableVisuals(); yield return new WaitForSeconds(1.5f); PhotonNetwork.Destroy(photonView); } protected virtual void DisableVisuals() { if (visuals != null) { visuals.SetActive(false); photonView.RPC(nameof(RPC_DisableVisuals), RpcTarget.Others); } } [PunRPC] protected virtual void RPC_DisableVisuals() { if (visuals != null) { visuals.SetActive(false); } } protected virtual bool IsValidTarget(Taggable target) { if (target == null) return false; if (!canHitSelf && target == ownerTag) return false; return target.IsValidTarget(ability.targettingTags); } protected virtual bool IsValidTarget(Collider collider) { possibleTargetView = collider.GetComponentInParent(); if (possibleTargetView == null) return false; if (!canHitSelf && possibleTargetView == owner) return false; possibleTarget = possibleTargetView.GetComponent(); if (possibleTarget == null) return false; if (!possibleTarget.IsValidTarget(ability.targettingTags)) return false; return true; } protected virtual void ApplyEffects(List targets) { if (!photonView.IsMine) return; foreach (BaseEffect effect in ability.abilityEffects) { effect.ApplyEffect(ownerTag, targets); } } }