Secret! (#8276)
Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
@@ -83,8 +83,10 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
|
||||
|
||||
_aliveNukeops.Clear();
|
||||
|
||||
var numOps = (int)Math.Min(Math.Floor((double)ev.PlayerPool.Count / _cfg.GetCVar(CCVars.NukeopsPlayersPerOp)),
|
||||
_cfg.GetCVar(CCVars.NukeopsMaxOps));
|
||||
// Between 1 and <max op count>: needs at least n players per op.
|
||||
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];
|
||||
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 IObjectivesManager _objectivesManager = default!;
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
[Dependency] private readonly GameTicker _gameTicker = default!;
|
||||
|
||||
public override string Prototype => "Traitor";
|
||||
|
||||
@@ -47,11 +48,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndText);
|
||||
}
|
||||
|
||||
public override void Started()
|
||||
{
|
||||
// This seems silly, but I'll leave it.
|
||||
_chatManager.DispatchServerAnnouncement(Loc.GetString("rule-traitor-added-announcement"));
|
||||
}
|
||||
public override void Started() {}
|
||||
|
||||
public override void Ended()
|
||||
{
|
||||
@@ -63,6 +60,13 @@ public sealed class TraitorRuleSystem : GameRuleSystem
|
||||
if (!Enabled)
|
||||
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);
|
||||
if (!ev.Forced && ev.Players.Length < minPlayers)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user