61 lines
1.0 KiB
C#
61 lines
1.0 KiB
C#
using Sandbox.Gravity;
|
|
|
|
namespace Sandbox.UI;
|
|
|
|
[Icon( "skip_next" )]
|
|
public sealed class TeleportMazeButton : InteractionButton
|
|
{
|
|
[Property] public Maze Maze { get; set; }
|
|
[Property] public InteractTeleporter Teleporter { get; set; }
|
|
|
|
int maxAttempts = 30;
|
|
|
|
public override bool Press( IPressable.Event e )
|
|
{
|
|
base.Press( e );
|
|
if ( Maze.IsValid() )
|
|
{
|
|
Maze.RpcRequestMaze();
|
|
}
|
|
else
|
|
{
|
|
// Log.Info( "pressed teleport maze" );
|
|
// return false;
|
|
}
|
|
|
|
DoTeleport();
|
|
return true;
|
|
}
|
|
|
|
private async void DoTeleport()
|
|
{
|
|
int attempt = 0;
|
|
|
|
if ( Maze.IsValid() )
|
|
{
|
|
while ( !Maze.IsReady && attempt < maxAttempts )
|
|
{
|
|
await Task.Delay( 1000 );
|
|
attempt++;
|
|
}
|
|
|
|
if ( Maze.IsReady )
|
|
{
|
|
// Teleporter.TeleportAll();
|
|
foreach ( var player in Teleporter.Players )
|
|
{
|
|
Teleporter.Teleport( player, Maze.GetRandomCellPosition() );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log.Warning( "Maze was not ready in time. Teleport aborted." );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Teleporter.TeleportAll();
|
|
}
|
|
}
|
|
}
|