2024-01-20 10:02:12 -08:00
|
|
|
using Content.Server.Administration.Logs;
|
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;
|
2024-01-05 15:30:00 -08:00
|
|
|
using Content.Shared.CCVar;
|
2024-01-20 10:02:12 -08:00
|
|
|
using Content.Shared.Database;
|
2022-05-19 14:44:24 +10:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Random;
|
2024-01-05 15:30:00 -08:00
|
|
|
using Robust.Shared.Configuration;
|
2022-05-19 14:44:24 +10:00
|
|
|
|
|
|
|
|
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!;
|
2024-01-05 15:30:00 -08:00
|
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
2024-01-20 10:02:12 -08:00
|
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
2022-05-19 14:44:24 +10:00
|
|
|
|
2024-01-30 22:52:35 -07:00
|
|
|
protected override void Added(EntityUid uid, SecretRuleComponent component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
2022-05-19 14:44:24 +10:00
|
|
|
{
|
2024-01-30 22:52:35 -07:00
|
|
|
base.Added(uid, component, gameRule, args);
|
2023-04-25 20:23:14 -04:00
|
|
|
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.
|
2024-01-05 15:30:00 -08:00
|
|
|
var presetString = _configurationManager.GetCVar(CCVars.SecretWeightPrototype);
|
|
|
|
|
var preset = _prototypeManager.Index<WeightedRandomPrototype>(presetString).Pick(_random);
|
2024-01-30 22:52:35 -07:00
|
|
|
Log.Info($"Selected {preset} for secret.");
|
2024-01-20 10:02:12 -08:00
|
|
|
_adminLogger.Add(LogType.EventStarted, $"Selected {preset} for secret.");
|
2022-05-19 14:44:24 +10:00
|
|
|
|
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
|
|
|
{
|
2024-01-30 22:52:35 -07:00
|
|
|
EntityUid ruleEnt;
|
|
|
|
|
|
|
|
|
|
// if we're pre-round (i.e. will only be added)
|
|
|
|
|
// then just add rules. if we're added in the middle of the round (or at any other point really)
|
|
|
|
|
// then we want to start them as well
|
|
|
|
|
if (GameTicker.RunLevel <= GameRunLevel.InRound)
|
|
|
|
|
ruleEnt = GameTicker.AddGameRule(rule);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GameTicker.StartGameRule(rule, out ruleEnt);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
component.AdditionalGameRules.Add(ruleEnt);
|
2022-05-19 14:44:24 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|