Skip to content

Commit

Permalink
[Port]Game presets can now have cooldowns to prevent back-to-back mod…
Browse files Browse the repository at this point in the history
…es (#2744)

* nukeblops

* Update game_presets.yml

i hate whitespace

Signed-off-by: Lyndomen <[email protected]>

* Update GamePresetPrototype.cs

Signed-off-by: Lyndomen <[email protected]>

* Update game_presets.yml

Signed-off-by: Lyndomen <[email protected]>

* Update game_presets.yml

Signed-off-by: Lyndomen <[email protected]>

* Update game_presets.yml

Signed-off-by: Lyndomen <[email protected]>

* cvar making

* untroll

---------

Signed-off-by: Lyndomen <[email protected]>
  • Loading branch information
Lyndomen authored Jan 19, 2025
1 parent 8e75752 commit 6cf83b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
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
24 changes: 24 additions & 0 deletions 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; // DeltaV
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,6 +52,15 @@ 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.");

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)
{
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

0 comments on commit 6cf83b3

Please sign in to comment.