From 686edc85a39a1b101d42ab33144a2b46cec3b8a1 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Thu, 3 Aug 2023 11:45:09 -0400 Subject: [PATCH 1/8] Basic round loop done --- code/Entities/MinigameManager.cs | 30 +++++++++++++++++-- code/Entities/RoundManager.cs | 19 +++++++++++- code/Minigames/Minigame.cs | 3 +- .../RussianRouletteMinigame.cs | 15 ++++++++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/code/Entities/MinigameManager.cs b/code/Entities/MinigameManager.cs index b3b8fa5..111cd39 100644 --- a/code/Entities/MinigameManager.cs +++ b/code/Entities/MinigameManager.cs @@ -14,6 +14,7 @@ public partial class MinigameManager : Entity { [Net] public Minigame LoadedMinigame { get; private set; } private List AvailableMinigames { get; set; } + private List InvolvedPlayers { get; set; } public override void Spawn() { @@ -23,6 +24,7 @@ public partial class MinigameManager : Entity public void StartMinigame(List players, string minigameName = null) { + InvolvedPlayers = players.ToList(); if (CheckForMinigames()) { LoadedMinigame = string.IsNullOrEmpty( minigameName ) ? AvailableMinigames.OrderBy( _ => Guid.NewGuid() ).FirstOrDefault() : TypeLibrary.Create( minigameName ); @@ -54,13 +56,35 @@ public partial class MinigameManager : Entity { FindMinigames(); } + + private void cleanupPlayerPawns() + { + InvolvedPlayers.ForEach( player => + { + player.Pawn.Delete(); + player.Pawn = null; + } ); + } - public void Tick() + /// + /// Called once per tick by the RoundManager. Ticks any running minigame. + /// + /// true if the current minigame has ended, else false + public bool Tick() { if ( LoadedMinigame is not { IsValid: true } ) { - return; + return false; } - LoadedMinigame.Tick(); + var ended = LoadedMinigame.Tick(); + if ( !ended ) + { + return false; + } + + LoadedMinigame.Cleanup(); + LoadedMinigame = null; + return true; + } } diff --git a/code/Entities/RoundManager.cs b/code/Entities/RoundManager.cs index e4f3780..65b21a3 100644 --- a/code/Entities/RoundManager.cs +++ b/code/Entities/RoundManager.cs @@ -76,7 +76,19 @@ public partial class RoundManager : Entity if ( RoundState == RoundState.InProgress ) { - MinigameManager.Tick(); + var ended = MinigameManager.Tick(); + if ( ended ) + { + MinigamesLeftInRound--; + if ( MinigamesLeftInRound > 0 ) + { + MinigameManager.StartMinigame( Players ); + } + else + { + RoundState = RoundState.NotStarted; + } + } } } @@ -120,6 +132,11 @@ public partial class RoundManager : Entity RoundState = RoundState.InProgress; Players = All.OfType().ToList(); + Players.ForEach( player => + { + player.Ready = false; + } ); + MinigamesLeftInRound = MinigamesPerRound; MinigameManager.StartMinigame( Players, minigameName ); } diff --git a/code/Minigames/Minigame.cs b/code/Minigames/Minigame.cs index c526597..ada9d05 100644 --- a/code/Minigames/Minigame.cs +++ b/code/Minigames/Minigame.cs @@ -21,7 +21,8 @@ public abstract class Minigame : Entity /// /// Once a minigame is loaded and initialized, this method is called once per server tick. /// - public abstract void Tick(); + /// true if the minigame has ended, false otherwise + public abstract bool 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 55ab89f..52885bf 100644 --- a/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs +++ b/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs @@ -16,8 +16,10 @@ public class RussianRouletteMinigame : Minigame public override string Name => "Russian Roulette"; private List Players { get; set; } private Pawn Shooter { get; set; } + private const float ShooterDistance = 80f; private const float TimeBetweenShots = 7f; + private const float TimeBetweenDeathAndEnd = 5f; private int Taunted = 0; private List DeadVictims => Players @@ -26,6 +28,7 @@ public class RussianRouletteMinigame : Minigame .ToList(); private TimeSince TimeSinceShot { get; set; } + private TimeSince TimeSinceDeadVictim { get; set; } public override void Initialize( List players ) { @@ -60,7 +63,7 @@ public class RussianRouletteMinigame : Minigame TimeSinceShot = 0; } - public override void Tick() + public override bool Tick() { if ( DeadVictims.Any() ) { @@ -68,10 +71,14 @@ public class RussianRouletteMinigame : Minigame { ChatBox.AddChatEntry( To.Everyone, "Shooter", "Heh, nothing personnel, kid." ); Taunted = int.MaxValue; + TimeSinceDeadVictim = 0; + } + else if(TimeSinceDeadVictim > TimeBetweenDeathAndEnd) + { + return true; } - return; } - if ( TimeSinceShot > TimeBetweenShots ) + else if ( TimeSinceShot > TimeBetweenShots ) { TimeSinceShot = 0; Taunted = 0; @@ -95,6 +102,8 @@ public class RussianRouletteMinigame : Minigame ChatBox.AddChatEntry( To.Everyone, "Shooter", "Im gettin' ready!" ); Taunted++; } + + return false; } public override void Cleanup() -- 2.49.1 From a5a734b31a69cebdbcf255dfee49796b078646da Mon Sep 17 00:00:00 2001 From: gamer147 Date: Thu, 3 Aug 2023 12:22:24 -0400 Subject: [PATCH 2/8] Pulls in FPS menu so we can make edits --- .sbproj | 15 +- code/Entities/MinigameManager.cs | 10 +- code/Entities/RoundManager.cs | 3 +- code/UI/MainMenu/ActiveLobby.razor | 121 ++++++++++++++ code/UI/MainMenu/FrontPage.razor | 40 +++++ code/UI/MainMenu/LoadingScreen.razor | 31 ++++ code/UI/MainMenu/LoadingScreen.razor.scss | 50 ++++++ code/UI/MainMenu/LobbyBrowser.razor | 66 ++++++++ code/UI/MainMenu/MainMenu.razor | 40 +++++ code/UI/MainMenu/MainMenu.razor.scss | 195 ++++++++++++++++++++++ code/UI/MainMenu/SavedGames.razor | 44 +++++ code/UI/MainMenu/SetupGame.razor | 78 +++++++++ code/UI/MainMenu/SlimPackageCard.razor | 32 ++++ 13 files changed, 722 insertions(+), 3 deletions(-) create mode 100644 code/UI/MainMenu/ActiveLobby.razor create mode 100644 code/UI/MainMenu/FrontPage.razor create mode 100644 code/UI/MainMenu/LoadingScreen.razor create mode 100644 code/UI/MainMenu/LoadingScreen.razor.scss create mode 100644 code/UI/MainMenu/LobbyBrowser.razor create mode 100644 code/UI/MainMenu/MainMenu.razor create mode 100644 code/UI/MainMenu/MainMenu.razor.scss create mode 100644 code/UI/MainMenu/SavedGames.razor create mode 100644 code/UI/MainMenu/SetupGame.razor create mode 100644 code/UI/MainMenu/SlimPackageCard.razor diff --git a/.sbproj b/.sbproj index f6de3ac..0e6ffda 100644 --- a/.sbproj +++ b/.sbproj @@ -37,7 +37,20 @@ "GameSettings": {}, "Addons": "", "PreLaunchCommand": "", - "PostLaunchCommand": "" + "PostLaunchCommand": "lucker_minigames_per_round 1" + } + ], + "PackageSettings": [ + { + "DisplayType": "Integer", + "Choices": [], + "ConVarName": "lucker_minigames_per_round", + "DisplayName": "Minigames Per Round", + "DefaultValue": "0", + "Description": "The number of minigames played per round", + "Group": "Other", + "Minimum": 1, + "Maximum": 12 } ] } diff --git a/code/Entities/MinigameManager.cs b/code/Entities/MinigameManager.cs index 111cd39..a9f6650 100644 --- a/code/Entities/MinigameManager.cs +++ b/code/Entities/MinigameManager.cs @@ -57,8 +57,16 @@ public partial class MinigameManager : Entity FindMinigames(); } - private void cleanupPlayerPawns() + /// + /// Goes through the players included in the loaded minigame and deletes and nulls out any pawns assigned to them + /// + private void CleanupPlayerPawns() { + if ( LoadedMinigame is not { IsValid: true } || InvolvedPlayers == null) + { + Log.Warning( "Attempted to clean up players without a minigame loaded!" ); + return; + } InvolvedPlayers.ForEach( player => { player.Pawn.Delete(); diff --git a/code/Entities/RoundManager.cs b/code/Entities/RoundManager.cs index 65b21a3..5a384b6 100644 --- a/code/Entities/RoundManager.cs +++ b/code/Entities/RoundManager.cs @@ -49,7 +49,8 @@ public partial class RoundManager : Entity private const int MinigamesPerRound = 1; - private int MinigamesLeftInRound { get; set; } + [ConVar.Replicated("lucker_minigames_per_round")] + public static int MinigamesLeftInRound { get; set; } private List Players { get; set; } #endregion diff --git a/code/UI/MainMenu/ActiveLobby.razor b/code/UI/MainMenu/ActiveLobby.razor new file mode 100644 index 0000000..9f5a775 --- /dev/null +++ b/code/UI/MainMenu/ActiveLobby.razor @@ -0,0 +1,121 @@ +@using Sandbox; +@using System; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; +@using Sandbox.UI; + +@namespace LuckerGame.UI.MainMenu +@inherits Panel + + + + + @if ( Lobby == null ) + { +
+ Loading... + + Return +
+ } + else + { + +
+
+ + +
+ @foreach (var member in Lobby.Members) + { + + } +
+
+ + @if ( Lobby.Owner.IsMe ) + { +
+ @if ( MaxPlayersSupported > 1 ) + { + + + + + + + } + + + + + + + +
+ } + +
+ + + Leave Lobby + + Start + + Return +
+ } + + +@code +{ + Friend Owner => Lobby.Owner; + ILobby Lobby => Game.Menu.Lobby; + + int MaxPlayersSupported { get; set; } = 1; + Package MapPackage { get; set; } + + void OnMapClicked() + { + Game.Overlay.ShowPackageSelector( "type:map sort:popular", OnMapSelected ); + StateHasChanged(); + } + + void OnMapSelected( Package map ) + { + MapPackage = map; + Game.Menu.Lobby.Map = map.FullIdent; + + StateHasChanged(); + } + + public void LeaveLobby() + { + Lobby?.Leave(); + + this.Navigate( "/lobby/list" ); + } + + async Task Start() + { + await Game.Menu.StartServerAsync( Game.Menu.Lobby.MaxMembers, $"{Game.Menu.Lobby.Owner.Name}'s game", Game.Menu.Lobby.Map ); + } + + async void FetchPackage() + { + MapPackage = await Package.FetchAsync( Game.Menu.Lobby?.Map ?? "facepunch.square", true ); + } + + protected override void OnAfterTreeRender( bool firstTime ) + { + FetchPackage(); + } + + protected override void OnParametersSet() + { + MaxPlayersSupported = Game.Menu.Package.GetMeta( "MaxPlayers", 1 ); + } +} \ No newline at end of file diff --git a/code/UI/MainMenu/FrontPage.razor b/code/UI/MainMenu/FrontPage.razor new file mode 100644 index 0000000..8d9d690 --- /dev/null +++ b/code/UI/MainMenu/FrontPage.razor @@ -0,0 +1,40 @@ +@using Sandbox; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; +@using Sandbox.UI; +@namespace LuckerGame.UI.MainMenu + + +
+ @Game.Menu.Package.Title +
+ +
+ @if (Game.InGame) + { + Leave + } + else + { + Play + + Lobbies + + @if ( Game.Menu.Package.SupportsSavedGames && Game.Menu.SavedGames.Any()) + { + Load Save + } + } + + Quit +
+
+ +@code +{ + void LeaveGame() + { + Game.Menu.LeaveServer( "Leaving" ); + } +} \ No newline at end of file diff --git a/code/UI/MainMenu/LoadingScreen.razor b/code/UI/MainMenu/LoadingScreen.razor new file mode 100644 index 0000000..2ec5690 --- /dev/null +++ b/code/UI/MainMenu/LoadingScreen.razor @@ -0,0 +1,31 @@ +@using Sandbox; +@using Sandbox.UI; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; + +@inherits RootPanel +@implements Sandbox.Menu.ILoadingScreenPanel +@attribute [StyleSheet] +@namespace LuckerGame.UI.MainMenu + + +
+ +
+ + + + +@code +{ + public LoadingProgress Progress; + + public void OnLoadingProgress( LoadingProgress progress ) + { + Progress = progress; + StateHasChanged(); + } +} diff --git a/code/UI/MainMenu/LoadingScreen.razor.scss b/code/UI/MainMenu/LoadingScreen.razor.scss new file mode 100644 index 0000000..6c5893a --- /dev/null +++ b/code/UI/MainMenu/LoadingScreen.razor.scss @@ -0,0 +1,50 @@ + +LoadingScreen +{ + background-color: #262934; + padding: 128px 128px; + opacity: 1; + flex-direction: column; + font-size: 25px; + width: 100%; + height: 100%; + position: absolute; + transition: all 0.3s ease-out; + color: rgba( white, 0.8 ); + + .background + { + position: absolute; + width: 100%; + height: 100%; + background-image: url( https://files.facepunch.com/tony/1b1311b1/boxes.webm ); + opacity: 0.2; + background-size: contain; + filter: blur( 20px ); + mask: linear-gradient( 45deg, white, white, black ); + mask-scope: filter; + } + + &:intro + { + opacity: 0; + transform: scaleX( 1.1 ); + } + + .game-title + { + font-family: Roboto; + font-weight: 700; + font-size: 70px; + color: rgba( white, 1 ); + } + + .controls + { + flex-direction: column; + gap: 50px; + align-items: flex-start; + font-family: Roboto; + text-transform: uppercase; + } +} diff --git a/code/UI/MainMenu/LobbyBrowser.razor b/code/UI/MainMenu/LobbyBrowser.razor new file mode 100644 index 0000000..fae7358 --- /dev/null +++ b/code/UI/MainMenu/LobbyBrowser.razor @@ -0,0 +1,66 @@ +@using Sandbox; +@using System; +@using System.Linq; +@using System.Threading.Tasks; +@using Sandbox.Menu; +@using Sandbox.UI; +@namespace LuckerGame.UI.MainMenu +@inherits Panel + + + + +
+
+ + refresh +
+ + + + + + +@code +{ + public async void CreateLobbyAsync() + { + await Game.Menu.CreateLobbyAsync( 64, "game", true ); + Game.Menu.Lobby.Map = "facepunch.square"; + this.Navigate( "/lobby/active" ); + } + + public async void JoinLobby( ILobby lobby ) + { + if ( lobby == null ) return; + + // don't exist in two lobbies at once + Game.Menu.Lobby?.Leave(); + + await lobby.JoinAsync(); + this.Navigate( "/lobby/active" ); + } + + public async void Refresh() + { + await Game.Menu.QueryLobbiesAsync( null, 1 ); + + StateHasChanged(); + } + + protected override int BuildHash() + { + return HashCode.Combine( Game.Menu.Lobbies.Count() ); + } +} \ No newline at end of file diff --git a/code/UI/MainMenu/MainMenu.razor b/code/UI/MainMenu/MainMenu.razor new file mode 100644 index 0000000..1b9f997 --- /dev/null +++ b/code/UI/MainMenu/MainMenu.razor @@ -0,0 +1,40 @@ +@using System; +@using Sandbox; +@using Sandbox.UI; + +@inherits Sandbox.UI.NavHostPanel +@implements Sandbox.Menu.IGameMenuPanel +@attribute [StyleSheet] +@namespace LuckerGame.UI.MainMenu + + +
+