Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SSS system to use CVars instead of datafield #35

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.CVars.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Content.Shared.CCVar;

namespace Content.Server._SSS.SuspicionGameRule;

public sealed partial class SuspicionRuleSystem
{
private void InitializeCVars()
{
Subs.CVar(_cfg, CCVars.SSSTraitorPercentage, f => _traitorPercentage = f, true);
Subs.CVar(_cfg, CCVars.SSSDetectivePercentage, f => _detectivePercentage = f, true);
Subs.CVar(_cfg, CCVars.SSSPreparingDuration, i => _preparingDuration = i, true);
Subs.CVar(_cfg, CCVars.SSSRoundDuration, i => _roundDuration = i, true);
Subs.CVar(_cfg, CCVars.SSSTimeAddedPerKill, i => _timeAddedPerKill = i, true);
Subs.CVar(_cfg, CCVars.SSSPostRoundDuration, i => _postRoundDuration = i, true);
}

private float _traitorPercentage = 0.25f;
private float _detectivePercentage = 0.25f;
private int _preparingDuration = 30;
private int _roundDuration = 480;
private int _timeAddedPerKill = 30;
private int _postRoundDuration = 30;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void OnMobStateChanged(EntityUid uid, SuspicionPlayerComponent component
if (sus.GameState != SuspicionGameState.InProgress)
break;

sus.EndAt += TimeSpan.FromSeconds(sus.TimeAddedPerKill);
sus.EndAt += TimeSpan.FromSeconds(_timeAddedPerKill);
sus.AnnouncedTimeLeft.Clear();

RaiseNetworkEvent(new SuspicionRuleTimerUpdate(_gameTicker.RoundDuration() + sus.EndAt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void OnGetBriefing(Entity<SuspicionRoleComponent> role, ref GetBriefingE
private void StartRound(EntityUid uid, SuspicionRuleComponent component, GameRuleComponent gameRule)
{
component.GameState = SuspicionGameState.InProgress;
component.EndAt = TimeSpan.FromSeconds(component.RoundDuration);
component.EndAt = TimeSpan.FromSeconds(_roundDuration);

var allPlayerData = _playerManager.GetAllPlayerData().ToList();
var participatingPlayers = new List<(EntityUid mind, SuspicionRoleComponent comp)>();
Expand Down Expand Up @@ -79,8 +79,8 @@ private void StartRound(EntityUid uid, SuspicionRuleComponent component, GameRul
_rejuvenate.PerformRejuvenate(ent.Value);
}

var traitorCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.TraitorPercentage), 1, allPlayerData.Count);
var detectiveCount = MathHelper.Clamp((int) (participatingPlayers.Count * component.DetectivePercentage), 1, allPlayerData.Count);
var traitorCount = MathHelper.Clamp((int) (participatingPlayers.Count * _traitorPercentage), 1, allPlayerData.Count);
var detectiveCount = MathHelper.Clamp((int) (participatingPlayers.Count * _detectivePercentage), 1, allPlayerData.Count);

if (traitorCount + detectiveCount > participatingPlayers.Count)
{
Expand Down Expand Up @@ -222,7 +222,7 @@ private void OnBeforeSpawn(PlayerBeforeSpawnEvent ev)
RaiseNetworkEvent(new SuspicionRulePlayerSpawn()
{
GameState = SuspicionGameState.Preparing,
EndTime = TimeSpan.FromSeconds(sus.PreparingDuration),
EndTime = TimeSpan.FromSeconds(_preparingDuration),
}, ev.Player);

var newMind = _mindSystem.CreateMind(ev.Player.UserId, ev.Profile.Name);
Expand Down
10 changes: 7 additions & 3 deletions Content.Server/_SSS/SuspicionGameRule/SuspicionRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
Expand Down Expand Up @@ -63,6 +64,7 @@ public sealed partial class SuspicionRuleSystem : GameRuleSystem<SuspicionRuleCo
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;

private readonly SoundSpecifier _traitorStartSound = new SoundPathSpecifier("/Audio/Ambience/Antag/traitor_start.ogg");

Expand All @@ -71,6 +73,8 @@ public override void Initialize()
{
base.Initialize();

InitializeCVars();

SubscribeLocalEvent<PlayerBeforeSpawnEvent>(OnBeforeSpawn);
SubscribeLocalEvent<SuspicionRoleComponent, GetBriefingEvent>(OnGetBriefing);
SubscribeLocalEvent<SuspicionPlayerComponent, ExaminedEvent>(OnExamine);
Expand Down Expand Up @@ -129,11 +133,11 @@ protected override void Started(EntityUid uid, SuspicionRuleComponent component,

component.GameState = SuspicionGameState.Preparing;

Timer.Spawn(TimeSpan.FromSeconds(component.PreparingDuration - 5), () => _chatManager.DispatchServerAnnouncement("The round will start in 5 seconds."));
Timer.Spawn(TimeSpan.FromSeconds(component.PreparingDuration), () => StartRound(uid, component, gameRule));
Timer.Spawn(TimeSpan.FromSeconds(_preparingDuration - 5), () => _chatManager.DispatchServerAnnouncement("The round will start in 5 seconds."));
Timer.Spawn(TimeSpan.FromSeconds(_preparingDuration), () => StartRound(uid, component, gameRule));
Log.Debug("Starting a game of Suspicion.");

RaiseNetworkEvent(new SuspicionRulePreroundStarted(TimeSpan.FromSeconds(component.PreparingDuration)));
RaiseNetworkEvent(new SuspicionRulePreroundStarted(TimeSpan.FromSeconds(_preparingDuration)));
}

public override void Update(float frameTime)
Expand Down
39 changes: 38 additions & 1 deletion Content.Shared/_SSS/CCvar/CCVars.SSS.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
using Robust.Shared.Configuration;
// ReSharper disable InconsistentNaming rawr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FUCK YOU!!!!!!!!!!!!!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow


namespace Content.Shared.CCVar;

public sealed partial class CCVars
{
//NONE???
/// <summary>
/// Percentage of total players that will be a traitor.
/// The number of players will be multiplied by this number, and then rounded down.
/// If the result is less than 1 or more than the player count, it is clamped to those values.
/// </summary>
public static readonly CVarDef<float> SSSTraitorPercentage =
CVarDef.Create("sss.traitor_percentage", 0.25f, CVar.SERVERONLY);

/// <summary>
/// Percentage of total players that will be a detective (detective innocent). Handled similar to traitor percentage (rounded down etc).
/// </summary>
public static readonly CVarDef<float> SSSDetectivePercentage =
CVarDef.Create("sss.detective_percentage", 0.25f, CVar.SERVERONLY);

/// <summary>
/// How long to wait before the game starts after the round starts.
/// </summary>
public static readonly CVarDef<int> SSSPreparingDuration =
CVarDef.Create("sss.preparing_duration", 30, CVar.SERVERONLY);

/// <summary>
/// How long the round lasts in seconds.
/// </summary>
public static readonly CVarDef<int> SSSRoundDuration =
CVarDef.Create("sss.round_duration", 480, CVar.SERVERONLY);

/// <summary>
/// How long to add to the round time when a player is killed.
/// </summary>
public static readonly CVarDef<int> SSSTimeAddedPerKill =
CVarDef.Create("sss.time_added_per_kill", 30, CVar.SERVERONLY);

/// <summary>
/// How long to wait before restarting the round after the summary is displayed.
/// </summary>
public static readonly CVarDef<int> SSSPostRoundDuration =
CVarDef.Create("sss.post_round_duration", 30, CVar.SERVERONLY);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,7 @@ public sealed partial class SuspicionRuleComponent : Component

#endregion

/// <summary>
/// Percentage of total players that will be a traitor.
/// The number of players will be multiplied by this number, and then rounded down.
/// If the result is less than 1 or more than the player count, it is clamped to those values.
/// </summary>
[DataField]
public float TraitorPercentage = 0.25f;

/// <summary>
/// Percentage of total players that will be a detective (detective innocent). Handled similar to traitor percentage (rounded down etc).
/// </summary>
[DataField]
public float DetectivePercentage = 0.20f;

/// <summary>
/// How long to wait before the game starts after the round starts.
/// </summary>
[DataField]
public int PreparingDuration = 30;

/// <summary>
/// How long the round lasts in seconds.
/// </summary>
[DataField]
public int RoundDuration = 480;

/// <summary>
/// How long to add to the round time when a player is killed.
/// </summary>
[DataField]
public int TimeAddedPerKill = 30;

/// <summary>
/// How long to wait before restarting the round after the summary is displayed.
/// </summary>
[DataField]
public int PostRoundDuration = 30;

Expand Down
Loading