Gamerule Entities, Take 2 (#15765)

This commit is contained in:
Nemanja
2023-04-25 20:23:14 -04:00
committed by GitHub
parent 08ccb5367e
commit 59349b1b9b
124 changed files with 3102 additions and 4344 deletions

View File

@@ -1,6 +1,5 @@
using System.Linq;
using Content.Server.GameTicking.Presets;
using Content.Server.GameTicking.Rules.Configurations;
using Content.Server.GameTicking.Rules.Components;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Robust.Shared.Prototypes;
@@ -8,34 +7,40 @@ using Robust.Shared.Random;
namespace Content.Server.GameTicking.Rules;
public sealed class SecretRuleSystem : GameRuleSystem
public sealed class SecretRuleSystem : GameRuleSystem<SecretRuleComponent>
{
[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()
protected override void Started(EntityUid uid, SecretRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
PickRule();
base.Started(uid, component, gameRule, args);
PickRule(component);
}
public override void Ended()
protected override void Ended(EntityUid uid, SecretRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
{
// Preset should already handle it.
base.Ended(uid, component, gameRule, args);
foreach (var rule in component.AdditionalGameRules)
{
GameTicker.EndGameRule(rule);
}
}
private void PickRule()
private void PickRule(SecretRuleComponent component)
{
// 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)
var rules = _prototypeManager.Index<GamePresetPrototype>(preset).Rules;
foreach (var rule in rules)
{
_ticker.StartGameRule(_prototypeManager.Index<GameRulePrototype>(rule));
Logger.Debug($"what the fuck, {rule}");
GameTicker.StartGameRule(rule, out var ruleEnt);
component.AdditionalGameRules.Add(ruleEnt);
}
}
}