aboutsummaryrefslogtreecommitdiffstats
path: root/code/phase
diff options
context:
space:
mode:
Diffstat (limited to 'code/phase')
-rw-r--r--code/phase/AssignPhase.cs100
-rw-r--r--code/phase/BasePhase.cs14
-rw-r--r--code/phase/EndPhase.cs12
-rw-r--r--code/phase/PlayPhase.cs85
-rw-r--r--code/phase/WaitPhase.cs37
5 files changed, 128 insertions, 120 deletions
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<string> NatoNames = new()
+ private readonly List<uint> 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<string> NatoNames = new()
+ {
+ "Alpha",
+ "Bravo",
"Charlie",
"Delta",
"Echo",
@@ -40,77 +51,69 @@ public partial class AssignPhase : BasePhase
"Yankee",
"Zulu"
};
-
- private List<uint> 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<DroppedWeapon>())
+ foreach ( var entity in Entity.All.OfType<DroppedWeapon>() )
{
entity.Delete();
}
+
DeleteFootprints();
// cleanup -- end
var detectivesNeeded = 1;
var murderersNeeded = 1;
-
+
Random random = new(Guid.NewGuid().GetHashCode());
-
+
var spawnPoints = Entity.All.OfType<SpawnPoint>().OrderBy( _ => random.Next() ).ToList();
var clients = Game.Clients.ToList().OrderBy( _ => random.Next() );
- var natoNamesRemaining = new List<string>(NatoNames.OrderBy( _ => random.Next() ));
- var colorsRemaining = new List<uint>(Colors.OrderBy( _ => random.Next() ));
+ var natoNamesRemaining = new List<string>( NatoNames.OrderBy( _ => random.Next() ) );
+ var colorsRemaining = new List<uint>( 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<string>(NatoNames);
+ natoNamesRemaining = new List<string>( NatoNames );
}
- if (colorsRemaining.Count == 0)
+
+ if ( colorsRemaining.Count == 0 )
{
- colorsRemaining = new List<uint>(Colors);
+ colorsRemaining = new List<uint>( 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<Footprint>())
+ foreach ( var entity in Entity.All.OfType<Footprint>() )
{
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();
}
-
}
diff --git a/code/phase/BasePhase.cs b/code/phase/BasePhase.cs
index 8f3d044..2ce7955 100644
--- a/code/phase/BasePhase.cs
+++ b/code/phase/BasePhase.cs
@@ -1,9 +1,4 @@
using Sandbox;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace MurderGame;
@@ -11,11 +6,10 @@ public abstract partial class BasePhase : BaseNetworkable
{
public virtual string Title => "Name";
- [Net]
- public int TimeLeft { get; set; } = -1;
+ [Net] public int TimeLeft { get; set; } = -1;
+
+ public BasePhase NextPhase { get; set; }
- public BasePhase NextPhase { get; set;}
-
public bool IsFinished { get; set; }
public abstract void Tick();
@@ -24,5 +18,5 @@ public abstract partial class BasePhase : BaseNetworkable
public virtual void Deactivate() { }
- public virtual void HandleClientJoin(ClientJoinedEvent e) { }
+ public virtual void HandleClientJoin( ClientJoinedEvent e ) { }
}
diff --git a/code/phase/EndPhase.cs b/code/phase/EndPhase.cs
index 904dc81..ada988d 100644
--- a/code/phase/EndPhase.cs
+++ b/code/phase/EndPhase.cs
@@ -1,26 +1,24 @@
using Sandbox;
-using System.Linq;
namespace MurderGame;
public class EndPhase : BasePhase
{
- public override string Title => "Game over";
public int TicksElapsed;
+ public override string Title => "Game over";
public override void Activate()
{
- base.TimeLeft = 7;
+ TimeLeft = 7;
}
public override void Tick()
{
++TicksElapsed;
- if (base.TimeLeft != -1 && TicksElapsed % Game.TickRate == 0 && --base.TimeLeft == 0)
+ if ( TimeLeft != -1 && TicksElapsed % Game.TickRate == 0 && --TimeLeft == 0 )
{
- base.NextPhase = new WaitPhase() { CountIn = false };
- base.IsFinished = true;
- return;
+ NextPhase = new WaitPhase { CountIn = false };
+ IsFinished = true;
}
}
}
diff --git a/code/phase/PlayPhase.cs b/code/phase/PlayPhase.cs
index 682cfe7..895c305 100644
--- a/code/phase/PlayPhase.cs
+++ b/code/phase/PlayPhase.cs
@@ -1,23 +1,21 @@
-using Sandbox;
-using Sandbox.UI;
-using System;
-using System.Buffers;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
+using Sandbox;
+using Sandbox.UI;
namespace MurderGame;
public class PlayPhase : BasePhase
{
- public override string Title => "Play";
public IDictionary<Entity, int> Blinded = new Dictionary<Entity, int>();
public int TicksElapsed;
+ public override string Title => "Play";
private string MurdererNames { get; set; }
public override void Activate()
{
- base.TimeLeft = MurderGame.RoundTime;
- Event.Register(this);
+ TimeLeft = MurderGame.RoundTime;
+ Event.Register( this );
foreach ( var client in Game.Clients )
{
if ( client.Pawn is not Player pawn || pawn.Team == Team.Spectator )
@@ -28,21 +26,24 @@ public class PlayPhase : BasePhase
pawn.Respawn();
TeamCapabilities.GiveLoadouts( pawn );
}
- MurdererNames = string.Join( ',', Game.Clients.Where( c => ((Player)c.Pawn).Team == Team.Murderer ).Select(c => c.Name));
+
+ MurdererNames = string.Join( ',',
+ Game.Clients.Where( c => ((Player)c.Pawn).Team == Team.Murderer ).Select( c => c.Name ) );
}
public override void Deactivate()
{
- base.TimeLeft = MurderGame.RoundTime;
- Event.Unregister(this);
- foreach(var item in Blinded)
+ TimeLeft = MurderGame.RoundTime;
+ Event.Unregister( this );
+ foreach ( var item in Blinded )
{
ClearDebuffs( item.Key );
}
+
Blinded.Clear();
}
- public void ClearDebuffs(Entity entity )
+ public void ClearDebuffs( Entity entity )
{
Log.Info( "Removing blind from " + entity.Name );
BlindedOverlay.Hide( To.Single( entity ) );
@@ -52,30 +53,38 @@ public class PlayPhase : BasePhase
return;
}
- if (pawn.Controller is WalkControllerComponent controller) controller.SpeedMultiplier = 1;
- if (pawn.Inventory!= null) pawn.Inventory.AllowPickup = true;
+ if ( pawn.Controller is WalkControllerComponent controller )
+ {
+ controller.SpeedMultiplier = 1;
+ }
+ if ( pawn.Inventory != null )
+ {
+ pawn.Inventory.AllowPickup = true;
+ }
}
public override void Tick()
{
++TicksElapsed;
- if (base.TimeLeft != -1 && TicksElapsed % Game.TickRate == 0 && --base.TimeLeft == 0)
+ if ( TimeLeft != -1 && TicksElapsed % Game.TickRate == 0 && --TimeLeft == 0 )
{
TriggerEndOfGame();
return;
}
- var bystandersAlive = Game.Clients.Any(c =>((Player)c.Pawn).Team == Team.Bystander || ((Player)c.Pawn).Team == Team.Detective);
- var murderersAlive = Game.Clients.Any(c =>((Player)c.Pawn).Team == Team.Murderer);
- if (!bystandersAlive || !murderersAlive)
+
+ var bystandersAlive = Game.Clients.Any( c =>
+ ((Player)c.Pawn).Team == Team.Bystander || ((Player)c.Pawn).Team == Team.Detective );
+ var murderersAlive = Game.Clients.Any( c => ((Player)c.Pawn).Team == Team.Murderer );
+ if ( !bystandersAlive || !murderersAlive )
{
TriggerEndOfGame();
}
- foreach(var item in Blinded)
+ foreach ( var item in Blinded )
{
var blindLeft = item.Value - 1;
- if (blindLeft < 0)
+ if ( blindLeft < 0 )
{
Blinded.Remove( item.Key );
ClearDebuffs( item.Key );
@@ -90,24 +99,25 @@ public class PlayPhase : BasePhase
public void TriggerEndOfGame()
{
- var bystandersWin = Game.Clients.Any(c =>((Player)c.Pawn).Team is Team.Bystander or Team.Detective);
- ChatBox.Say( (bystandersWin ? "Bystanders" : "Murderers") +" win! The murderers were: " + MurdererNames );
- base.NextPhase = new EndPhase();
- base.IsFinished = true;
+ var bystandersWin = Game.Clients.Any( c => ((Player)c.Pawn).Team is Team.Bystander or Team.Detective );
+ ChatBox.Say( (bystandersWin ? "Bystanders" : "Murderers") + " win! The murderers were: " + MurdererNames );
+ NextPhase = new EndPhase();
+ IsFinished = true;
}
[MurderEvent.Kill]
- public void OnKill(Entity killer, Entity victim)
+ public void OnKill( Entity killer, Entity victim )
{
- if (killer is not Player && victim is not Player )
+ if ( killer is not Player && victim is not Player )
{
return;
}
+
var victimPlayer = (Player)victim;
var victimTeam = victimPlayer.Team;
victimPlayer.Team = Team.Spectator;
- if (killer == null)
+ if ( killer == null )
{
Log.Info( victimPlayer + " died mysteriously" );
return;
@@ -118,28 +128,31 @@ public class PlayPhase : BasePhase
Log.Info( victimPlayer + " died to " + killerPlayer );
- if (victimTeam != Team.Murderer && killerTeam != Team.Murderer)
+ if ( victimTeam != Team.Murderer && killerTeam != Team.Murderer )
{
- Log.Info( killerPlayer + " shot a bystander");
+ Log.Info( killerPlayer + " shot a bystander" );
ChatBox.Say( killerPlayer.Client.Name + " killed an innocent bystander" );
BlindedOverlay.Show( To.Single( killer ) );
- if (killerPlayer.Controller is WalkControllerComponent controller) controller.SpeedMultiplier = 0.3f;
- if (killerPlayer.Inventory != null)
+ if ( killerPlayer.Controller is WalkControllerComponent controller )
+ {
+ controller.SpeedMultiplier = 0.3f;
+ }
+
+ if ( killerPlayer.Inventory != null )
{
killerPlayer.Inventory.AllowPickup = false;
- killerPlayer.Inventory.SpillContents(killerPlayer.EyePosition, killerPlayer.AimRay.Forward);
+ killerPlayer.Inventory.SpillContents( killerPlayer.EyePosition, killerPlayer.AimRay.Forward );
}
Blinded[killer] = 30 * Game.TickRate;
}
- else if (victimTeam == Team.Murderer )
+ else if ( victimTeam == Team.Murderer )
{
- Log.Info( killerPlayer + " killed a murderer");
+ Log.Info( killerPlayer + " killed a murderer" );
ChatBox.Say( killerPlayer.Client.Name + " killed a murderer" );
}
}
-
}
diff --git a/code/phase/WaitPhase.cs b/code/phase/WaitPhase.cs
index e52c91c..c284e10 100644
--- a/code/phase/WaitPhase.cs
+++ b/code/phase/WaitPhase.cs
@@ -1,9 +1,6 @@
-using Sandbox;
-using System;
-using System.Collections.Generic;
+using System;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using Sandbox;
namespace MurderGame;
@@ -17,28 +14,30 @@ public class WaitPhase : BasePhase
public override void Tick()
{
- if (Game.Clients.Count >= MurderGame.MinPlayers)
+ if ( Game.Clients.Count >= MurderGame.MinPlayers )
{
- if (!CountIn || (_isCountDown && ++TicksElapsed % Game.TickRate == 0 && --base.TimeLeft == 0))
+ if ( !CountIn || (_isCountDown && ++TicksElapsed % Game.TickRate == 0 && --TimeLeft == 0) )
{
- base.NextPhase = new AssignPhase();
- base.IsFinished = true;
+ NextPhase = new AssignPhase();
+ IsFinished = true;
return;
}
- else if (CountIn && !_isCountDown)
+
+ if ( CountIn && !_isCountDown )
{
_isCountDown = true;
- base.TimeLeft = 10;
+ TimeLeft = 10;
}
- } else if (CountIn && _isCountDown)
+ }
+ else if ( CountIn && _isCountDown )
{
_isCountDown = false;
- base.TimeLeft = -1;
+ TimeLeft = -1;
}
- foreach (var client in Game.Clients)
+ foreach ( var client in Game.Clients )
{
- if (client.Pawn == null)
+ if ( client.Pawn == null )
{
var pawn = new Player();
client.Pawn = pawn;
@@ -54,10 +53,11 @@ public class WaitPhase : BasePhase
pawn.Spawn();
RespawnPlayer( pawn );
- } else
+ }
+ else
{
var pawn = (Player)client.Pawn;
- if (pawn.LifeState == LifeState.Dead && pawn.TimeSinceDeath > 5)
+ if ( pawn.LifeState == LifeState.Dead && pawn.TimeSinceDeath > 5 )
{
RespawnPlayer( pawn );
}
@@ -65,7 +65,7 @@ public class WaitPhase : BasePhase
}
}
- private void RespawnPlayer(Player pawn)
+ private void RespawnPlayer( Player pawn )
{
pawn.Team = Team.Spectator;
pawn.DressFromClient( pawn.Client );
@@ -74,6 +74,5 @@ public class WaitPhase : BasePhase
public override void HandleClientJoin( ClientJoinedEvent e )
{
-
}
}