57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using System.Collections;
|
|
using Fusion;
|
|
using UnityEngine;
|
|
|
|
public class FlashbangTrap : TrapBase
|
|
{
|
|
protected override void OnTriggered(GameObject victim)
|
|
{
|
|
float radius = trapData.EffectRadius;
|
|
float duration = trapData.EffectDuration;
|
|
|
|
Debug.Log($"[Server] Flashbang Trap triggered at {transform.position}. Radius: {radius}m");
|
|
|
|
// Blind all Seekers in the explosion radius
|
|
Collider[] overlaps = Physics.OverlapSphere(transform.position, radius, LayerMask.GetMask("Player"));
|
|
foreach (var col in overlaps)
|
|
{
|
|
if (IsTargetValid(col.gameObject))
|
|
{
|
|
var netObj = col.gameObject.GetComponent<NetworkObject>();
|
|
if (netObj != null)
|
|
{
|
|
// Calculate visual falloff based on distance
|
|
float distance = Vector3.Distance(transform.position, col.transform.position);
|
|
float intensity = Mathf.Clamp01(1f - (distance / radius));
|
|
|
|
RPC_ApplyFlashbang(netObj.InputAuthority, netObj.Id, duration, intensity);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Wait for SFX/VFX to play, then despawn
|
|
StartCoroutine(DespawnAfterDelay(2f));
|
|
}
|
|
|
|
[Rpc(RpcSources.StateAuthority, RpcTargets.InputAuthority)]
|
|
private void RPC_ApplyFlashbang([RpcTarget] PlayerRef targetPlayer, NetworkId victimId, float duration, float intensity)
|
|
{
|
|
// Resolve the victim GameObject using NetworkId on the client
|
|
var victimNetObj = Runner.FindObject(victimId);
|
|
if (victimNetObj != null)
|
|
{
|
|
var overlay = victimNetObj.GetComponentInChildren<FlashbangScreenOverlay>();
|
|
if (overlay != null)
|
|
{
|
|
overlay.Flash(duration, intensity);
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator DespawnAfterDelay(float delay)
|
|
{
|
|
yield return new WaitForSeconds(delay);
|
|
DespawnTrap();
|
|
}
|
|
}
|