|
|
@ -64,7 +64,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
DOTween.Play(PlatformID);
|
|
|
|
DOTween.Play(PlatformID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
public void PausePlatformAnimation()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (IsServer)
|
|
|
|
if (IsServer)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -96,26 +96,68 @@ namespace Unity.Multiplayer.Samples.BossRoom
|
|
|
|
|
|
|
|
|
|
|
|
public void Occupy(ServerCharacter player)
|
|
|
|
public void Occupy(ServerCharacter player)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!IsServer || IsOccupied)
|
|
|
|
if (!IsServer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
Debug.LogWarning($"[Occupy] Attempted to occupy platform {PlatformID.Value} on a non-server instance.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Pause();
|
|
|
|
if (IsOccupied)
|
|
|
|
bool giveScore = player.PreviousPlatformId != PlatformID.Value;
|
|
|
|
{
|
|
|
|
int score = (player.TargetPlatformId == PlatformID.Value) ? 10 : 20;
|
|
|
|
Debug.LogWarning($"[Occupy] Platform {PlatformID.Value} is already occupied. Player {player.OwnerClientId} cannot occupy.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
IsOccupied = true;
|
|
|
|
|
|
|
|
occupierId.Value = player.OwnerClientId;
|
|
|
|
|
|
|
|
player.OnArrivalOnPlatform(PlatformID.Value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] Player {player.OwnerClientId} is occupying platform {PlatformID.Value}.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PausePlatformAnimation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool giveScore = player.PreviousPlatformId.HasValue && player.PreviousPlatformId.Value != PlatformID.Value;
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] GiveScore check: PreviousPlatformId = {player.PreviousPlatformId}, CurrentPlatformId = {PlatformID.Value}, Result = {giveScore}");
|
|
|
|
|
|
|
|
|
|
|
|
if (giveScore)
|
|
|
|
if (giveScore)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
bool isOnTargetedPlatform = player.TargetPlatformId.HasValue && player.TargetPlatformId.Value == this.PlatformID.Value;
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] Is on targeted platform: {isOnTargetedPlatform}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Platform platformB = isOnTargetedPlatform
|
|
|
|
|
|
|
|
? PlatformManager.Instance.GetPlatformById(player.TargetPlatformId.Value)
|
|
|
|
|
|
|
|
: PlatformManager.Instance.GetPlatformById(this.PlatformID.Value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!player.PreviousPlatformId.HasValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Debug.LogError($"[Occupy] Error: player.PreviousPlatformId is null! Cannot calculate distance.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Platform platformA = PlatformManager.Instance.GetPlatformById(player.PreviousPlatformId.Value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (platformA == null || platformB == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Debug.LogError($"[Occupy] Platform lookup failed: platformA ({player.PreviousPlatformId.Value}) or platformB ({(isOnTargetedPlatform ? player.TargetPlatformId.Value : this.PlatformID.Value)}) is null!");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int multiplier = (int)Vector3.Distance(platformA.transform.position, platformB.transform.position);
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] Distance multiplier: {multiplier} (from {platformA.PlatformID.Value} to {platformB.PlatformID.Value})");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int score = (player.TargetPlatformId.HasValue && player.TargetPlatformId.Value == PlatformID.Value) ? 10 : 20;
|
|
|
|
|
|
|
|
score *= multiplier;
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] Calculated score for player {player.OwnerClientId}: {score}");
|
|
|
|
|
|
|
|
|
|
|
|
ScoreManager.Instance.AddPlayerScore(player.OwnerClientId, score);
|
|
|
|
ScoreManager.Instance.AddPlayerScore(player.OwnerClientId, score);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] Player {player.OwnerClientId} successfully occupied platform {PlatformID.Value}. Starting penalty coroutine.");
|
|
|
|
|
|
|
|
|
|
|
|
IsOccupied = true;
|
|
|
|
|
|
|
|
occupierId.Value = player.OwnerClientId;
|
|
|
|
|
|
|
|
player.OnArrivalOnPlatform(PlatformID.Value);
|
|
|
|
|
|
|
|
penaltyCoroutine = StartCoroutine(HandleOccupationPenalty(player));
|
|
|
|
penaltyCoroutine = StartCoroutine(HandleOccupationPenalty(player));
|
|
|
|
EnableBarrier();
|
|
|
|
EnableBarrier();
|
|
|
|
|
|
|
|
Debug.Log($"[Occupy] Barrier enabled for platform {PlatformID.Value}.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator HandleOccupationPenalty(ServerCharacter player)
|
|
|
|
private IEnumerator HandleOccupationPenalty(ServerCharacter player)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
occupationTime = 0f;
|
|
|
|
occupationTime = 0f;
|
|
|
|