Fixed the distance based issue

dev-hazim
Hazim Bin Ijaz 18 hours ago
parent 08917b2652
commit 17e16a68de

@ -280,6 +280,17 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
if (IsServer)
{
IsOnAPlatform = status; // Update on the server
if (status)
{
Debug.Log($"[ServerChar] Setting CurrentPlatformId = {platformId}");
CurrentPlatformId = platformId;
}
else
{
Debug.Log($"[ServerChar] Setting PreviousPlatformId = {platformId}");
PreviousPlatformId = platformId;
CurrentPlatformId = null;
}
UpdatePlatformStatusClientRpc(status, platformId); // Notify all clients
}
else
@ -295,10 +306,12 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
IsSwapping = false;
if (status)
{
Debug.Log($"[ServerChar] Setting CurrentPlatformId = {platformId}");
CurrentPlatformId = platformId;
}
else
{
Debug.Log($"[ServerChar] Setting PreviousPlatformId = {platformId}");
PreviousPlatformId = platformId;
CurrentPlatformId = null;
}

@ -64,7 +64,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
DOTween.Play(PlatformID);
}
public void Pause()
public void PausePlatformAnimation()
{
if (IsServer)
{
@ -96,26 +96,68 @@ namespace Unity.Multiplayer.Samples.BossRoom
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;
}
Pause();
bool giveScore = player.PreviousPlatformId != PlatformID.Value;
int score = (player.TargetPlatformId == PlatformID.Value) ? 10 : 20;
if (IsOccupied)
{
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)
{
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);
}
IsOccupied = true;
occupierId.Value = player.OwnerClientId;
player.OnArrivalOnPlatform(PlatformID.Value);
Debug.Log($"[Occupy] Player {player.OwnerClientId} successfully occupied platform {PlatformID.Value}. Starting penalty coroutine.");
penaltyCoroutine = StartCoroutine(HandleOccupationPenalty(player));
EnableBarrier();
Debug.Log($"[Occupy] Barrier enabled for platform {PlatformID.Value}.");
}
private IEnumerator HandleOccupationPenalty(ServerCharacter player)
{
occupationTime = 0f;

Loading…
Cancel
Save