Revert "Gamerule Entities" (#15724)

This commit is contained in:
metalgearsloth
2023-04-24 16:21:05 +10:00
committed by GitHub
parent 39cc02b8f9
commit d3552dae00
124 changed files with 4328 additions and 3083 deletions

View File

@@ -1,7 +1,5 @@
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Components;
using Content.Server.StationEvents.Events;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
@@ -9,20 +7,35 @@ using Robust.Shared.Random;
namespace Content.Server.StationEvents;
public sealed class RampingStationEventSchedulerSystem : GameRuleSystem<RampingStationEventSchedulerComponent>
public sealed class RampingStationEventSchedulerSystem : GameRuleSystem
{
public override string Prototype => "RampingStationEventScheduler";
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly EventManagerSystem _event = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
public float GetChaosModifier(EntityUid uid, RampingStationEventSchedulerComponent component)
{
var roundTime = (float) _gameTicker.RoundDuration().TotalSeconds;
if (roundTime > component.EndTime)
return component.MaxChaos;
[ViewVariables(VVAccess.ReadWrite)]
private float _endTime;
[ViewVariables(VVAccess.ReadWrite)]
private float _maxChaos;
[ViewVariables(VVAccess.ReadWrite)]
private float _startingChaos;
[ViewVariables(VVAccess.ReadWrite)]
private float _timeUntilNextEvent;
return component.MaxChaos / component.EndTime * roundTime + component.StartingChaos;
[ViewVariables]
public float ChaosModifier
{
get
{
var roundTime = (float) _gameTicker.RoundDuration().TotalSeconds;
if (roundTime > _endTime)
return _maxChaos;
return (_maxChaos / _endTime) * roundTime + _startingChaos;
}
}
public override void Initialize()
@@ -32,65 +45,60 @@ public sealed class RampingStationEventSchedulerSystem : GameRuleSystem<RampingS
SubscribeLocalEvent<GetSeverityModifierEvent>(OnGetSeverityModifier);
}
protected override void Started(EntityUid uid, RampingStationEventSchedulerComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
public override void Started()
{
base.Started(uid, component, gameRule, args);
var avgChaos = _cfg.GetCVar(CCVars.EventsRampingAverageChaos);
var avgTime = _cfg.GetCVar(CCVars.EventsRampingAverageEndTime);
// Worlds shittiest probability distribution
// Got a complaint? Send them to
component.MaxChaos = _random.NextFloat(avgChaos - avgChaos / 4, avgChaos + avgChaos / 4);
_maxChaos = _random.NextFloat(avgChaos - avgChaos / 4, avgChaos + avgChaos / 4);
// This is in minutes, so *60 for seconds (for the chaos calc)
component.EndTime = _random.NextFloat(avgTime - avgTime / 4, avgTime + avgTime / 4) * 60f;
component.StartingChaos = component.MaxChaos / 10;
_endTime = _random.NextFloat(avgTime - avgTime / 4, avgTime + avgTime / 4) * 60f;
_startingChaos = _maxChaos / 10;
PickNextEventTime(uid, component);
PickNextEventTime();
}
public override void Ended()
{
_endTime = 0f;
_maxChaos = 0f;
_startingChaos = 0f;
_timeUntilNextEvent = 0f;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!_event.EventsEnabled)
if (!RuleStarted || !_event.EventsEnabled)
return;
var query = EntityQueryEnumerator<RampingStationEventSchedulerComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var scheduler, out var gameRule))
if (_timeUntilNextEvent > 0f)
{
if (!GameTicker.IsGameRuleActive(uid, gameRule))
return;
if (scheduler.TimeUntilNextEvent > 0f)
{
scheduler.TimeUntilNextEvent -= frameTime;
return;
}
PickNextEventTime(uid, scheduler);
_event.RunRandomEvent();
_timeUntilNextEvent -= frameTime;
return;
}
PickNextEventTime();
_event.RunRandomEvent();
}
private void OnGetSeverityModifier(GetSeverityModifierEvent ev)
{
var query = EntityQueryEnumerator<RampingStationEventSchedulerComponent, GameRuleComponent>();
while (query.MoveNext(out var uid, out var scheduler, out var gameRule))
{
if (!GameTicker.IsGameRuleActive(uid, gameRule))
return;
if (!RuleStarted)
return;
ev.Modifier *= GetChaosModifier(uid, scheduler);
Logger.Info($"Ramping set modifier to {ev.Modifier}");
}
ev.Modifier *= ChaosModifier;
Logger.Info($"Ramping set modifier to {ev.Modifier}");
}
private void PickNextEventTime(EntityUid uid, RampingStationEventSchedulerComponent component)
private void PickNextEventTime()
{
var mod = GetChaosModifier(uid, component);
var mod = ChaosModifier;
// 4-12 minutes baseline. Will get faster over time as the chaos mod increases.
component.TimeUntilNextEvent = _random.NextFloat(240f / mod, 720f / mod);
_timeUntilNextEvent = _random.NextFloat(240f / mod, 720f / mod);
}
}