* Диверсионный отряд * фиксы * фиксы линтера * Спрайт терминала икаруса * фикс пинпоинтера * Доработки ДО * Фиксы удалённого управления шаттлом * Не запускать ДО если на может быть меньше 3 глав
202 lines
7.3 KiB
C#
202 lines
7.3 KiB
C#
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Server.Chat.Managers;
|
|
using Content.Server.Jobs;
|
|
using Content.Server.Preferences.Managers;
|
|
using Content.Server.Revolutionary.Components;
|
|
using Content.Shared.GameTicking.Components;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Roles;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.GameTicking.Rules;
|
|
|
|
public abstract partial class GameRuleSystem<T> : EntitySystem where T : IComponent
|
|
{
|
|
[Dependency] protected readonly IRobustRandom RobustRandom = default!;
|
|
[Dependency] protected readonly IChatManager ChatManager = default!;
|
|
[Dependency] protected readonly GameTicker GameTicker = default!;
|
|
[Dependency] protected readonly IGameTiming Timing = default!;
|
|
[Dependency] protected readonly IPrototypeManager _prototype = default!;
|
|
[Dependency] private readonly IComponentFactory _componentFactory = default!;
|
|
|
|
// Not protected, just to be used in utility methods
|
|
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
|
[Dependency] private readonly MapSystem _map = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RoundStartAttemptEvent>(OnStartAttempt);
|
|
SubscribeLocalEvent<T, GameRuleAddedEvent>(OnGameRuleAdded);
|
|
SubscribeLocalEvent<T, GameRuleStartedEvent>(OnGameRuleStarted);
|
|
SubscribeLocalEvent<T, GameRuleEndedEvent>(OnGameRuleEnded);
|
|
SubscribeLocalEvent<RoundEndTextAppendEvent>(OnRoundEndTextAppend);
|
|
}
|
|
|
|
private void OnStartAttempt(RoundStartAttemptEvent args)
|
|
{
|
|
if (args.Forced || args.Cancelled)
|
|
return;
|
|
|
|
var query = QueryAllRules();
|
|
while (query.MoveNext(out var uid, out _, out var gameRule))
|
|
{
|
|
// Sunrise-Start
|
|
if (gameRule.MinCommandStaff > 0)
|
|
{
|
|
var availableHeads = new List<string>();
|
|
|
|
foreach (var playerSession in args.Players)
|
|
{
|
|
var userId = playerSession.UserId;
|
|
var preferencesManager = IoCManager.Resolve<IServerPreferencesManager>();
|
|
var prefs = preferencesManager.GetPreferences(userId);
|
|
var profile = prefs.SelectedCharacter as HumanoidCharacterProfile;
|
|
if (profile == null)
|
|
continue;
|
|
foreach (var profileJobPriority in profile.JobPriorities)
|
|
{
|
|
if (profileJobPriority.Value == JobPriority.Never)
|
|
continue;
|
|
if (!_prototype.TryIndex<JobPrototype>(profileJobPriority.Key.Id, out var job))
|
|
continue;
|
|
foreach (var special in job.Special)
|
|
{
|
|
if (special is not AddComponentSpecial componentSpecial)
|
|
continue;
|
|
|
|
foreach (var componentSpecialComponent in componentSpecial.Components)
|
|
{
|
|
var copy = _componentFactory.GetComponent(componentSpecialComponent.Value);
|
|
if (copy is CommandStaffComponent)
|
|
{
|
|
if (availableHeads.Contains(profileJobPriority.Key))
|
|
continue;
|
|
availableHeads.Add(profileJobPriority.Key);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (gameRule.CancelPresetOnTooFewPlayers && availableHeads.Count < gameRule.MinCommandStaff)
|
|
{
|
|
ChatManager.SendAdminAnnouncement(Loc.GetString("preset-not-enough-ready-command-staff",
|
|
("readyCommandStaffCount", args.Players.Length),
|
|
("minimumCommandStaff", gameRule.MinCommandStaff),
|
|
("presetName", ToPrettyString(uid))));
|
|
args.Cancel();
|
|
}
|
|
}
|
|
// Sunrise-Edit
|
|
|
|
var minPlayers = gameRule.MinPlayers;
|
|
if (args.Players.Length >= minPlayers)
|
|
continue;
|
|
|
|
if (gameRule.CancelPresetOnTooFewPlayers)
|
|
{
|
|
ChatManager.SendAdminAnnouncement(Loc.GetString("preset-not-enough-ready-players",
|
|
("readyPlayersCount", args.Players.Length),
|
|
("minimumPlayers", minPlayers),
|
|
("presetName", ToPrettyString(uid))));
|
|
args.Cancel();
|
|
}
|
|
else
|
|
{
|
|
ForceEndSelf(uid, gameRule);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnGameRuleAdded(EntityUid uid, T component, ref GameRuleAddedEvent args)
|
|
{
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
|
return;
|
|
Added(uid, component, ruleData, args);
|
|
}
|
|
|
|
private void OnGameRuleStarted(EntityUid uid, T component, ref GameRuleStartedEvent args)
|
|
{
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
|
return;
|
|
Started(uid, component, ruleData, args);
|
|
}
|
|
|
|
private void OnGameRuleEnded(EntityUid uid, T component, ref GameRuleEndedEvent args)
|
|
{
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
|
return;
|
|
Ended(uid, component, ruleData, args);
|
|
}
|
|
|
|
private void OnRoundEndTextAppend(RoundEndTextAppendEvent ev)
|
|
{
|
|
var query = AllEntityQuery<T>();
|
|
while (query.MoveNext(out var uid, out var comp))
|
|
{
|
|
if (!TryComp<GameRuleComponent>(uid, out var ruleData))
|
|
continue;
|
|
|
|
AppendRoundEndText(uid, comp, ruleData, ref ev);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the gamerule is added
|
|
/// </summary>
|
|
protected virtual void Added(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleAddedEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the gamerule begins
|
|
/// </summary>
|
|
protected virtual void Started(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the gamerule ends
|
|
/// </summary>
|
|
protected virtual void Ended(EntityUid uid, T component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called at the end of a round when text needs to be added for a game rule.
|
|
/// </summary>
|
|
protected virtual void AppendRoundEndText(EntityUid uid, T component, GameRuleComponent gameRule, ref RoundEndTextAppendEvent args)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called on an active gamerule entity in the Update function
|
|
/// </summary>
|
|
protected virtual void ActiveTick(EntityUid uid, T component, GameRuleComponent gameRule, float frameTime)
|
|
{
|
|
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
var query = EntityQueryEnumerator<T, GameRuleComponent>();
|
|
while (query.MoveNext(out var uid, out var comp1, out var comp2))
|
|
{
|
|
if (!GameTicker.IsGameRuleActive(uid, comp2))
|
|
continue;
|
|
|
|
ActiveTick(uid, comp1, comp2, frameTime);
|
|
}
|
|
}
|
|
}
|