You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Gameplay/ChaosRuneBase.cs

76 lines
2.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
// serveronly 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<ServerCharacter>();
if (picker == null) return;
// cancel expiry
StopCoroutine(_expireRoutine);
// serveronly hook
OnChaosRunePickedUp(picker);
// remove from all clients
NetworkObject.Despawn();
}
/// <summary>
/// Override in your concrete prefabscript (or subclass) to grant effects.
/// </summary>
protected virtual void OnChaosRunePickedUp(ServerCharacter picker)
{
Debug.Log($"[Server] {picker.name} picked up {name}");
// e.g. picker.ApplyEffect(chaosRuneMagnitude, chaosRuneDuration);
}
/// <summary>
/// Override to do cleanup if nobody picked it up.
/// </summary>
protected virtual void OnChaosRuneExpired()
{
Debug.Log($"[Server] {name} expired before pickup");
}
}