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

[Port]Game presets can now have cooldowns to prevent back-to-back modes #2744

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions Content.Server/GameTicking/Presets/GamePresetPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public sealed partial class GamePresetPrototype : IPrototype
[DataField("maxPlayers")]
public int? MaxPlayers;

// Begin Imp
/// <summary>
/// Ensures that this gamemode does not get selected for a number of rounds
/// by something like Secret. This is not considered when the preset is forced.
/// </summary>
[DataField]
public int Cooldown = 0;
// End Imp

[DataField("rules", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
public IReadOnlyList<string> Rules { get; private set; } = Array.Empty<string>();

Expand Down
26 changes: 25 additions & 1 deletion Content.Server/GameTicking/Rules/SecretRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.Chat.Managers;
using Content.Server.GameTicking.Presets;
using Content.Server.GameTicking.Rules.Components;
using Content.Shared._DV.CCVars;
Copy link
Member

Choose a reason for hiding this comment

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

comment

using Content.Shared.GameTicking.Components;
using Content.Shared.Random;
using Content.Shared.CCVar;
Expand All @@ -22,6 +23,11 @@ public sealed class SecretRuleSystem : GameRuleSystem<SecretRuleComponent>
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IComponentFactory _compFact = default!;
[Dependency] private readonly GameTicker _ticker = default!; // begin Imp

// Dictionary that contains the minimum round number for certain preset
// prototypes to be allowed to roll again
private static Dictionary<ProtoId<GamePresetPrototype>, int> _nextRoundAllowed = new(); // end Imp

private string _ruleCompName = default!;

Expand All @@ -46,7 +52,16 @@ protected override void Added(EntityUid uid, SecretRuleComponent component, Game
Log.Info($"Selected {preset.ID} as the secret preset.");
_adminLogger.Add(LogType.EventStarted, $"Selected {preset.ID} as the secret preset.");

foreach (var rule in preset.Rules)
if (_configurationManager.GetCVar(DCCVars.EnableBacktoBack) == true) // DeltaV
{
if (preset.Cooldown > 0) // Begin Imp
{
_nextRoundAllowed[preset.ID] = _ticker.RoundId + preset.Cooldown + 1;
Log.Info($"{preset.ID} is now on cooldown until {_nextRoundAllowed[preset.ID]}");
} // End Imp
} // DeltaV

foreach (var rule in preset.Rules)
Copy link
Member

Choose a reason for hiding this comment

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

untroll

{
EntityUid ruleEnt;

Expand Down Expand Up @@ -167,6 +182,15 @@ private bool CanPick([NotNullWhen(true)] GamePresetPrototype? selected, int play
return false;
}

if (_configurationManager.GetCVar(DCCVars.EnableBacktoBack) == true) // DeltaV
{
if (_nextRoundAllowed.ContainsKey(selected.ID) && _nextRoundAllowed[selected.ID] > _ticker.RoundId) // Begin Imp
{
Log.Info($"Skipping preset {selected.ID} (Not available until round {_nextRoundAllowed[selected.ID]}");
return false;
} // End Imp
} // DeltaV

return true;
}
}
6 changes: 6 additions & 0 deletions Content.Shared/_DV/CCVars/DCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,10 @@ public sealed class DCCVars
/// </summary>
public static readonly CVarDef<string> DiscordReplyColor =
CVarDef.Create("admin.discord_reply_color", string.Empty, CVar.SERVERONLY);

/// <summary>
/// Whether or not to disable the preset selecting test rule from running. Should be disabled in production. DeltaV specific, attached to Impstation Secret concurrent feature.
/// </summary>
public static readonly CVarDef<bool> EnableBacktoBack =
CVarDef.Create("game.disable_preset_test", false, CVar.SERVERONLY);
}
4 changes: 4 additions & 0 deletions Resources/Prototypes/game_presets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
name: survival-title
showInVote: true # secret # DeltaV - Me when the survival. Used for periapsis.
description: survival-description
cooldown: 2 # Imp - Can't occur thrice
rules:
- MeteorSwarmScheduler
- RampingStationEventScheduler
Expand Down Expand Up @@ -155,6 +156,7 @@
- tator
name: traitor-title
description: traitor-description
cooldown: 2 # Imp - Can't occur thrice
showInVote: false
rules:
- Traitor
Expand Down Expand Up @@ -185,6 +187,7 @@
name: nukeops-title
description: nukeops-description
showInVote: false
cooldown: 2 # Imp - Can't occur thrice
rules:
- Nukeops
- SubGamemodesRule
Expand Down Expand Up @@ -222,6 +225,7 @@
- zomber
name: zombie-title
description: zombie-description
cooldown: 2 # Imp - Can't occur thrice
showInVote: false
rules:
- Zombie
Expand Down
Loading