2023-08-17 23:41:13 +03:00
|
|
|
using Content.Server.GameTicking;
|
2023-08-15 14:47:55 +03:00
|
|
|
using Content.Server.Popups;
|
2023-08-17 23:41:13 +03:00
|
|
|
using Content.Server.Station.Systems;
|
2024-01-28 18:18:54 +07:00
|
|
|
using Content.Server._White.ERTRecruitment;
|
2023-08-15 14:47:55 +03:00
|
|
|
using Content.Shared.Access.Systems;
|
|
|
|
|
using Content.Shared.Administration.Logs;
|
|
|
|
|
using Content.Shared.Database;
|
|
|
|
|
using Content.Shared.GameTicking;
|
|
|
|
|
using Content.Shared.White.AuthPanel;
|
2023-08-17 23:41:13 +03:00
|
|
|
using Content.Shared.White.GhostRecruitment;
|
2023-08-15 14:47:55 +03:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
2024-01-28 18:18:54 +07:00
|
|
|
namespace Content.Server._White.AuthPanel;
|
2023-08-15 14:47:55 +03:00
|
|
|
|
|
|
|
|
public sealed class AuthPanelSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
|
|
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
|
[Dependency] private readonly AccessReaderSystem _access = default!;
|
|
|
|
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
2023-08-17 23:41:13 +03:00
|
|
|
[Dependency] private readonly ERTRecruitmentRule _ert = default!;
|
|
|
|
|
[Dependency] private readonly GameTicker _gameTicker = default!;
|
|
|
|
|
[Dependency] private readonly StationSystem _station = default!;
|
2023-08-15 14:47:55 +03:00
|
|
|
|
|
|
|
|
public Dictionary<AuthPanelAction, HashSet<EntityUid>> Counter = new();
|
|
|
|
|
public Dictionary<AuthPanelAction, HashSet<int>> CardIndexes = new();
|
|
|
|
|
public string Reason = "";
|
|
|
|
|
|
|
|
|
|
public static int MaxCount = 2;
|
|
|
|
|
|
|
|
|
|
private TimeSpan? _delay;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
SubscribeLocalEvent<AuthPanelComponent,AuthPanelButtonPressedMessage>(OnButtonPressed);
|
|
|
|
|
SubscribeLocalEvent<AuthPanelComponent,AuthPanelPerformActionEvent>(OnPerformAction);
|
2023-08-17 23:41:13 +03:00
|
|
|
SubscribeLocalEvent<RecruitedComponent,ERTRecruitedReasonEvent>(OnReason);
|
2023-08-15 14:47:55 +03:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRestart);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 23:41:13 +03:00
|
|
|
private void OnReason(EntityUid uid, RecruitedComponent component, ERTRecruitedReasonEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Reason = Reason;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 14:47:55 +03:00
|
|
|
private void OnRestart(RoundRestartCleanupEvent ev)
|
|
|
|
|
{
|
|
|
|
|
Counter.Clear();
|
|
|
|
|
CardIndexes.Clear();
|
|
|
|
|
|
|
|
|
|
_delay = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPerformAction(EntityUid uid, AuthPanelComponent component, AuthPanelPerformActionEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Action is AuthPanelAction.ERTRecruit)
|
|
|
|
|
{
|
2023-08-17 23:41:13 +03:00
|
|
|
if (_random.Next(10) < 2)
|
2023-08-15 14:47:55 +03:00
|
|
|
{
|
2023-08-17 23:41:13 +03:00
|
|
|
_gameTicker.AddGameRule(ERTRecruitmentRuleComponent.EventName);
|
2023-08-15 14:47:55 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-08-17 23:41:13 +03:00
|
|
|
var station = _station.GetStationInMap(Transform(uid).MapID);
|
|
|
|
|
|
|
|
|
|
if (station != null)
|
|
|
|
|
_ert.DeclineERT(station.Value);
|
2023-08-15 14:47:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var entities in Counter.Values)
|
|
|
|
|
{
|
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
{
|
|
|
|
|
_adminLogger.Add(LogType.EventStarted, LogImpact.High,
|
|
|
|
|
$"{ToPrettyString(entity):player} just called ERT. Reason: {Reason}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnButtonPressed(EntityUid uid, AuthPanelComponent component, AuthPanelButtonPressedMessage args)
|
|
|
|
|
{
|
|
|
|
|
if(args.Session.AttachedEntity == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var access = _access.FindAccessTags(args.Session.AttachedEntity.Value);
|
|
|
|
|
|
|
|
|
|
if (!access.Contains("Command"))
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("auth-panel-no-access"),
|
|
|
|
|
args.Session.AttachedEntity.Value,args.Session.AttachedEntity.Value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(args.Reason))
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("auth-panel-no-reason"),
|
|
|
|
|
args.Session.AttachedEntity.Value,args.Session.AttachedEntity.Value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_delay != null)
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("auth-panel-wait"),
|
|
|
|
|
args.Session.AttachedEntity.Value,args.Session.AttachedEntity.Value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Counter.TryGetValue(args.Button, out var hashSet))
|
|
|
|
|
{
|
|
|
|
|
hashSet = new HashSet<EntityUid>();
|
|
|
|
|
Counter.Add(args.Button,hashSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(hashSet.Count == MaxCount)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!CardIndexes.TryGetValue(args.Button, out var cardSet))
|
|
|
|
|
{
|
|
|
|
|
cardSet = new HashSet<int>();
|
|
|
|
|
CardIndexes.Add(args.Button,cardSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cardSet.Contains(access.Count))
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("auth-panel-used-ID"),
|
|
|
|
|
args.Session.AttachedEntity.Value,args.Session.AttachedEntity.Value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hashSet.Add(args.Session.AttachedEntity.Value))
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupEntity(Loc.GetString("auth-panel-pressed"),
|
|
|
|
|
args.Session.AttachedEntity.Value,args.Session.AttachedEntity.Value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cardSet.Add(access.Count);
|
|
|
|
|
_delay = _timing.CurTime + TimeSpan.FromSeconds(5);
|
|
|
|
|
|
|
|
|
|
Reason = args.Reason;
|
|
|
|
|
UpdateUserInterface(args.Button);
|
|
|
|
|
_adminLogger.Add(LogType.EventStarted, LogImpact.High,
|
|
|
|
|
$"{ToPrettyString(args.Session.AttachedEntity.Value):player} vote for {args.Button}. Reason: {Reason}");
|
|
|
|
|
|
|
|
|
|
if (hashSet.Count == MaxCount)
|
|
|
|
|
{
|
|
|
|
|
var ev = new AuthPanelPerformActionEvent(args.Button);
|
|
|
|
|
RaiseLocalEvent(uid,ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateUserInterface(AuthPanelAction rawaction)
|
|
|
|
|
{
|
|
|
|
|
if(!Counter.TryGetValue(rawaction,out var hashSet))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var action = new AuthPanelConfirmationAction(rawaction, hashSet.Count, MaxCount,Reason);
|
|
|
|
|
|
|
|
|
|
var query = EntityQueryEnumerator<AuthPanelComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid,out _))
|
|
|
|
|
{
|
|
|
|
|
if (!_ui.HasUi(uid, AuthPanelUiKey.Key))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var state = new AuthPanelConfirmationActionState(action);
|
|
|
|
|
var ui = _ui.GetUi(uid, AuthPanelUiKey.Key);
|
|
|
|
|
|
2023-08-17 23:41:13 +03:00
|
|
|
_ui.SetUiState(ui, state);
|
2023-08-15 14:47:55 +03:00
|
|
|
_appearance.SetData(uid,AuthPanelVisualLayers.Confirm,true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
if (_delay == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_timing.CurTime >= _delay)
|
|
|
|
|
{
|
|
|
|
|
_delay = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|