Files
OldThink/Content.Shared/Revolutionary/SharedRevolutionarySystem.cs
ThereDrD 4a7dd80442 Random fixes (#668)
* fix captain headrev

* fix double lathe recipe

* fix security webbing whitelist

* fix defibrillator doafter

* revert hardsuits armor stats
2024-08-27 14:32:28 +03:00

121 lines
4.7 KiB
C#

using Content.Shared.Ghost;
using Content.Shared.IdentityManagement;
using Content.Shared.Mindshield.Components;
using Content.Shared.Popups;
using Content.Shared.Revolutionary.Components;
using Content.Shared.Stunnable;
using Content.Shared._White.Mood;
using Robust.Shared.GameStates;
using Robust.Shared.Player;
namespace Content.Shared.Revolutionary;
public sealed 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, ComponentShutdown>(OnShutdown); // WD EDIT
SubscribeLocalEvent<RevolutionaryComponent, ComponentGetStateAttemptEvent>(OnRevCompGetStateAttempt);
SubscribeLocalEvent<HeadRevolutionaryComponent, ComponentGetStateAttemptEvent>(OnRevCompGetStateAttempt);
SubscribeLocalEvent<RevolutionaryComponent, ComponentStartup>(DirtyRevComps);
SubscribeLocalEvent<HeadRevolutionaryComponent, ComponentStartup>(DirtyRevComps);
SubscribeLocalEvent<ShowRevIconsComponent, ComponentStartup>(DirtyRevComps);
}
// WD START
private void OnShutdown(Entity<RevolutionaryComponent> ent, ref ComponentShutdown args)
{
RaiseLocalEvent(ent, new MoodRemoveEffectEvent("RevolutionFocused"));
}
// WD END
/// <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, comp.IconVisibleToGhost);
}
/// <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, comp.IconVisibleToGhost);
}
/// <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>
/// <param name="visibleToGhosts"> Whether the component permits the icon to be visible to observers. </param>
/// <returns></returns>
private bool CanGetState(ICommonSession? player, bool visibleToGhosts)
{
//Apparently this can be null in replays so I am just returning true.
if (player is null)
return true;
var uid = player.AttachedEntity;
if (HasComp<RevolutionaryComponent>(uid) || HasComp<HeadRevolutionaryComponent>(uid))
return true;
if (visibleToGhosts && HasComp<GhostComponent>(uid))
return true;
return HasComp<ShowRevIconsComponent>(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);
}
}
}