ArenaSelection.cs
using Sandbox;
namespace PaintballBaddies;
// Both modes share each arena, session and native scene-loading path.
public static class ArenaSelection
{
public const string Foundry="scenes/neon_foundry.scene";
public const string Restaurant="scenes/last_orders.scene";
public const string Marine="scenes/marine_base.scene";
public static string Current(Scene scene)=>ArenaMap.DisplayTitle(scene) switch {"Marine Base"=>Marine,"Last Orders" or "The Missing Link Diner"=>Restaurant,_=>Foundry};
private static bool pending;
private static ArenaGameMode mode;
private static int minutes;
private static bool publicLobby;
private static bool showSetup;
internal static bool TakeSetupRequest(){bool value=showSetup;showSetup=false;return value;}
public static bool Change(Scene scene,string path)
{
if(path!=Foundry && path!=Marine && path!=Restaurant)return false;
if(MultiplayerSession.Online && !Networking.IsHost)return false;
if(Current(scene)==path)return true;
var session=MultiplayerSession.Find(scene);
var options=new SceneLoadOptions{ShowLoadingScreen=true,IsAdditive=false,DeleteEverything=true};
if(!options.SetScene(path))return false;
mode=session?.Mode ?? ArenaGameMode.PaintRush;
minutes=MultiplayerSession.Online ? session?.Minutes ?? 3 : (int)(MultiplayerSession.LocalPlayer(scene)?.Components.Get<ArenaMatch>()?.RoundDuration ?? 180)/60;
publicLobby=session?.PublicLobby ?? true;
pending=true;
showSetup=true;
scene.TimeScale=1;
Input.ReleaseActions();
if(Game.ChangeScene(options))return true;
pending=false;showSetup=false;return false;
}
internal static void Restore(MultiplayerSession session)
{
if(!pending || !MultiplayerSession.Authority)return;
pending=false;
session.RestoreArenaSelection(mode,minutes,publicLobby);
var match=MultiplayerSession.LocalPlayer(session.Scene)?.Components.Get<ArenaMatch>();
if(match.IsValid())match.RoundDuration=minutes*60;
}
}