CatStation/Content.Shared/Revolutionary/SharedRevolutionarySystem.cs
themias 864b741942
Cleanup - remove zombie hardcoding in RevolutionaryRuleSystem (#43986)
* Cleanup - remove zombie hardcoding in RevolutionaryRuleSystem

* Update Content.Shared/Revolutionary/SharedRevolutionary.cs

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>

* fix

* review

* didnt save for some reason

---------

Co-authored-by: Pok <113675512+Pok27@users.noreply.github.com>
2026-05-20 20:50:43 +00:00

109 lines
4.3 KiB
C#

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 partial class SharedRevolutionarySystem : EntitySystem
{
[Dependency] private SharedPopupSystem _popupSystem = default!;
[Dependency] private 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);
SubscribeLocalEvent<RevolutionaryComponent, AttemptConvertRevolutionaryEvent>(OnAttemptConvert);
}
/// <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.TryUpdateParalyzeDuration(uid, stunTime);
_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);
}
}
private void OnAttemptConvert(Entity<RevolutionaryComponent> ent, ref AttemptConvertRevolutionaryEvent args)
{
args.Cancelled = true;
}
}