Secret! (#8276)
Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
using Content.Server.GameTicking.Presets;
|
using Content.Server.GameTicking.Presets;
|
||||||
using Content.Server.GameTicking.Rules;
|
using Content.Server.GameTicking.Rules;
|
||||||
using Content.Server.Ghost.Components;
|
using Content.Server.Ghost.Components;
|
||||||
@@ -14,7 +15,7 @@ namespace Content.Server.GameTicking
|
|||||||
{
|
{
|
||||||
public const float PresetFailedCooldownIncrease = 30f;
|
public const float PresetFailedCooldownIncrease = 30f;
|
||||||
|
|
||||||
private GamePresetPrototype? _preset;
|
public GamePresetPrototype? Preset { get; private set; }
|
||||||
|
|
||||||
private bool StartPreset(IPlayerSession[] origReadyPlayers, bool force)
|
private bool StartPreset(IPlayerSession[] origReadyPlayers, bool force)
|
||||||
{
|
{
|
||||||
@@ -24,7 +25,7 @@ namespace Content.Server.GameTicking
|
|||||||
if (!startAttempt.Cancelled)
|
if (!startAttempt.Cancelled)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var presetTitle = _preset != null ? Loc.GetString(_preset.ModeTitle) : string.Empty;
|
var presetTitle = Preset != null ? Loc.GetString(Preset.ModeTitle) : string.Empty;
|
||||||
|
|
||||||
void FailedPresetRestart()
|
void FailedPresetRestart()
|
||||||
{
|
{
|
||||||
@@ -36,7 +37,7 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
if (_configurationManager.GetCVar(CCVars.GameLobbyFallbackEnabled))
|
if (_configurationManager.GetCVar(CCVars.GameLobbyFallbackEnabled))
|
||||||
{
|
{
|
||||||
var oldPreset = _preset;
|
var oldPreset = Preset;
|
||||||
ClearGameRules();
|
ClearGameRules();
|
||||||
SetGamePreset(_configurationManager.GetCVar(CCVars.GameLobbyFallbackPreset));
|
SetGamePreset(_configurationManager.GetCVar(CCVars.GameLobbyFallbackPreset));
|
||||||
AddGamePresetRules();
|
AddGamePresetRules();
|
||||||
@@ -48,7 +49,7 @@ namespace Content.Server.GameTicking
|
|||||||
_chatManager.DispatchServerAnnouncement(
|
_chatManager.DispatchServerAnnouncement(
|
||||||
Loc.GetString("game-ticker-start-round-cannot-start-game-mode-fallback",
|
Loc.GetString("game-ticker-start-round-cannot-start-game-mode-fallback",
|
||||||
("failedGameMode", presetTitle),
|
("failedGameMode", presetTitle),
|
||||||
("fallbackMode", Loc.GetString(_preset!.ModeTitle))));
|
("fallbackMode", Loc.GetString(Preset!.ModeTitle))));
|
||||||
|
|
||||||
if (startAttempt.Cancelled)
|
if (startAttempt.Cancelled)
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,7 @@ namespace Content.Server.GameTicking
|
|||||||
if (DummyTicker)
|
if (DummyTicker)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_preset = preset;
|
Preset = preset;
|
||||||
UpdateInfoText();
|
UpdateInfoText();
|
||||||
|
|
||||||
if (force)
|
if (force)
|
||||||
@@ -120,10 +121,10 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
private bool AddGamePresetRules()
|
private bool AddGamePresetRules()
|
||||||
{
|
{
|
||||||
if (DummyTicker || _preset == null)
|
if (DummyTicker || Preset == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
foreach (var rule in _preset.Rules)
|
foreach (var rule in Preset.Rules)
|
||||||
{
|
{
|
||||||
if (!_prototypeManager.TryIndex(rule, out GameRulePrototype? ruleProto))
|
if (!_prototypeManager.TryIndex(rule, out GameRulePrototype? ruleProto))
|
||||||
continue;
|
continue;
|
||||||
@@ -136,7 +137,8 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
private void StartGamePresetRules()
|
private void StartGamePresetRules()
|
||||||
{
|
{
|
||||||
foreach (var rule in _addedGameRules)
|
// May be touched by the preset during init.
|
||||||
|
foreach (var rule in _addedGameRules.ToArray())
|
||||||
{
|
{
|
||||||
StartGameRule(rule);
|
StartGameRule(rule);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
private string GetInfoText()
|
private string GetInfoText()
|
||||||
{
|
{
|
||||||
if (_preset == null)
|
if (Preset == null)
|
||||||
{
|
{
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,8 @@ namespace Content.Server.GameTicking
|
|||||||
var playerCount = $"{_playerManager.PlayerCount}";
|
var playerCount = $"{_playerManager.PlayerCount}";
|
||||||
var map = _gameMapManager.GetSelectedMap();
|
var map = _gameMapManager.GetSelectedMap();
|
||||||
var mapName = map?.MapName ?? Loc.GetString("game-ticker-no-map-selected");
|
var mapName = map?.MapName ?? Loc.GetString("game-ticker-no-map-selected");
|
||||||
var gmTitle = Loc.GetString(_preset.ModeTitle);
|
var gmTitle = Loc.GetString(Preset.ModeTitle);
|
||||||
var desc = Loc.GetString(_preset.Description);
|
var desc = Loc.GetString(Preset.Description);
|
||||||
return Loc.GetString("game-ticker-get-info-text",("roundId", RoundId), ("playerCount", playerCount),("mapName", mapName),("gmTitle", gmTitle),("desc", desc));
|
return Loc.GetString("game-ticker-get-info-text",("roundId", RoundId), ("playerCount", playerCount),("mapName", mapName),("gmTitle", gmTitle),("desc", desc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ namespace Content.Server.GameTicking
|
|||||||
RunLevel = GameRunLevel.PostRound;
|
RunLevel = GameRunLevel.PostRound;
|
||||||
|
|
||||||
//Tell every client the round has ended.
|
//Tell every client the round has ended.
|
||||||
var gamemodeTitle = _preset != null ? Loc.GetString(_preset.ModeTitle) : string.Empty;
|
var gamemodeTitle = Preset != null ? Loc.GetString(Preset.ModeTitle) : string.Empty;
|
||||||
|
|
||||||
// Let things add text here.
|
// Let things add text here.
|
||||||
var textEv = new RoundEndTextAppendEvent();
|
var textEv = new RoundEndTextAppendEvent();
|
||||||
@@ -469,11 +469,11 @@ namespace Content.Server.GameTicking
|
|||||||
|
|
||||||
private void AnnounceRound()
|
private void AnnounceRound()
|
||||||
{
|
{
|
||||||
if (_preset == null) return;
|
if (Preset == null) return;
|
||||||
|
|
||||||
foreach (var proto in _prototypeManager.EnumeratePrototypes<RoundAnnouncementPrototype>())
|
foreach (var proto in _prototypeManager.EnumeratePrototypes<RoundAnnouncementPrototype>())
|
||||||
{
|
{
|
||||||
if (!proto.GamePresets.Contains(_preset.ID)) continue;
|
if (!proto.GamePresets.Contains(Preset.ID)) continue;
|
||||||
|
|
||||||
if (proto.Message != null)
|
if (proto.Message != null)
|
||||||
_chatManager.DispatchStationAnnouncement(Loc.GetString(proto.Message), playDefaultSound: false);
|
_chatManager.DispatchStationAnnouncement(Loc.GetString(proto.Message), playDefaultSound: false);
|
||||||
|
|||||||
@@ -83,8 +83,10 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
|||||||
|
|
||||||
_aliveNukeops.Clear();
|
_aliveNukeops.Clear();
|
||||||
|
|
||||||
var numOps = (int)Math.Min(Math.Floor((double)ev.PlayerPool.Count / _cfg.GetCVar(CCVars.NukeopsPlayersPerOp)),
|
// Between 1 and <max op count>: needs at least n players per op.
|
||||||
_cfg.GetCVar(CCVars.NukeopsMaxOps));
|
var numOps = Math.Max(1,
|
||||||
|
(int)Math.Min(
|
||||||
|
Math.Floor((double)ev.PlayerPool.Count / _cfg.GetCVar(CCVars.NukeopsPlayersPerOp)), _cfg.GetCVar(CCVars.NukeopsMaxOps)));
|
||||||
var ops = new IPlayerSession[numOps];
|
var ops = new IPlayerSession[numOps];
|
||||||
for (var i = 0; i < numOps; i++)
|
for (var i = 0; i < numOps; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
42
Content.Server/GameTicking/Rules/SecretRuleSystem.cs
Normal file
42
Content.Server/GameTicking/Rules/SecretRuleSystem.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using Content.Server.GameTicking.Presets;
|
||||||
|
using Content.Shared.Random;
|
||||||
|
using Content.Shared.Random.Helpers;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Server.GameTicking.Rules;
|
||||||
|
|
||||||
|
public sealed class SecretRuleSystem : GameRuleSystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
[Dependency] private readonly GameTicker _ticker = default!;
|
||||||
|
|
||||||
|
public override string Prototype => "Secret";
|
||||||
|
|
||||||
|
public override void Started()
|
||||||
|
{
|
||||||
|
PickRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Ended()
|
||||||
|
{
|
||||||
|
// noop
|
||||||
|
// Preset should already handle it.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PickRule()
|
||||||
|
{
|
||||||
|
// TODO: This doesn't consider what can't start due to minimum player count, but currently there's no way to know anyway.
|
||||||
|
// as they use cvars.
|
||||||
|
var preset = _prototypeManager.Index<WeightedRandomPrototype>("Secret").Pick(_random);
|
||||||
|
Logger.InfoS("gamepreset", $"Selected {preset} for secret.");
|
||||||
|
|
||||||
|
foreach (var rule in _prototypeManager.Index<GamePresetPrototype>(preset).Rules)
|
||||||
|
{
|
||||||
|
_ticker.AddGameRule(_prototypeManager.Index<GameRulePrototype>(rule));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem
|
|||||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||||
[Dependency] private readonly IObjectivesManager _objectivesManager = default!;
|
[Dependency] private readonly IObjectivesManager _objectivesManager = default!;
|
||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
|
[Dependency] private readonly GameTicker _gameTicker = default!;
|
||||||
|
|
||||||
public override string Prototype => "Traitor";
|
public override string Prototype => "Traitor";
|
||||||
|
|
||||||
@@ -47,11 +48,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem
|
|||||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Started()
|
public override void Started() {}
|
||||||
{
|
|
||||||
// This seems silly, but I'll leave it.
|
|
||||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("rule-traitor-added-announcement"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Ended()
|
public override void Ended()
|
||||||
{
|
{
|
||||||
@@ -63,6 +60,13 @@ public sealed class TraitorRuleSystem : GameRuleSystem
|
|||||||
if (!Enabled)
|
if (!Enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// If the current preset doesn't explicitly contain the traitor game rule, just carry on and remove self.
|
||||||
|
if (_gameTicker.Preset?.Rules.Contains(Prototype) ?? false)
|
||||||
|
{
|
||||||
|
_gameTicker.EndGameRule(_prototypeManager.Index<GameRulePrototype>(Prototype));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var minPlayers = _cfg.GetCVar(CCVars.TraitorMinPlayers);
|
var minPlayers = _cfg.GetCVar(CCVars.TraitorMinPlayers);
|
||||||
if (!ev.Forced && ev.Players.Length < minPlayers)
|
if (!ev.Forced && ev.Players.Length < minPlayers)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Dataset;
|
using System.Linq;
|
||||||
|
using Content.Shared.Dataset;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
namespace Content.Shared.Random.Helpers
|
namespace Content.Shared.Random.Helpers
|
||||||
@@ -9,5 +10,28 @@ namespace Content.Shared.Random.Helpers
|
|||||||
{
|
{
|
||||||
return random.Pick(prototype.Values);
|
return random.Pick(prototype.Values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Pick(this WeightedRandomPrototype prototype, IRobustRandom? random = null)
|
||||||
|
{
|
||||||
|
IoCManager.Resolve(ref random);
|
||||||
|
var picks = prototype.Weights;
|
||||||
|
var sum = picks.Values.Sum();
|
||||||
|
var accumulated = 0f;
|
||||||
|
|
||||||
|
var rand = random.NextFloat() * sum;
|
||||||
|
|
||||||
|
foreach (var (key, weight) in picks)
|
||||||
|
{
|
||||||
|
accumulated += weight;
|
||||||
|
|
||||||
|
if (accumulated >= rand)
|
||||||
|
{
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shouldn't happen
|
||||||
|
throw new InvalidOperationException($"Invalid weighted pick for {prototype.ID}!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
Content.Shared/Random/WeightedRandomPrototype.cs
Normal file
15
Content.Shared/Random/WeightedRandomPrototype.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
|
namespace Content.Shared.Random;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generic random weighting dataset to use.
|
||||||
|
/// </summary>
|
||||||
|
[Prototype("weightedRandom")]
|
||||||
|
public sealed class WeightedRandomPrototype : IPrototype
|
||||||
|
{
|
||||||
|
[IdDataFieldAttribute] public string ID { get; } = default!;
|
||||||
|
|
||||||
|
[DataField("weights")]
|
||||||
|
public Dictionary<string, float> Weights = new();
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
secret-title = Secret
|
||||||
|
secret-description = It's a secret to everyone. The threats you encounter are randomized.
|
||||||
@@ -7,6 +7,17 @@
|
|||||||
showInVote: true
|
showInVote: true
|
||||||
description: extended-description
|
description: extended-description
|
||||||
|
|
||||||
|
- type: gamePreset
|
||||||
|
id: Secret
|
||||||
|
alias:
|
||||||
|
- secret
|
||||||
|
- sekrit
|
||||||
|
name: secret-title
|
||||||
|
showInVote: true
|
||||||
|
description: secret-description
|
||||||
|
rules:
|
||||||
|
- Secret
|
||||||
|
|
||||||
- type: gamePreset
|
- type: gamePreset
|
||||||
id: Sandbox
|
id: Sandbox
|
||||||
alias:
|
alias:
|
||||||
|
|||||||
@@ -21,3 +21,6 @@
|
|||||||
|
|
||||||
- type: gameRule
|
- type: gameRule
|
||||||
id: Sandbox
|
id: Sandbox
|
||||||
|
|
||||||
|
- type: gameRule
|
||||||
|
id: Secret
|
||||||
|
|||||||
6
Resources/Prototypes/secret_weights.yml
Normal file
6
Resources/Prototypes/secret_weights.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
- type: weightedRandom
|
||||||
|
id: Secret
|
||||||
|
weights:
|
||||||
|
Extended: 0.25
|
||||||
|
Nukeops: 0.25
|
||||||
|
Traitor: 0.75
|
||||||
Reference in New Issue
Block a user