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 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions Content.Server/GameTicking/Rules/SecretRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 +51,12 @@ 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 (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

foreach (var rule in preset.Rules)
{
EntityUid ruleEnt;
Expand Down Expand Up @@ -166,6 +177,11 @@ private bool CanPick([NotNullWhen(true)] GamePresetPrototype? selected, int play
if (ruleComp.MinPlayers > players && ruleComp.CancelPresetOnTooFewPlayers)
return false;
}
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

return true;
}
Expand Down
3 changes: 3 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 @@ -185,6 +186,7 @@
name: nukeops-title
description: nukeops-description
showInVote: false
cooldown: 1 # Imp - Can't occur back to back
rules:
- Nukeops
- SubGamemodesRule
Expand Down Expand Up @@ -222,6 +224,7 @@
- zomber
name: zombie-title
description: zombie-description
cooldown: 2 # Imp - Can't occur thrice
showInVote: false
rules:
- Zombie
Expand Down
Loading