2022-05-19 14:44:24 +10:00
|
|
|
using Content.Server.GameTicking.Presets;
|
2023-04-25 20:23:14 -04:00
|
|
|
using Content.Server.GameTicking.Rules.Components;
|
2022-05-19 14:44:24 +10:00
|
|
|
using Content.Shared.Random;
|
|
|
|
|
using Content.Shared.Random.Helpers;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
public sealed class SecretRuleSystem : GameRuleSystem<SecretRuleComponent>
|
2022-05-19 14:44:24 +10:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
protected override void Started(EntityUid uid, SecretRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
2022-05-19 14:44:24 +10:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
base.Started(uid, component, gameRule, args);
|
|
|
|
|
PickRule(component);
|
2022-05-19 14:44:24 +10:00
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
protected override void Ended(EntityUid uid, SecretRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
2022-05-19 14:44:24 +10:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
base.Ended(uid, component, gameRule, args);
|
|
|
|
|
|
|
|
|
|
foreach (var rule in component.AdditionalGameRules)
|
|
|
|
|
{
|
|
|
|
|
GameTicker.EndGameRule(rule);
|
|
|
|
|
}
|
2022-05-19 14:44:24 +10:00
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
private void PickRule(SecretRuleComponent component)
|
2022-05-19 14:44:24 +10:00
|
|
|
{
|
2023-06-08 00:16:18 -07:00
|
|
|
// 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.
|
2022-05-19 14:44:24 +10:00
|
|
|
var preset = _prototypeManager.Index<WeightedRandomPrototype>("Secret").Pick(_random);
|
|
|
|
|
Logger.InfoS("gamepreset", $"Selected {preset} for secret.");
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
var rules = _prototypeManager.Index<GamePresetPrototype>(preset).Rules;
|
|
|
|
|
foreach (var rule in rules)
|
2022-05-19 14:44:24 +10:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
GameTicker.StartGameRule(rule, out var ruleEnt);
|
|
|
|
|
component.AdditionalGameRules.Add(ruleEnt);
|
2022-05-19 14:44:24 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|