aboutsummaryrefslogtreecommitdiffstats
path: root/code/Game.cs
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-07-27 22:11:31 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-07-27 22:11:31 +0100
commit71db52c5443a7bf82d9a23a770994a42b043be04 (patch)
treef75f2605bb1bdc53842cd85c90d105dcc77e1c10 /code/Game.cs
Initial commit
Diffstat (limited to 'code/Game.cs')
-rw-r--r--code/Game.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/code/Game.cs b/code/Game.cs
new file mode 100644
index 0000000..e603fda
--- /dev/null
+++ b/code/Game.cs
@@ -0,0 +1,75 @@
+
+using Sandbox;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace MurderGame;
+
+public partial class MurderGame : Sandbox.GameManager
+{
+ public MurderGame()
+ {
+ if ( Game.IsClient )
+ {
+ Game.RootPanel = new Hud();
+ }
+ // if ( Game.IsServer )
+ // {
+ // // The packageName should always match org.ident
+ // // In this case, we ask to download gvar.citizen_zombie -> https://asset.party/gvar/citizen_zombie
+ // DownloadAsset( "gvar.citizen_zombie" );
+ // }
+ }
+
+ public static MurderGame Instance
+ {
+ get => Current as MurderGame;
+ }
+
+
+ [ConVar.Server( "mm_min_players", Help = "The minimum number of players required to start a round." )]
+ public static int MinPlayers { get; set; } = 2;
+
+ [ConVar.Server( "mm_allow_suicide", Help = "Allow players to kill themselves during a round." )]
+ public static bool AllowSuicide { get; set; } = true;
+
+ [ConVar.Server( "mm_round_time", Help = "The amount of time in a round." )]
+ public static int RoundTime { get; set; } = 600;
+
+ [Net]
+ public BasePhase CurrentPhase { get; set; } = new WaitPhase() { CountIn = true };
+
+ [GameEvent.Tick.Server]
+ public void TickServer()
+ {
+ CurrentPhase.Tick();
+
+ if (CurrentPhase.NextPhase != null && CurrentPhase.IsFinished)
+ {
+ CurrentPhase.Deactivate();
+ CurrentPhase = CurrentPhase.NextPhase;
+ Log.Info("Advancing phase to " + CurrentPhase.ToString());
+ CurrentPhase.Activate();
+ }
+ }
+
+ public override void ClientJoined( IClient client )
+ {
+ base.ClientJoined( client );
+
+ // Create a pawn for this client to play with
+ var pawn = new Player();
+ client.Pawn = pawn;
+
+ var spawnpoints = Entity.All.OfType<SpawnPoint>();
+ var randomSpawnPoint = spawnpoints.OrderBy( x => Guid.NewGuid() ).FirstOrDefault();
+ if ( randomSpawnPoint != null )
+ {
+ var tx = randomSpawnPoint.Transform;
+ tx.Position = tx.Position + Vector3.Up * 50.0f;
+ pawn.Transform = tx;
+ }
+ }
+}
+