More russian roulette setup

This commit is contained in:
gamer147
2023-08-02 20:52:13 -04:00
parent 285a130a81
commit 0d6df93904
10 changed files with 93 additions and 17 deletions

View File

@@ -46,4 +46,13 @@ public partial class MinigameManager : Entity
{
FindMinigames();
}
public void Tick()
{
if ( LoadedMinigame is not { IsValid: true } )
{
return;
}
LoadedMinigame.Tick();
}
}

View File

@@ -73,6 +73,11 @@ public partial class RoundManager : Entity
Log.Info( "Starting round" );
StartRound();
}
if ( RoundState == RoundState.InProgress )
{
MinigameManager.Tick();
}
}
/// <summary>
@@ -117,4 +122,10 @@ public partial class RoundManager : Entity
Players = All.OfType<Lucker>().ToList();
MinigameManager.StartRandomMinigame( Players );
}
[ConCmd.Server("start_round")]
public static void ForceStart()
{
Entity.All.OfType<RoundManager>().FirstOrDefault()?.StartRound();
}
}

View File

@@ -3,8 +3,9 @@ using Sandbox;
namespace LuckerGame.Components.Lucker.Cameras;
public abstract class AbstractCamera : EntityComponent<Entities.Lucker>
public abstract class AbstractCamera : EntityComponent<Entities.Lucker>, ISingletonComponent
{
public virtual bool ShouldShowCursor => false;
protected Vector3 CameraPosition { get; set; }
protected Rotation CameraRotation { get; set; }
protected float FieldOfView { get; set; }

View File

@@ -9,6 +9,7 @@ namespace LuckerGame.Components.Lucker.Cameras;
/// </summary>
public partial class RTSCamera : AbstractCamera, ISingletonComponent
{
public override bool ShouldShowCursor => true;
private const float MaxDistance = 400f;
private const float MinDistance = 200f;
private const float Speed = 4f;

View File

@@ -7,13 +7,22 @@ namespace LuckerGame.Minigames;
public abstract class Minigame : Entity
{
public abstract string Name { get; }
/// <summary>
/// Initializes the minigame with a list of luckers playing it
/// The name of this minigame
/// </summary>
public abstract string Name { get; }
/// <summary>
/// Initializes the minigame with a list of luckers playing it.
/// </summary>
/// <param name="players">the players who made it into the minigame</param>
public abstract void Initialize(List<Lucker> players);
/// <summary>
/// Once a minigame is loaded and initialized, this method is called once per server tick.
/// </summary>
public abstract void Tick();
/// <summary>
/// Cleans up any entities and components created by this minigame.
/// It is not necessary to remove the lucker's pawns, the manager will do so if any were assigned.

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LuckerGame.Components.Lucker.Cameras;
using LuckerGame.Entities;
using Sandbox;
@@ -9,28 +10,51 @@ namespace LuckerGame.Minigames.RussianRoulette;
public class RussianRouletteMinigame : Minigame
{
public override string Name => "Russian Roulette";
private List<Lucker> Players { get; set; }
private Pawn Shooter { get; set; }
private const float ShooterDistance = 50f;
private const int CardinalDirections = 4;
public override void Initialize( List<Lucker> players )
{
var pawn = new Pawn();
Players = players;
Shooter = new Pawn();
// Get all of the spawnpoints
/*// Spawn shooter at a random spawnpoint
var spawnpoints = Entity.All.OfType<SpawnPoint>();
// chose a random one
var randomSpawnPoint = spawnpoints.OrderBy( x => Guid.NewGuid() ).FirstOrDefault();
// if it exists, place the pawn there
if ( randomSpawnPoint != null )
{
var tx = randomSpawnPoint.Transform;
tx.Position = tx.Position + Vector3.Up * 50.0f; // raise it up
pawn.Position = tx.Position;
Shooter.Position = tx.Position;*/
// Setup cameras for players
Players.ForEach( player =>
{
player.Components.Create<RTSCamera>();
player.Position = Shooter.Position;
} );
Players.Select((player, i) => (Player: player, Index: i) ).ToList().ForEach( pair =>
{
var player = pair.Player;
var index = pair.Index;
var pawn = new Pawn();
player.Pawn = pawn;
pawn.DressFromClient( player.Client );
var pawnOffset = ShooterDistance * (index % 2 == 0 ? Vector3.Forward : Vector3.Right) * (index % 4 >= 2 ? -1 : 1);
player.Pawn.Position = Shooter.Position + pawnOffset;
} );
}
public override void Tick()
{
return;
}
public override void Cleanup()
{
throw new System.NotImplementedException();
Shooter?.Delete();
}
}

View File

@@ -12,8 +12,7 @@
<VoiceList/>
<VotingLobby/>
<Scoreboard/>
<div class="pointer-visible" />
<CameraCursor/>
</root>

View File

@@ -0,0 +1,16 @@
@using LuckerGame.Components.Lucker.Cameras
@using Sandbox
@using Sandbox.UI
@namespace LuckerGame.UI.HudComponents
@attribute [StyleSheet]
@inherits Panel
@if (ShouldShowCursor)
{
<root/>
}
@code {
private bool ShouldShowCursor => Game.LocalClient.Pawn?.Components.Get<AbstractCamera>()?.ShouldShowCursor ?? false;
}

View File

@@ -0,0 +1,3 @@
CameraCursor {
pointer-events: all;
}

View File

@@ -1,3 +1,6 @@
Scoreboard {
z-index: 0;
.scoreboard-panel {
flex-direction: column;
}
}