diff --git a/code/Entities/MinigameManager.cs b/code/Entities/MinigameManager.cs index f7a9be4..0832c8b 100644 --- a/code/Entities/MinigameManager.cs +++ b/code/Entities/MinigameManager.cs @@ -46,4 +46,13 @@ public partial class MinigameManager : Entity { FindMinigames(); } + + public void Tick() + { + if ( LoadedMinigame is not { IsValid: true } ) + { + return; + } + LoadedMinigame.Tick(); + } } diff --git a/code/Entities/RoundManager.cs b/code/Entities/RoundManager.cs index 2771b06..ae7941a 100644 --- a/code/Entities/RoundManager.cs +++ b/code/Entities/RoundManager.cs @@ -73,6 +73,11 @@ public partial class RoundManager : Entity Log.Info( "Starting round" ); StartRound(); } + + if ( RoundState == RoundState.InProgress ) + { + MinigameManager.Tick(); + } } /// @@ -117,4 +122,10 @@ public partial class RoundManager : Entity Players = All.OfType().ToList(); MinigameManager.StartRandomMinigame( Players ); } + + [ConCmd.Server("start_round")] + public static void ForceStart() + { + Entity.All.OfType().FirstOrDefault()?.StartRound(); + } } diff --git a/code/EntityComponents/Lucker/Cameras/AbstractCamera.cs b/code/EntityComponents/Lucker/Cameras/AbstractCamera.cs index d30de0f..0d9e6d7 100644 --- a/code/EntityComponents/Lucker/Cameras/AbstractCamera.cs +++ b/code/EntityComponents/Lucker/Cameras/AbstractCamera.cs @@ -3,8 +3,9 @@ using Sandbox; namespace LuckerGame.Components.Lucker.Cameras; -public abstract class AbstractCamera : EntityComponent +public abstract class AbstractCamera : EntityComponent, ISingletonComponent { + public virtual bool ShouldShowCursor => false; protected Vector3 CameraPosition { get; set; } protected Rotation CameraRotation { get; set; } protected float FieldOfView { get; set; } diff --git a/code/EntityComponents/Lucker/Cameras/RTSCamera.cs b/code/EntityComponents/Lucker/Cameras/RTSCamera.cs index 4d5d905..e107fba 100644 --- a/code/EntityComponents/Lucker/Cameras/RTSCamera.cs +++ b/code/EntityComponents/Lucker/Cameras/RTSCamera.cs @@ -9,6 +9,7 @@ namespace LuckerGame.Components.Lucker.Cameras; /// public partial class RTSCamera : AbstractCamera, ISingletonComponent { + public override bool ShouldShowCursor => true; private const float MaxDistance = 400f; private const float MinDistance = 200f; private const float Speed = 4f; diff --git a/code/Minigames/Minigame.cs b/code/Minigames/Minigame.cs index d814282..c526597 100644 --- a/code/Minigames/Minigame.cs +++ b/code/Minigames/Minigame.cs @@ -7,12 +7,21 @@ namespace LuckerGame.Minigames; public abstract class Minigame : Entity { - public abstract string Name { get; } /// - /// Initializes the minigame with a list of luckers playing it + /// The name of this minigame + /// + public abstract string Name { get; } + + /// + /// Initializes the minigame with a list of luckers playing it. /// /// the players who made it into the minigame public abstract void Initialize(List players); + + /// + /// Once a minigame is loaded and initialized, this method is called once per server tick. + /// + public abstract void Tick(); /// /// Cleans up any entities and components created by this minigame. diff --git a/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs b/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs index a2397cc..7633166 100644 --- a/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs +++ b/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using LuckerGame.Components.Lucker.Cameras; using LuckerGame.Entities; using Sandbox; @@ -9,28 +10,51 @@ namespace LuckerGame.Minigames.RussianRoulette; public class RussianRouletteMinigame : Minigame { public override string Name => "Russian Roulette"; + private List Players { get; set; } + private Pawn Shooter { get; set; } + private const float ShooterDistance = 50f; + private const int CardinalDirections = 4; public override void Initialize( List players ) { - var pawn = new Pawn(); + Players = players; + Shooter = new Pawn(); - // Get all of the spawnpoints + /*// Spawn shooter at a random spawnpoint var spawnpoints = Entity.All.OfType(); - - // chose a random one var randomSpawnPoint = spawnpoints.OrderBy( x => Guid.NewGuid() ).FirstOrDefault(); + var tx = randomSpawnPoint.Transform; + tx.Position = tx.Position + Vector3.Up * 50.0f; // raise it up + Shooter.Position = tx.Position;*/ - // if it exists, place the pawn there - if ( randomSpawnPoint != null ) + // Setup cameras for players + Players.ForEach( player => { - var tx = randomSpawnPoint.Transform; - tx.Position = tx.Position + Vector3.Up * 50.0f; // raise it up - pawn.Position = tx.Position; - } + player.Components.Create(); + player.Position = Shooter.Position; + } ); + + Players.Select((player, i) => (Player: player, Index: i) ).ToList().ForEach( pair => + { + var player = pair.Player; + var index = pair.Index; + var pawn = new Pawn(); + player.Pawn = pawn; + pawn.DressFromClient( player.Client ); + + var pawnOffset = ShooterDistance * (index % 2 == 0 ? Vector3.Forward : Vector3.Right) * (index % 4 >= 2 ? -1 : 1); + + player.Pawn.Position = Shooter.Position + pawnOffset; + } ); + } + + public override void Tick() + { + return; } public override void Cleanup() { - throw new System.NotImplementedException(); + Shooter?.Delete(); } } diff --git a/code/UI/Hud.razor b/code/UI/Hud.razor index 8322108..75e06e5 100644 --- a/code/UI/Hud.razor +++ b/code/UI/Hud.razor @@ -10,10 +10,9 @@ - + - -
+ diff --git a/code/UI/HudComponents/CameraCursor.razor b/code/UI/HudComponents/CameraCursor.razor new file mode 100644 index 0000000..e32e736 --- /dev/null +++ b/code/UI/HudComponents/CameraCursor.razor @@ -0,0 +1,16 @@ +@using LuckerGame.Components.Lucker.Cameras +@using Sandbox +@using Sandbox.UI +@namespace LuckerGame.UI.HudComponents +@attribute [StyleSheet] +@inherits Panel + +@if (ShouldShowCursor) +{ + +} + + +@code { + private bool ShouldShowCursor => Game.LocalClient.Pawn?.Components.Get()?.ShouldShowCursor ?? false; +} \ No newline at end of file diff --git a/code/UI/HudComponents/CameraCursor.razor.scss b/code/UI/HudComponents/CameraCursor.razor.scss new file mode 100644 index 0000000..82e3b95 --- /dev/null +++ b/code/UI/HudComponents/CameraCursor.razor.scss @@ -0,0 +1,3 @@ +CameraCursor { + pointer-events: all; +} \ No newline at end of file diff --git a/code/UI/HudComponents/Scoreboard.razor.scss b/code/UI/HudComponents/Scoreboard.razor.scss index e1211f3..d91045b 100644 --- a/code/UI/HudComponents/Scoreboard.razor.scss +++ b/code/UI/HudComponents/Scoreboard.razor.scss @@ -1,3 +1,6 @@ Scoreboard { z-index: 0; + .scoreboard-panel { + flex-direction: column; + } } \ No newline at end of file