feature/Lucker-misc_RoundFramework #2

Merged
para merged 8 commits from feature/Lucker-misc_RoundFramework into master 2023-08-07 05:13:13 +00:00
4 changed files with 78 additions and 17 deletions
Showing only changes of commit 5f804f5c24 - Show all commits

View File

@@ -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
{
/// <summary>
/// The entity this Player currently controls
/// The entity this player controls. This value is networked and should be accessed through <see cref="Pawn"/>.
/// </summary>
public Entity Pawn { get; set; }
[Net] private Entity InternalPawn { get; set; }
/// <summary>
/// Accesses or sets the entity this player current controls
/// </summary>
public Entity Pawn
{
get => InternalPawn;
set
{
InternalPawn = value;
value.Owner = this;
}
}
Review

According to Bing Chat this can be

value?.Owner = this
According to Bing Chat this can be ```cs value?.Owner = this ```
Review


Please ask bing chat which version of C# it believes supports this feature

![](https://media.discordapp.net/attachments/501842091983241218/1137254962603241543/image.png) Please ask bing chat which version of C# it believes supports this feature
Review

Yeah that's what I thought. I asked it and it just confidently lies about it and doesn't admit it's wrong. I found this stack overflow article on the topic and they just suggest a setValue() method but that's kinda dumb for one-offs.

Yeah that's what I thought. I asked it and it just confidently lies about it and doesn't admit it's wrong. [I found this stack overflow article on the topic and they just suggest a `setValue()` method but that's kinda dumb for one-offs.](https://stackoverflow.com/questions/35887106/using-the-null-conditional-operator-on-the-left-hand-side-of-an-assignment)
/// <summary>
/// Before the round has started, this player indicated they were ready
@@ -24,6 +38,8 @@ public partial class Lucker : Entity
/// This Lucker's camera
/// </summary>
[BindComponent] public AbstractCamera Camera { get; }
[BindComponent] public LuckerStats Stats { get; }
/// <summary>
/// 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<RTSCamera>();
var stats = player.Components.Create<LuckerStats>();
return player;
}
Outdated
Review

nit: unused locals

nit: unused locals
Outdated
Review

Should be fixed

Should be fixed

View File

@@ -12,8 +12,19 @@ namespace LuckerGame.Entities;
/// </summary>
public partial class MinigameManager : Entity
{
/// <summary>
/// The currently loaded minigame
/// </summary>
[Net] public Minigame LoadedMinigame { get; private set; }
/// <summary>
/// A cached list of available minigames. Gets reloaded on a hotreload
/// </summary>
private List<TypeDescription> AvailableMinigames { get; set; }
/// <summary>
/// The players involved in the current minigame
/// </summary>
private List<Lucker> InvolvedPlayers { get; set; }
Outdated
Review

I think this correctly caches the Lucker list when the minigame is created, which is nice. Although I'm wondering how we deal with Luckers who leave before a minigame is ended. If there's other logic that deletes a Lucker in response to the client disconnecting, will the logic in CleanupPlayerPawns() fail / crash?

Also, I feel like it'd be nice to standardize the naming of these variables to disambiguate references to Players and Luckers. Might as well just name variables after the type to avoid clashing the names.

I think this correctly caches the `Lucker` list when the minigame is created, which is nice. Although I'm wondering how we deal with Luckers who leave before a minigame is ended. If there's other logic that deletes a `Lucker` in response to the client disconnecting, will the logic in `CleanupPlayerPawns()` fail / crash? Also, I feel like it'd be nice to standardize the naming of these variables to disambiguate references to `Player`s and `Lucker`s. Might as well just name variables after the type to avoid clashing the names.
Outdated
Review

I agree with the variable naming, and will go through and do that.

I think an investigation into handling client disconnects should be done in another ticket however, as I believe there's both an investigation in how S&box handles a client disconnect by default, and also a discussion in how we handle it, such as keeping the player around for the remainder of the round but assigning them to a bot, only a minigame, leave it up to the minigames, etc.

I agree with the variable naming, and will go through and do that. I think an investigation into handling client disconnects should be done in another ticket however, as I believe there's both an investigation in how S&box handles a client disconnect by default, and also a discussion in how we handle it, such as keeping the player around for the remainder of the round but assigning them to a bot, only a minigame, leave it up to the minigames, etc.
Outdated
Review

Variables should be renamed now based on the naming of 'Lucker' as opposed to player for the most part

Variables should be renamed now based on the naming of 'Lucker' as opposed to player for the most part
public override void Spawn()

View File

@@ -1,15 +0,0 @@
using Sandbox;
namespace LuckerGame.EntityComponents.Lucker;
/// <summary>
/// A component for capturing and passing around a client's input for an attached Lucker
/// </summary>
public class LuckerClientInput : EntityComponent<Entities.Lucker>
{
[ClientInput]
public Vector3 InputDirection { get; set; }
[ClientInput]
public Angles ViewAngles { get; set; }
}

View File

@@ -0,0 +1,48 @@
using Sandbox;
using Sandbox.UI;
namespace LuckerGame.EntityComponents.Lucker;
/// <summary>
/// Handles the stats associated with a lucker during a lobby.
/// </summary>
public partial class LuckerStats : EntityComponent<Entities.Lucker>, ISingletonComponent
{
/// <summary>
/// The lucker's current score.
/// </summary>
[Net] private long Score { get; set; }
/// <summary>
/// Adds points to this lucker's score
/// </summary>
/// <param name="points">points to add (or remove if negative)</param>
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 );
}
/// <summary>
/// Resets this lucker's score to zero
/// </summary>
public void ResetScore()
{
Score = 0;
}
/// <summary>
/// Gets this lucker's current score
/// </summary>
/// <returns>this lucker's current score</returns>
public long GetScore()
{
return Score;
}
}