From 5f804f5c240ad82c30b5aaea96776df4a01805c1 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Thu, 3 Aug 2023 21:31:47 -0400 Subject: [PATCH] Adds basic lucker stats component holding score, removes unused client input fixes up lucker entity setting to properly set owner on the target entity --- code/Entities/Lucker.cs | 21 +++++++- code/Entities/MinigameManager.cs | 11 +++++ .../Lucker/LuckerClientInput.cs | 15 ------ code/EntityComponents/Lucker/LuckerStats.cs | 48 +++++++++++++++++++ 4 files changed, 78 insertions(+), 17 deletions(-) delete mode 100644 code/EntityComponents/Lucker/LuckerClientInput.cs create mode 100644 code/EntityComponents/Lucker/LuckerStats.cs diff --git a/code/Entities/Lucker.cs b/code/Entities/Lucker.cs index 3394cd4..4bffd2d 100644 --- a/code/Entities/Lucker.cs +++ b/code/Entities/Lucker.cs @@ -1,4 +1,5 @@ using LuckerGame.Components.Lucker.Cameras; +using LuckerGame.EntityComponents.Lucker; using LuckerGame.Events; using Sandbox; @@ -11,9 +12,22 @@ namespace LuckerGame.Entities; public partial class Lucker : Entity { /// - /// The entity this Player currently controls + /// The entity this player controls. This value is networked and should be accessed through . /// - public Entity Pawn { get; set; } + [Net] private Entity InternalPawn { get; set; } + + /// + /// Accesses or sets the entity this player current controls + /// + public Entity Pawn + { + get => InternalPawn; + set + { + InternalPawn = value; + value.Owner = this; + } + } /// /// Before the round has started, this player indicated they were ready @@ -24,6 +38,8 @@ public partial class Lucker : Entity /// This Lucker's camera /// [BindComponent] public AbstractCamera Camera { get; } + + [BindComponent] public LuckerStats Stats { get; } /// /// Creates and properly sets up a Player entity for a given client @@ -37,6 +53,7 @@ public partial class Lucker : Entity player.Owner = client as Entity; player.Name = client.Name; var camera = player.Components.Create(); + var stats = player.Components.Create(); return player; } diff --git a/code/Entities/MinigameManager.cs b/code/Entities/MinigameManager.cs index 73f1fcf..e478882 100644 --- a/code/Entities/MinigameManager.cs +++ b/code/Entities/MinigameManager.cs @@ -12,8 +12,19 @@ namespace LuckerGame.Entities; /// public partial class MinigameManager : Entity { + /// + /// The currently loaded minigame + /// [Net] public Minigame LoadedMinigame { get; private set; } + + /// + /// A cached list of available minigames. Gets reloaded on a hotreload + /// private List AvailableMinigames { get; set; } + + /// + /// The players involved in the current minigame + /// private List InvolvedPlayers { get; set; } public override void Spawn() diff --git a/code/EntityComponents/Lucker/LuckerClientInput.cs b/code/EntityComponents/Lucker/LuckerClientInput.cs deleted file mode 100644 index 0f0575d..0000000 --- a/code/EntityComponents/Lucker/LuckerClientInput.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Sandbox; - -namespace LuckerGame.EntityComponents.Lucker; - -/// -/// A component for capturing and passing around a client's input for an attached Lucker -/// -public class LuckerClientInput : EntityComponent -{ - [ClientInput] - public Vector3 InputDirection { get; set; } - - [ClientInput] - public Angles ViewAngles { get; set; } -} diff --git a/code/EntityComponents/Lucker/LuckerStats.cs b/code/EntityComponents/Lucker/LuckerStats.cs new file mode 100644 index 0000000..3e801ca --- /dev/null +++ b/code/EntityComponents/Lucker/LuckerStats.cs @@ -0,0 +1,48 @@ +using Sandbox; +using Sandbox.UI; + +namespace LuckerGame.EntityComponents.Lucker; + +/// +/// Handles the stats associated with a lucker during a lobby. +/// +public partial class LuckerStats : EntityComponent, ISingletonComponent +{ + /// + /// The lucker's current score. + /// + [Net] private long Score { get; set; } + + /// + /// Adds points to this lucker's score + /// + /// points to add (or remove if negative) + public void AddScore( long points ) + { + Score += points; + if ( points == 0 ) + { + return; + } + + var message = $"{Entity.Name} {(points > 0 ? "gained" : "lost")} {points} points!"; + ChatBox.AddInformation( To.Everyone, message ); + } + + /// + /// Resets this lucker's score to zero + /// + public void ResetScore() + { + Score = 0; + } + + /// + /// Gets this lucker's current score + /// + /// this lucker's current score + public long GetScore() + { + return Score; + } +}