start_round by minigame name
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using LuckerGame.Minigames;
|
using LuckerGame.Minigames;
|
||||||
|
using LuckerGame.Minigames.RussianRoulette;
|
||||||
using Sandbox;
|
using Sandbox;
|
||||||
using Sandbox.UI;
|
using Sandbox.UI;
|
||||||
|
|
||||||
@@ -21,19 +23,27 @@ public partial class MinigameManager : Entity
|
|||||||
FindMinigames();
|
FindMinigames();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartRandomMinigame(List<Lucker> players)
|
public void StartMinigame(List<Lucker> players, string minigameName = null)
|
||||||
|
{
|
||||||
|
if (CheckForMinigames())
|
||||||
|
{
|
||||||
|
LoadedMinigame = string.IsNullOrEmpty( minigameName ) ? AvailableMinigames.OrderBy( _ => Guid.NewGuid() ).FirstOrDefault() : TypeLibrary.Create<Minigame>( minigameName );
|
||||||
|
ChatBox.AddInformation( To.Everyone, $"Starting {LoadedMinigame.Name}" );
|
||||||
|
LoadedMinigame.Initialize( players );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckForMinigames()
|
||||||
{
|
{
|
||||||
if ( (AvailableMinigames?.Count ?? 0) == 0 )
|
if ( (AvailableMinigames?.Count ?? 0) == 0 )
|
||||||
{
|
{
|
||||||
Log.Error( "Attempted to start minigame, but none available" );
|
Log.Error( "Attempted to start minigame, but none available" );
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadedMinigame = AvailableMinigames.OrderBy( _ => Guid.NewGuid() ).FirstOrDefault();
|
return true;
|
||||||
ChatBox.AddInformation( To.Everyone, $"Starting {LoadedMinigame.Name}" );
|
|
||||||
LoadedMinigame.Initialize( players );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FindMinigames()
|
private void FindMinigames()
|
||||||
{
|
{
|
||||||
AvailableMinigames = TypeLibrary.GetTypes<Minigame>()
|
AvailableMinigames = TypeLibrary.GetTypes<Minigame>()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public partial class RoundManager : Entity
|
|||||||
/// The minigame manager we should be using to manage minigames
|
/// The minigame manager we should be using to manage minigames
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MinigameManager MinigameManager { get; set; }
|
private MinigameManager MinigameManager { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This percentage of the lobby must be ready to start the countdown for round start
|
/// This percentage of the lobby must be ready to start the countdown for round start
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,30 +27,30 @@ public partial class RoundManager : Entity
|
|||||||
/// The number of seconds from the timer starting before the round starts
|
/// The number of seconds from the timer starting before the round starts
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const float RoundStartCountdownSeconds = 5f;
|
private const float RoundStartCountdownSeconds = 5f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The state of the current round
|
/// The state of the current round
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Net] public RoundState RoundState { get; private set; }
|
[Net] public RoundState RoundState { get; private set; }
|
||||||
|
|
||||||
#region Countdown State
|
#region Countdown State
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How long since we started counting down to game start. Only useful if in the StartCountdown state.
|
/// How long since we started counting down to game start. Only useful if in the StartCountdown state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Net] public TimeSince TimeSinceCountdownStarted { get; set; }
|
[Net] public TimeSince TimeSinceCountdownStarted { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The number of seconds left in the countdown. Only useful if in the StartCountdown state.
|
/// The number of seconds left in the countdown. Only useful if in the StartCountdown state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int SecondsLeftInCountdown => (int)Math.Ceiling( RoundStartCountdownSeconds - TimeSinceCountdownStarted );
|
public int SecondsLeftInCountdown => (int)Math.Ceiling( RoundStartCountdownSeconds - TimeSinceCountdownStarted );
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region In Progress State
|
#region In Progress State
|
||||||
|
|
||||||
private const int MinigamesPerRound = 1;
|
private const int MinigamesPerRound = 1;
|
||||||
|
|
||||||
private int MinigamesLeftInRound { get; set; }
|
private int MinigamesLeftInRound { get; set; }
|
||||||
|
|
||||||
private List<Lucker> Players { get; set; }
|
private List<Lucker> Players { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public partial class RoundManager : Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartRound()
|
private void StartRound( string minigameName = null )
|
||||||
{
|
{
|
||||||
if ( RoundState == RoundState.InProgress )
|
if ( RoundState == RoundState.InProgress )
|
||||||
{
|
{
|
||||||
@@ -120,12 +120,20 @@ public partial class RoundManager : Entity
|
|||||||
|
|
||||||
RoundState = RoundState.InProgress;
|
RoundState = RoundState.InProgress;
|
||||||
Players = All.OfType<Lucker>().ToList();
|
Players = All.OfType<Lucker>().ToList();
|
||||||
MinigameManager.StartRandomMinigame( Players );
|
|
||||||
|
if ( string.IsNullOrEmpty( minigameName ) )
|
||||||
|
{
|
||||||
|
MinigameManager.StartMinigame( Players );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MinigameManager.StartMinigame( Players, minigameName );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConCmd.Server("start_round")]
|
[ConCmd.Server( "start_round" )]
|
||||||
public static void ForceStart()
|
public static void ForceStart( string minigameName = null )
|
||||||
{
|
{
|
||||||
Entity.All.OfType<RoundManager>().FirstOrDefault()?.StartRound();
|
Entity.All.OfType<RoundManager>().FirstOrDefault()?.StartRound( minigameName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user