|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
|
|
|
using Unity.Netcode;
|
|
|
|
|
using UnityEngine;
|
|
|
|
@ -14,7 +15,9 @@ namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
|
private NetworkVariable<ulong> occupierId = new NetworkVariable<ulong>(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
|
|
|
|
|
private Collider platformCollider;
|
|
|
|
|
private Animator animator;
|
|
|
|
|
|
|
|
|
|
private float occupationTime = 0f;
|
|
|
|
|
private float penaltyInterval = 3f; // Interval for penalty deduction
|
|
|
|
|
private Coroutine penaltyCoroutine;
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
platformCollider = GetComponent<Collider>();
|
|
|
|
@ -108,8 +111,29 @@ namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
|
IsOccupied = true;
|
|
|
|
|
occupierId.Value = player.OwnerClientId;
|
|
|
|
|
player.OnArrivalOnPlatform(PlatformID.Value);
|
|
|
|
|
penaltyCoroutine = StartCoroutine(HandleOccupationPenalty(player));
|
|
|
|
|
}
|
|
|
|
|
private IEnumerator HandleOccupationPenalty(ServerCharacter player)
|
|
|
|
|
{
|
|
|
|
|
occupationTime = 0f;
|
|
|
|
|
|
|
|
|
|
while (IsOccupied)
|
|
|
|
|
{
|
|
|
|
|
occupationTime += Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
if (occupationTime >= 10f)
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(penaltyInterval);
|
|
|
|
|
|
|
|
|
|
// Deduct points
|
|
|
|
|
ScoreManager.Instance.SubtractPlayerScore(player.OwnerClientId, 10);
|
|
|
|
|
Debug.Log($"Player {player.OwnerClientId} lost 10 points for occupying the platform too long.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Vacate(ServerCharacter player)
|
|
|
|
|
{
|
|
|
|
|
if (!IsServer || !IsOccupied || occupierId.Value != player.OwnerClientId)
|
|
|
|
@ -121,6 +145,11 @@ namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
|
IsOccupied = false;
|
|
|
|
|
occupierId.Value = 0;
|
|
|
|
|
player.OnLeavingPlatform(PlatformID.Value);
|
|
|
|
|
if (penaltyCoroutine != null)
|
|
|
|
|
{
|
|
|
|
|
StopCoroutine(penaltyCoroutine);
|
|
|
|
|
penaltyCoroutine = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
@ -145,114 +174,3 @@ namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
|
|
|
//using Unity.Netcode;
|
|
|
|
|
//using UnityEngine;
|
|
|
|
|
//using DG.Tweening;
|
|
|
|
|
//using Unity.Netcode.Components;
|
|
|
|
|
|
|
|
|
|
//namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
|
//{
|
|
|
|
|
// [RequireComponent(typeof(Collider))]
|
|
|
|
|
// public class Platform : NetworkBehaviour
|
|
|
|
|
// {
|
|
|
|
|
// public NetworkVariable<int> PlatformID = new NetworkVariable<int>(0);
|
|
|
|
|
// public bool IsOccupied { get; private set; }
|
|
|
|
|
|
|
|
|
|
// private NetworkVariable<ulong> occupierId = new NetworkVariable<ulong>(0, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
|
|
|
|
|
// private Collider platformCollider;
|
|
|
|
|
// private Animator animator;
|
|
|
|
|
// private void Awake()
|
|
|
|
|
// {
|
|
|
|
|
// platformCollider = GetComponent<Collider>();
|
|
|
|
|
// if (!platformCollider.isTrigger)
|
|
|
|
|
// platformCollider.isTrigger = true;
|
|
|
|
|
|
|
|
|
|
// animator = GetComponent<Animator>();
|
|
|
|
|
// }
|
|
|
|
|
// private void Start()
|
|
|
|
|
// {
|
|
|
|
|
// Invoke(nameof(ColliderEnabler),2);
|
|
|
|
|
// }
|
|
|
|
|
// public void AssignID(int id)
|
|
|
|
|
// {
|
|
|
|
|
// if (IsServer) PlatformID.Value = id;
|
|
|
|
|
// }
|
|
|
|
|
// void ColliderEnabler()
|
|
|
|
|
// {
|
|
|
|
|
// platformCollider.enabled = true;
|
|
|
|
|
// }
|
|
|
|
|
// public void StartRotation() => transform.DOLocalRotate(Vector3.up, 120).SetSpeedBased(true).SetId(PlatformID).SetLoops(-1, LoopType.Incremental);
|
|
|
|
|
|
|
|
|
|
// private void PauseRotation() => DOTween.Pause(PlatformID);
|
|
|
|
|
// private void ResumeRotation() => DOTween.Play(PlatformID);
|
|
|
|
|
|
|
|
|
|
// public void Pause()
|
|
|
|
|
// {
|
|
|
|
|
// if (IsOwner)
|
|
|
|
|
// {
|
|
|
|
|
// animator.speed = 0f;
|
|
|
|
|
// PauseServerRpc();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void Resume()
|
|
|
|
|
// {
|
|
|
|
|
// if (IsOwner)
|
|
|
|
|
// {
|
|
|
|
|
// animator.speed = 1f;
|
|
|
|
|
// ResumeServerRpc();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// [ServerRpc]
|
|
|
|
|
// private void PauseServerRpc() => PauseClientRpc();
|
|
|
|
|
// [ClientRpc]
|
|
|
|
|
// private void PauseClientRpc() => animator.speed = 0f;
|
|
|
|
|
|
|
|
|
|
// [ServerRpc]
|
|
|
|
|
// private void ResumeServerRpc() => ResumeClientRpc();
|
|
|
|
|
// [ClientRpc]
|
|
|
|
|
// private void ResumeClientRpc() => animator.speed = 1f;
|
|
|
|
|
|
|
|
|
|
// public void Occupy(ServerCharacter player)
|
|
|
|
|
// {
|
|
|
|
|
// if (!IsServer || IsOccupied) return;
|
|
|
|
|
// Pause();
|
|
|
|
|
// bool giveScore = player.PreviousPlatformId != PlatformID.Value;
|
|
|
|
|
// int score = (player.TargetPlatformId == PlatformID.Value) ? 10 : 20;
|
|
|
|
|
|
|
|
|
|
// if (giveScore) ScoreManager.Instance.AddPlayerScore(player.OwnerClientId, score);
|
|
|
|
|
|
|
|
|
|
// IsOccupied = true;
|
|
|
|
|
// occupierId.Value = player.OwnerClientId;
|
|
|
|
|
// player.OnArrivalOnPlatform(PlatformID.Value);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public void Vacate(ServerCharacter player)
|
|
|
|
|
// {
|
|
|
|
|
// if (!IsServer || !IsOccupied || occupierId.Value != player.OwnerClientId) return;
|
|
|
|
|
|
|
|
|
|
// Resume();
|
|
|
|
|
// IsOccupied = false;
|
|
|
|
|
// occupierId.Value = 0;
|
|
|
|
|
// player.OnLeavingPlatform(PlatformID.Value);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// private void OnTriggerEnter(Collider other)
|
|
|
|
|
// {
|
|
|
|
|
// if (IsServer && other.TryGetComponent<ServerCharacter>(out var player) && !IsOccupied)
|
|
|
|
|
// Occupy(player);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// private void OnTriggerExit(Collider other)
|
|
|
|
|
// {
|
|
|
|
|
// if (IsServer && other.TryGetComponent<ServerCharacter>(out var player))
|
|
|
|
|
// Vacate(player);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public ulong GetOccupierId() => occupierId.Value;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|