using System.Collections; using Unity.BossRoom.Gameplay.GameplayObjects.Character; using Unity.Netcode; using UnityEngine; [RequireComponent(typeof(NetworkObject), typeof(Collider))] public abstract class ChaosRuneBase : NetworkBehaviour { [Header("Rune Data")] [Tooltip("Radius of the trigger collider; set your collider to match.")] public float chaosRuneRadius = 1f; public float chaosRuneMagnitude = 1f; public float chaosRuneDuration = 5f; public float chaosRuneCooldownTime = 10f; public float chaosRuneApplicationRadius = 2f; [Space, Tooltip("Seconds before this rune auto-expires if not picked up")] public float lifetime = 5f; private Coroutine _expireRoutine; public override void OnNetworkSpawn() { if (!IsServer) return; // start the expiry countdown _expireRoutine = StartCoroutine(ExpireAfter(lifetime)); } private IEnumerator ExpireAfter(float secs) { yield return new WaitForSeconds(secs); // server‐only hook OnChaosRuneExpired(); // remove from all clients NetworkObject.Despawn(); } private void OnTriggerEnter(Collider other) { if (!IsServer) return; // only players can pick up var picker = other.GetComponent(); if (picker == null) return; // cancel expiry StopCoroutine(_expireRoutine); // server‐only hook OnChaosRunePickedUp(picker); // remove from all clients NetworkObject.Despawn(); } /// /// Override in your concrete prefab‐script (or subclass) to grant effects. /// protected virtual void OnChaosRunePickedUp(ServerCharacter picker) { Debug.Log($"[Server] {picker.name} picked up {name}"); // e.g. picker.ApplyEffect(chaosRuneMagnitude, chaosRuneDuration); } /// /// Override to do cleanup if nobody picked it up. /// protected virtual void OnChaosRuneExpired() { Debug.Log($"[Server] {name} expired before pickup"); } }