- voting now fully cancels and clears when atleast one player cancels or closes the voting UI - when selecting a job and voting, the zone is stored on all players, allowing to load different zones / jobs
108 lines
2.8 KiB
C#
108 lines
2.8 KiB
C#
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<Taggable> targets = new List<Taggable>();
|
|
|
|
protected PhotonView possibleTargetView;
|
|
protected Taggable possibleTarget;
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
photonView = GetComponent<PhotonView>();
|
|
}
|
|
|
|
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<PhotonView>();
|
|
if (possibleTargetView == null) return false;
|
|
|
|
if (!canHitSelf && possibleTargetView == owner) return false;
|
|
|
|
possibleTarget = possibleTargetView.GetComponent<Taggable>();
|
|
if (possibleTarget == null) return false;
|
|
|
|
if (!possibleTarget.IsValidTarget(ability.targettingTags)) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
protected virtual void ApplyEffects(List<Taggable> targets)
|
|
{
|
|
if (!photonView.IsMine) return;
|
|
|
|
foreach (BaseEffect effect in ability.abilityEffects)
|
|
{
|
|
effect.ApplyEffect(ownerTag, targets);
|
|
}
|
|
}
|
|
}
|