From 0bba89a7858ce091f485e04284f853e1f7f304af Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sun, 6 Aug 2023 17:21:45 +0100 Subject: Reformat --- code/phase/AssignPhase.cs | 100 ++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'code/phase/AssignPhase.cs') diff --git a/code/phase/AssignPhase.cs b/code/phase/AssignPhase.cs index 90a8000..15891dc 100644 --- a/code/phase/AssignPhase.cs +++ b/code/phase/AssignPhase.cs @@ -1,20 +1,31 @@ -using Sandbox; -using Sandbox.UI; -using System; +using System; using System.Collections.Generic; using System.Linq; +using Sandbox; +using Sandbox.UI; namespace MurderGame; public partial class AssignPhase : BasePhase { - public override string Title => "Assigning teams"; - public int TicksElapsed; - - private List NatoNames = new() + private readonly List Colors = new() { - "Alpha", - "Bravo", + 0x0074D9, // blue + 0x7FDBFF, // aqua + 0x39CCCC, // teal + 0xF012BE, // fuchsia + 0xFF4136, // red + 0xFF851B, // orange + 0xFFDC00, // yellow + 0x3D9970, // olive + 0x2ECC40, // lime + 0x01FF70 // green + }; + + private readonly List NatoNames = new() + { + "Alpha", + "Bravo", "Charlie", "Delta", "Echo", @@ -40,77 +51,69 @@ public partial class AssignPhase : BasePhase "Yankee", "Zulu" }; - - private List Colors = new() - { - 0x0074D9, // blue - 0x7FDBFF, // aqua - 0x39CCCC, // teal - 0xF012BE, // fuchsia - 0xFF4136, // red - 0xFF851B, // orange - 0xFFDC00, // yellow - 0x3D9970, // olive - 0x2ECC40, // lime - 0x01FF70 // green - }; + + public int TicksElapsed; + public override string Title => "Assigning teams"; public override void Activate() { // cleanup -- start - foreach (var entity in Entity.All.OfType()) + foreach ( var entity in Entity.All.OfType() ) { entity.Delete(); } + DeleteFootprints(); // cleanup -- end var detectivesNeeded = 1; var murderersNeeded = 1; - + Random random = new(Guid.NewGuid().GetHashCode()); - + var spawnPoints = Entity.All.OfType().OrderBy( _ => random.Next() ).ToList(); var clients = Game.Clients.ToList().OrderBy( _ => random.Next() ); - var natoNamesRemaining = new List(NatoNames.OrderBy( _ => random.Next() )); - var colorsRemaining = new List(Colors.OrderBy( _ => random.Next() )); + var natoNamesRemaining = new List( NatoNames.OrderBy( _ => random.Next() ) ); + var colorsRemaining = new List( Colors.OrderBy( _ => random.Next() ) ); foreach ( var client in clients ) { - if (client.Pawn != null) + if ( client.Pawn != null ) { - ((Player) client.Pawn).Cleanup(); + ((Player)client.Pawn).Cleanup(); client.Pawn.Delete(); } - + Player pawn = new(); client.Pawn = pawn; - - if (spawnPoints.Count == 0) + + if ( spawnPoints.Count == 0 ) { ChatBox.Say( "Could not spawn " + client.Name + " as there are not enough spawn points." ); pawn.Team = Team.Spectator; continue; } - pawn.Dress( ); + + pawn.Dress(); // re-use names and colours if needed - if (natoNamesRemaining.Count == 0) + if ( natoNamesRemaining.Count == 0 ) { - natoNamesRemaining = new List(NatoNames); + natoNamesRemaining = new List( NatoNames ); } - if (colorsRemaining.Count == 0) + + if ( colorsRemaining.Count == 0 ) { - colorsRemaining = new List(Colors); + colorsRemaining = new List( Colors ); } // assign team - if (murderersNeeded > 0) + if ( murderersNeeded > 0 ) { pawn.Team = Team.Murderer; --murderersNeeded; } - else if (detectivesNeeded > 0) + else if ( detectivesNeeded > 0 ) { pawn.Team = Team.Detective; --detectivesNeeded; @@ -119,6 +122,7 @@ public partial class AssignPhase : BasePhase { pawn.Team = Team.Bystander; } + Log.Info( "Assigning " + client.Name + " to team " + pawn.GetTeamName() ); // position pawn @@ -127,26 +131,27 @@ public partial class AssignPhase : BasePhase var tx = spawnPoint.Transform; tx.Position += Vector3.Up * 10.0f; pawn.Transform = tx; - + // assign nato name var natoName = natoNamesRemaining[0]; natoNamesRemaining.RemoveAt( 0 ); pawn.CharacterName = natoName; - + // assign nato name var hexColor = colorsRemaining[0]; colorsRemaining.RemoveAt( 0 ); - pawn.Color = Color.FromRgb(hexColor); + pawn.Color = Color.FromRgb( hexColor ); RoleOverlay.Show( To.Single( client ) ); } - base.TimeLeft = 5; + + TimeLeft = 5; } [ClientRpc] public static void DeleteFootprints() { - foreach (var entity in Entity.All.OfType()) + foreach ( var entity in Entity.All.OfType() ) { entity.Delete(); } @@ -154,7 +159,7 @@ public partial class AssignPhase : BasePhase public override void Deactivate() { - foreach (var client in Game.Clients) + foreach ( var client in Game.Clients ) { RoleOverlay.Hide( To.Single( client ) ); } @@ -163,7 +168,7 @@ public partial class AssignPhase : BasePhase public override void Tick() { ++TicksElapsed; - if ( TimeLeft == -1 || TicksElapsed % Game.TickRate != 0 || --base.TimeLeft != 0 ) + if ( TimeLeft == -1 || TicksElapsed % Game.TickRate != 0 || --TimeLeft != 0 ) { return; } @@ -171,5 +176,4 @@ public partial class AssignPhase : BasePhase IsFinished = true; NextPhase = new PlayPhase(); } - } -- cgit v1.2.3-70-g09d2