|
|
|
@ -142,8 +142,37 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
|
|
|
|
|
NetworkAvatarGuidState m_State;
|
|
|
|
|
|
|
|
|
|
public ulong? PendingSwapRequest { get; set; }
|
|
|
|
|
public int? TargetPlatformId { get; private set; } = null;
|
|
|
|
|
|
|
|
|
|
public void SetTargetPlatform(int platformId)
|
|
|
|
|
{
|
|
|
|
|
TargetPlatformId = platformId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearTargetPlatform()
|
|
|
|
|
{
|
|
|
|
|
TargetPlatformId = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if (TargetPlatformId.HasValue && other.TryGetComponent<Platform>(out var platform))
|
|
|
|
|
{
|
|
|
|
|
if (platform.PlatformID == TargetPlatformId.Value)
|
|
|
|
|
{
|
|
|
|
|
if (!platform.IsOccupied)
|
|
|
|
|
{
|
|
|
|
|
// platform.Occupy(this);
|
|
|
|
|
Debug.Log($"{name} successfully occupied Platform {platform.PlatformID}.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"{name} couldn't occupy Platform {platform.PlatformID}. Becoming a crow!");
|
|
|
|
|
}
|
|
|
|
|
ClearTargetPlatform();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
@ -194,14 +223,10 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
|
|
|
|
|
if (NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(initiatingPlayerId, out var initiatingPlayerObj) &&
|
|
|
|
|
initiatingPlayerObj.TryGetComponent(out ServerCharacter initiatingPlayer))
|
|
|
|
|
{
|
|
|
|
|
Vector3 initiatingPlayerPosition = initiatingPlayer.physicsWrapper.Transform.position;
|
|
|
|
|
Vector3 targetPlayerPosition = this.physicsWrapper.Transform.position;
|
|
|
|
|
// Call InitiateSwap directly
|
|
|
|
|
InitiateSwap(initiatingPlayer, this);
|
|
|
|
|
|
|
|
|
|
// Execute the swap
|
|
|
|
|
initiatingPlayer.ServerSendCharacterInputRpc(targetPlayerPosition);
|
|
|
|
|
this.ServerSendCharacterInputRpc(initiatingPlayerPosition);
|
|
|
|
|
|
|
|
|
|
Debug.Log($"Swap confirmed: {initiatingPlayer.name} swapped with {this.name}.");
|
|
|
|
|
Debug.Log($"Swap confirmed: {initiatingPlayer.name} and {this.name} are swapping.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -209,10 +234,27 @@ namespace Unity.BossRoom.Gameplay.GameplayObjects.Character
|
|
|
|
|
Debug.Log($"Swap request denied by {this.name}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear pending request
|
|
|
|
|
PendingSwapRequest = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitiateSwap(ServerCharacter initiatingPlayer, ServerCharacter targetPlayer)
|
|
|
|
|
{
|
|
|
|
|
int initiatingPlatformId = PlatformManager.Instance.GetPlatformOccupiedByPlayer(initiatingPlayer).PlatformID;
|
|
|
|
|
int targetPlatformId = PlatformManager.Instance.GetPlatformOccupiedByPlayer(targetPlayer).PlatformID;
|
|
|
|
|
|
|
|
|
|
initiatingPlayer.SetTargetPlatform(targetPlatformId);
|
|
|
|
|
targetPlayer.SetTargetPlatform(initiatingPlatformId);
|
|
|
|
|
|
|
|
|
|
Vector3 initiatingPlayerPosition = initiatingPlayer.physicsWrapper.Transform.position;
|
|
|
|
|
Vector3 targetPlayerPosition = this.physicsWrapper.Transform.position;
|
|
|
|
|
|
|
|
|
|
// Execute the swap
|
|
|
|
|
initiatingPlayer.ServerSendCharacterInputRpc(targetPlayerPosition);
|
|
|
|
|
this.ServerSendCharacterInputRpc(initiatingPlayerPosition);
|
|
|
|
|
|
|
|
|
|
Debug.Log($"Swap initiated: {initiatingPlayer.name} -> Platform {targetPlatformId}, {targetPlayer.name} -> Platform {initiatingPlatformId}.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnNetworkSpawn()
|
|
|
|
|
{
|
|
|
|
|