Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
metalgearsloth
2022-05-19 14:44:24 +10:00
committed by GitHub
parent a6a25e30e5
commit 8d6a3ecea7
12 changed files with 133 additions and 22 deletions

View 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));
}
}
}