| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using Content.Shared.IdentityManagement;
- using Content.Shared.Mindshield.Components;
- using Content.Shared.Popups;
- using Content.Shared.Revolutionary.Components;
- using Content.Shared.Stunnable;
- using Robust.Shared.GameStates;
- using Robust.Shared.Player;
- using Content.Shared.Antag;
- namespace Content.Shared.Revolutionary;
- public abstract class SharedRevolutionarySystem : EntitySystem
- {
- [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
- [Dependency] private readonly SharedStunSystem _sharedStun = default!;
- public override void Initialize()
- {
- base.Initialize();
- SubscribeLocalEvent<MindShieldComponent, MapInitEvent>(MindShieldImplanted);
- SubscribeLocalEvent<RevolutionaryComponent, ComponentGetStateAttemptEvent>(OnRevCompGetStateAttempt);
- SubscribeLocalEvent<HeadRevolutionaryComponent, ComponentGetStateAttemptEvent>(OnRevCompGetStateAttempt);
- SubscribeLocalEvent<RevolutionaryComponent, ComponentStartup>(DirtyRevComps);
- SubscribeLocalEvent<HeadRevolutionaryComponent, ComponentStartup>(DirtyRevComps);
- SubscribeLocalEvent<ShowAntagIconsComponent, ComponentStartup>(DirtyRevComps);
- }
- /// <summary>
- /// When the mindshield is implanted in the rev it will popup saying they were deconverted. In Head Revs it will remove the mindshield component.
- /// </summary>
- private void MindShieldImplanted(EntityUid uid, MindShieldComponent comp, MapInitEvent init)
- {
- if (HasComp<HeadRevolutionaryComponent>(uid))
- {
- RemCompDeferred<MindShieldComponent>(uid);
- return;
- }
- if (HasComp<RevolutionaryComponent>(uid))
- {
- var stunTime = TimeSpan.FromSeconds(4);
- var name = Identity.Entity(uid, EntityManager);
- RemComp<RevolutionaryComponent>(uid);
- _sharedStun.TryParalyze(uid, stunTime, true);
- _popupSystem.PopupEntity(Loc.GetString("rev-break-control", ("name", name)), uid);
- }
- }
- /// <summary>
- /// Determines if a HeadRev component should be sent to the client.
- /// </summary>
- private void OnRevCompGetStateAttempt(EntityUid uid, HeadRevolutionaryComponent comp, ref ComponentGetStateAttemptEvent args)
- {
- args.Cancelled = !CanGetState(args.Player);
- }
- /// <summary>
- /// Determines if a Rev component should be sent to the client.
- /// </summary>
- private void OnRevCompGetStateAttempt(EntityUid uid, RevolutionaryComponent comp, ref ComponentGetStateAttemptEvent args)
- {
- args.Cancelled = !CanGetState(args.Player);
- }
- /// <summary>
- /// The criteria that determine whether a Rev/HeadRev component should be sent to a client.
- /// </summary>
- /// <param name="player"> The Player the component will be sent to.</param>
- /// <returns></returns>
- private bool CanGetState(ICommonSession? player)
- {
- //Apparently this can be null in replays so I am just returning true.
- if (player?.AttachedEntity is not {} uid)
- return true;
- if (HasComp<RevolutionaryComponent>(uid) || HasComp<HeadRevolutionaryComponent>(uid))
- return true;
- return HasComp<ShowAntagIconsComponent>(uid);
- }
- /// <summary>
- /// Dirties all the Rev components so they are sent to clients.
- ///
- /// We need to do this because if a rev component was not earlier sent to a client and for example the client
- /// becomes a rev then we need to send all the components to it. To my knowledge there is no way to do this on a
- /// per client basis so we are just dirtying all the components.
- /// </summary>
- private void DirtyRevComps<T>(EntityUid someUid, T someComp, ComponentStartup ev)
- {
- var revComps = AllEntityQuery<RevolutionaryComponent>();
- while (revComps.MoveNext(out var uid, out var comp))
- {
- Dirty(uid, comp);
- }
- var headRevComps = AllEntityQuery<HeadRevolutionaryComponent>();
- while (headRevComps.MoveNext(out var uid, out var comp))
- {
- Dirty(uid, comp);
- }
- }
- }
|