using Content.Shared._NF.Roles.Components; using Content.Shared._NF.Roles.Events; using Content.Shared._NF.Shipyard.Components; using Content.Shared.Access.Systems; using Content.Shared.Hands; using Content.Shared.Interaction.Events; using Content.Shared.Item; using Content.Shared.Paper; namespace Content.Server._NF.Roles.Systems; public abstract partial class SharedInterviewHologramSystem : EntitySystem { [Dependency] protected SharedIdCardSystem IdCardSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnSetCaptainApproved); SubscribeLocalEvent(OnToggleApplicantApproval); SubscribeLocalEvent(OnUseAttempt); SubscribeLocalEvent(OnAttemptInteract); SubscribeLocalEvent(OnAttempt); SubscribeLocalEvent(OnAttempt); } private void OnAttemptInteract(Entity ent, ref InteractionAttemptEvent args) { if (!HasComp(args.Target)) args.Cancelled = true; } private void OnUseAttempt(EntityUid uid, InterviewHologramComponent component, ref UseAttemptEvent args) { if (!HasComp(args.Used)) args.Cancel(); } private void OnAttempt(EntityUid uid, InterviewHologramComponent component, CancellableEntityEventArgs args) { args.Cancel(); } private void OnSetCaptainApproved(Entity ent, ref SetCaptainApprovedEvent ev) { if (IsCaptain(ev.Captain, ent)) { ent.Comp.CaptainApproved = ev.Approved; Dirty(ent); HandleApprovalChanged(ent); } } /// /// Checks if a given entity is the captain of the ship the target entity is on. /// /// The entity to check. /// The target entity that's on the ship in question. protected bool IsCaptain(EntityUid uid, EntityUid target) { return IdCardSystem.TryFindIdCard(uid, out var idCard) && TryComp(idCard, out ShuttleDeedComponent? shuttleDeed) && TryComp(target, out TransformComponent? targetXform) && shuttleDeed.ShuttleUid == targetXform.GridUid; } private void OnToggleApplicantApproval(Entity ent, ref ToggleApplicantApprovalEvent ev) { ent.Comp.ApplicantApproved = !ent.Comp.ApplicantApproved; Dirty(ent); HandleApprovalChanged(ent); ev.Toggle = true; ev.Handled = true; } /// /// An abstract approval handler, expected to be defined server- and client-side. /// /// The entity whose approval state has changed. abstract protected void HandleApprovalChanged(Entity ent); }