using UnityEngine; using Unity.Netcode; using Unity.BossRoom.Gameplay.GameplayObjects.Character; using System.Collections; using Unity.BossRoom.Gameplay.GameplayObjects; public class ExecutionerBox : NetworkBehaviour { private ServerCharacter _owner; private Vector3 _endPos; private float _travelTime; private float _startTime; private Vector3 _startPos; private float _warningTime; public override void OnNetworkSpawn() { var playerList = CrowManager.Instance.players; foreach (ServerCharacter serverCharacter in playerList) { if (serverCharacter.NetworkObject.IsOwner) // Check if this player is the local player { var abilitySystem = serverCharacter.GetComponent(); if (abilitySystem != null) { abilitySystem.InitiateGlobalCooldown(GameDataSource.Instance.TheExecutionerKey); } break; // Exit loop after finding the local player } } } public void Initialize(ServerCharacter owner, Vector3 startPos, Vector3 endPos, float travelTime, float warningTime) { _owner = owner; _startPos = startPos; _endPos = endPos; _travelTime = travelTime; _warningTime = warningTime; transform.position = startPos; transform.LookAt(endPos); StartCoroutine(StartExecutionerSequence()); } private IEnumerator StartExecutionerSequence() { // Show warning UI on all clients // UIManager.Instance.ShowExecutionerWarning(_warningTime); // Wait for the warning time before moving yield return new WaitForSeconds(_warningTime); _startTime = Time.time; StartCoroutine(MoveExecutioner()); } private IEnumerator MoveExecutioner() { float elapsedTime = 0f; while (elapsedTime < _travelTime) { elapsedTime = Time.time - _startTime; transform.position = Vector3.Lerp(_startPos, _endPos, elapsedTime / _travelTime); yield return null; } NetworkObject.Despawn(); } private void OnTriggerEnter(Collider other) { if (!IsServer) return; if (other.TryGetComponent(out var victim)) { ulong ownerId = _owner.OwnerClientId; ScoreManager.Instance.SubtractPlayerScore(victim.OwnerClientId, 10); ScoreManager.Instance.AddPlayerScore(ownerId, 10); Debug.Log($"[ExecutionerBox] Scores updated. " + $"Owner ({ownerId}) gained 10, " + $"Victim ({victim.OwnerClientId}) lost 10"); } } }