mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-28 11:07:50 +03:00
This cherry-pick's Wizden's Antag Refactor, which is needed for all future antag updates, as well as for me to cherry-pick over Cultists(Who are going to need some editing to fit the antag refactor), Changelings, Heretics, and Wizards. I actually selected the White-Dream-Public version of the Antag Refactor, due to it having commits made tailored to our repository, so it comes prepackaged with all the changes necessary for our repo-specific content. https://github.com/frosty-dev/ss14-wwdp/pull/10 Signed-off-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com> Co-authored-by: ThereDrD <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Jeff <velcroboy333@hotmail.com> Co-authored-by: Timemaster99 <57200767+Timemaster99@users.noreply.github.com> Co-authored-by: Timemaster99 <elijahrobot@gmail.com> Co-authored-by: luckywill339@gmail.com <luckywill339@gmail.com> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: Azzy <azzydev@icloud.com>
119 lines
4.1 KiB
C#
119 lines
4.1 KiB
C#
using System.Linq;
|
|
using Content.Server.Administration;
|
|
using Content.Server.GameTicking.Components;
|
|
using Content.Server.GameTicking.Rules;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.StationEvents.Components;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.CCVar;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Toolshed;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.StationEvents
|
|
{
|
|
/// <summary>
|
|
/// The basic event scheduler rule, loosely based off of /tg/ events, which most
|
|
/// game presets use.
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed class BasicStationEventSchedulerSystem : GameRuleSystem<BasicStationEventSchedulerComponent>
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly EventManagerSystem _event = default!;
|
|
[Dependency] private readonly IConfigurationManager _config = default!;
|
|
|
|
protected override void Ended(EntityUid uid, BasicStationEventSchedulerComponent component, GameRuleComponent gameRule,
|
|
GameRuleEndedEvent args)
|
|
{
|
|
component.TimeUntilNextEvent = BasicStationEventSchedulerComponent.MinimumTimeUntilFirstEvent;
|
|
}
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
if (!_event.EventsEnabled)
|
|
return;
|
|
|
|
var query = EntityQueryEnumerator<BasicStationEventSchedulerComponent, GameRuleComponent>();
|
|
while (query.MoveNext(out var uid, out var eventScheduler, out var gameRule))
|
|
{
|
|
if (!GameTicker.IsGameRuleActive(uid, gameRule))
|
|
continue;
|
|
|
|
if (eventScheduler.TimeUntilNextEvent > 0)
|
|
{
|
|
eventScheduler.TimeUntilNextEvent -= frameTime;
|
|
return;
|
|
}
|
|
|
|
_event.RunRandomEvent();
|
|
ResetTimer(eventScheduler);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset the event timer once the event is done.
|
|
/// </summary>
|
|
private void ResetTimer(BasicStationEventSchedulerComponent component)
|
|
{
|
|
component.TimeUntilNextEvent = _random.Next(_config.GetCVar(CCVars.GameEventsBasicMinimumTime),
|
|
_config.GetCVar(CCVars.GameEventsBasicMaximumTime));
|
|
}
|
|
}
|
|
|
|
[ToolshedCommand, AdminCommand(AdminFlags.Debug)]
|
|
public sealed class StationEventCommand : ToolshedCommand
|
|
{
|
|
private EventManagerSystem? _stationEvent;
|
|
|
|
[CommandImplementation("lsprob")]
|
|
public IEnumerable<(string, float)> LsProb()
|
|
{
|
|
_stationEvent ??= GetSys<EventManagerSystem>();
|
|
var events = _stationEvent.AllEvents();
|
|
|
|
var totalWeight = events.Sum(x => x.Value.Weight);
|
|
|
|
foreach (var (proto, comp) in events)
|
|
{
|
|
yield return (proto.ID, comp.Weight / totalWeight);
|
|
}
|
|
}
|
|
|
|
[CommandImplementation("lsprobtime")]
|
|
public IEnumerable<(string, float)> LsProbTime([CommandArgument] float time)
|
|
{
|
|
_stationEvent ??= GetSys<EventManagerSystem>();
|
|
var events = _stationEvent.AllEvents().Where(pair => pair.Value.EarliestStart <= time).ToList();
|
|
|
|
var totalWeight = events.Sum(x => x.Value.Weight);
|
|
|
|
foreach (var (proto, comp) in events)
|
|
{
|
|
yield return (proto.ID, comp.Weight / totalWeight);
|
|
}
|
|
}
|
|
|
|
[CommandImplementation("prob")]
|
|
public float Prob([CommandArgument] string eventId)
|
|
{
|
|
_stationEvent ??= GetSys<EventManagerSystem>();
|
|
var events = _stationEvent.AllEvents();
|
|
|
|
var totalWeight = events.Sum(x => x.Value.Weight);
|
|
var weight = 0f;
|
|
if (events.TryFirstOrNull(p => p.Key.ID == eventId, out var pair))
|
|
{
|
|
weight = pair.Value.Value.Weight;
|
|
}
|
|
|
|
return weight / totalWeight;
|
|
}
|
|
}
|
|
}
|