Compare commits
6 Commits
bdb25fd3ce
...
fixed-came
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9dbe07e1f | ||
|
|
4a338d9502 | ||
| 39b9f71801 | |||
|
|
ef88c51454 | ||
|
|
35be78c341 | ||
|
|
5c0a454b79 |
@@ -21,19 +21,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,12 @@ public partial class RoundManager : Entity
|
|||||||
|
|
||||||
RoundState = RoundState.InProgress;
|
RoundState = RoundState.InProgress;
|
||||||
Players = All.OfType<Lucker>().ToList();
|
Players = All.OfType<Lucker>().ToList();
|
||||||
MinigameManager.StartRandomMinigame( Players );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using Sandbox;
|
|||||||
|
|
||||||
namespace LuckerGame.Components.Lucker.Cameras;
|
namespace LuckerGame.Components.Lucker.Cameras;
|
||||||
|
|
||||||
public abstract class AbstractCamera : EntityComponent<Entities.Lucker>, ISingletonComponent
|
public abstract partial class AbstractCamera : EntityComponent<Entities.Lucker>, ISingletonComponent
|
||||||
{
|
{
|
||||||
public virtual bool ShouldShowCursor => false;
|
public virtual bool ShouldShowCursor => false;
|
||||||
protected Vector3 CameraPosition { get; set; }
|
protected Vector3 CameraPosition { get; set; }
|
||||||
@@ -16,11 +16,11 @@ public abstract class AbstractCamera : EntityComponent<Entities.Lucker>, ISingle
|
|||||||
/// Handles any input-independent camera updates (ie following a pawn)
|
/// Handles any input-independent camera updates (ie following a pawn)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void UpdateCameraParameters();
|
protected abstract void UpdateCameraParameters();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles any input dependent camera updates (ie moving around a top down cam)
|
/// Handles any input dependent camera updates (ie moving around a top down cam)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract void BuildInput();
|
public virtual void BuildInput() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Applies Camera parameters to the static Camera
|
/// Applies Camera parameters to the static Camera
|
||||||
|
|||||||
41
code/EntityComponents/Lucker/Cameras/FixedCamera.cs
Normal file
41
code/EntityComponents/Lucker/Cameras/FixedCamera.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Sandbox;
|
||||||
|
|
||||||
|
namespace LuckerGame.Components.Lucker.Cameras;
|
||||||
|
|
||||||
|
public partial class FixedCamera : AbstractCamera, ISingletonComponent
|
||||||
|
{
|
||||||
|
[Net] public float FieldOfViewValue { get; set; } = 70f;
|
||||||
|
public override bool ShouldShowCursor => true;
|
||||||
|
protected override void UpdateCameraParameters()
|
||||||
|
{
|
||||||
|
FieldOfView = FieldOfViewValue;
|
||||||
|
FirstPersonViewer = null;
|
||||||
|
SoundSource = new Transform { Position = CameraPosition };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ClientRpc doesn't allow for nullable versions of non-nullable types
|
||||||
|
/// so here we are
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateCameraPositionRotation( Vector3? position = null, Rotation? rotation = null )
|
||||||
|
{
|
||||||
|
CameraPosition = (Vector3)(position.Equals( null ) ? CameraPosition : position);
|
||||||
|
CameraRotation = (Rotation)(rotation.Equals( null ) ? CameraRotation : rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ClientRpc]
|
||||||
|
public void LookAt( Vector3 position )
|
||||||
|
{
|
||||||
|
UpdateCameraPositionRotation( position );
|
||||||
|
}
|
||||||
|
[ClientRpc]
|
||||||
|
public void LookAt( Rotation rotation )
|
||||||
|
{
|
||||||
|
UpdateCameraPositionRotation( rotation: rotation );
|
||||||
|
}
|
||||||
|
[ClientRpc]
|
||||||
|
public void LookAt( Vector3 position, Rotation rotation )
|
||||||
|
{
|
||||||
|
UpdateCameraPositionRotation( position, rotation );
|
||||||
|
}
|
||||||
|
}
|
||||||
52
code/Minigames/TerryRaces/TerryRacesMinigame.cs
Normal file
52
code/Minigames/TerryRaces/TerryRacesMinigame.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
using LuckerGame.Components.Lucker.Cameras;
|
||||||
|
using LuckerGame.Components.Pawn;
|
||||||
|
using LuckerGame.Entities;
|
||||||
|
using Sandbox;
|
||||||
|
using Sandbox.UI;
|
||||||
|
|
||||||
|
namespace LuckerGame.Minigames.TerryRaces;
|
||||||
|
|
||||||
|
[Library( "mg_terry_races" )]
|
||||||
|
public class TerryRaces : Minigame
|
||||||
|
{
|
||||||
|
public override string Name => "Terry Races";
|
||||||
|
private List<Lucker> Players { get; set; }
|
||||||
|
private FixedCamera camera;
|
||||||
|
|
||||||
|
public override void Initialize( List<Lucker> players )
|
||||||
|
{
|
||||||
|
Players = players;
|
||||||
|
// Setup cameras for players
|
||||||
|
Players.ForEach( player =>
|
||||||
|
{
|
||||||
|
camera = player.Components.Create<FixedCamera>();
|
||||||
|
camera.LookAt( new Vector3( -110f, 4f, 180f ), Rotation.FromPitch( 45 ) );
|
||||||
|
camera.FieldOfViewValue = 120f;
|
||||||
|
} );
|
||||||
|
|
||||||
|
Players.Select( ( player, i ) => (Player: player, Index: i) ).ToList().ForEach( pair =>
|
||||||
|
{
|
||||||
|
var player = pair.Player;
|
||||||
|
var index = pair.Index;
|
||||||
|
var pawn = new Pawn();
|
||||||
|
pawn.Name = player.Name;
|
||||||
|
pawn.Tags.Add( "victim" );
|
||||||
|
pawn.Health = 1;
|
||||||
|
player.Pawn = pawn;
|
||||||
|
pawn.DressFromClient( player.Client );
|
||||||
|
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Tick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Cleanup()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user