CatStation/Content.Shared/Mindshield/MindShieldSystem.cs
KeTuFaisPiKiNut ea2dd83e77
Mindshield Refactor + Changeling Fake Mindshield (#43864)
* the great mindshield rework

* it just works :D

* glory to nyanotransen, I said with my very obviously fake mindshield.

* work on things to remove manual mindshield queries

* very wip impl

* yeah there we go apc destroyed mission accomplished

* some comments

* textures!

* i will stab the person who decided to spell it differently.

* rename things since i am crazy (i was also crazy once)

* minor spelling mistake :(

* Revert "minor spelling mistake :("

This reverts commit ece1f1c3509063d1c43b7f136509ed4df2cd62e7.

* Revert "rename things since i am crazy (i was also crazy once)"

This reverts commit e75411d4bb84e819ca525b9fa0fe1792b6ace0b6.

* Revert "i will stab the person who decided to spell it differently."

This reverts commit 696ffdc062094cc9e4cf382f1e39b4ae4e3d781d.

* fixed things + better texs

* aaaa

* INSANITY RAHHHHH

* e

* changing things a bit.

* testifying things actually no insanity

* cleaning

* only doing this cuz of heseintests failing

* cleanup

* Update Content.Server/Revolutionary/RevolutionarySystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Apply suggestions from code review

fucking suggestions WHY IS THE BUTTON THERE EVEN WHEN ITS DISABLED!!!!

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* half of things for scarky0

* event merging stub / beginning

* big rewrite

* there ya go scar

* e

* NETWORK YOU PRICK

* Update Content.Shared/Mindshield/SharedMindShieldSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Mindshield/SharedMindShieldSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Server/Revolutionary/RevolutionarySystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Mindshield/FakeMindshieldSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* e

* RAHHHH

* cleaning

* Update changeling.yml

* Update meta.json

* slarti 1/3

* slarti things 2

* le real fix

* commit & push

* Update Content.Client/Overlays/ShowMindShieldIconsSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Server/Implants/MindshieldImplantSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Mindshield/SharedMindShieldSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Mindshield/FakeMindshieldSystem.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* Update Content.Shared/Mindshield/Components/MindShieldStatusComponent.cs

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* scarky0

* dirty

* fml

* robust thyself now

* minor fix

* stub

* Revert "stub"

This reverts commit c1204b88d3ae1bbdca2deeb075a9dd0d6c529326.

* s

* jrwebiwerhweir

* shrimple fix

* Apply suggestions from code review

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

* yeeeuuuwhqeheueuuu

* rweifohgeterwt

* cleaning, compiling

* container bs and icons

* werewrewr

* fix

* crisis averted

* howd i forget this

* leave me ALONE

---------

Co-authored-by: nomdéraisonnablementlong <you@example.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: ScarKy0 <scarky0@onet.eu>
Co-authored-by: Pok245 <113675512+Pok27@users.noreply.github.com>
2026-07-30 22:39:13 +00:00

139 lines
4.6 KiB
C#

using Content.Shared.Clothing;
using Content.Shared.Implants;
using Content.Shared.Inventory;
using Content.Shared.Mindshield.Components;
using Content.Shared.StatusIcon;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.Mindshield;
public sealed partial class MindShieldSystem : EntitySystem
{
[Dependency] private IGameTiming _timing = default!;
/// <summary>
/// Status icon displayed in the sec HUD.
/// </summary>
public static ProtoId<SecurityIconPrototype> StatusIcon = "MindShieldIcon";
public override void Initialize()
{
base.Initialize();
// Mind shield status events
SubscribeLocalEvent<MindShieldComponent, ImplantRelayEvent<GetMindShieldStatusEvent>>((e, ref k) => OnStatusQuery(e, ref k.Args));
SubscribeLocalEvent<MindShieldComponent, InventoryRelayedEvent<GetMindShieldStatusEvent>>((e, ref k) => OnStatusQuery(e, ref k.Args));
}
[SubscribeLocalEvent]
private void OnMindshieldUnequip(Entity<MindShieldComponent> ent, ref ClothingGotUnequippedEvent args)
{
if (_timing.ApplyingState)
return;
RefreshMindshieldStatus(args.Wearer);
}
[SubscribeLocalEvent]
private void OnMindshieldEquip(Entity<MindShieldComponent> ent, ref ClothingGotEquippedEvent args)
{
if (_timing.ApplyingState)
return;
RefreshMindshieldStatus(args.Wearer);
}
[SubscribeLocalEvent]
private void OnMindshieldRemoved(Entity<MindShieldComponent> ent, ref ComponentRemove args)
{
RefreshMindshieldStatus(ent.Owner);
}
[SubscribeLocalEvent]
private void OnMindshieldImplantRemoved(Entity<MindShieldComponent> ent, ref ImplantRemovedEvent args)
{
RefreshMindshieldStatus(args.Implanted);
}
[SubscribeLocalEvent]
private void OnMindshieldImplanted(Entity<MindShieldComponent> ent, ref ImplantImplantedEvent args)
{
RefreshMindshieldStatus(args.Implanted);
}
[SubscribeLocalEvent]
private void OnMindshieldMapInit(Entity<MindShieldComponent> ent, ref MapInitEvent args)
{
// todo: make it not refresh on implant & clothing items
RefreshMindshieldStatus(ent.Owner);
}
/// <summary>
/// This function updates <see cref="MindShieldStatusComponent"/>. It should be called when anything makes a modification of its mindshielded-ness.
/// </summary>
public void RefreshMindshieldStatus(EntityUid ent)
{
var ev = new GetMindShieldStatusEvent();
RaiseLocalEvent(ent, ref ev);
var mindshielded = ev.IsMindshielded;
var visible = ev.IsVisible;
if (!mindshielded && !visible)
{
if (HasComp<MindShieldStatusComponent>(ent))
RemCompDeferred<MindShieldStatusComponent>(ent);
}
else
{
EnsureComp<MindShieldStatusComponent>(ent, out var c);
c.IsMindshielded = mindshielded;
c.IsVisible = visible;
Dirty(ent, c);
}
}
[SubscribeLocalEvent]
private void OnStatusQuery(Entity<MindShieldComponent> e, ref GetMindShieldStatusEvent args)
{
args.IsMindshielded = true;
args.IsVisible = true;
}
/// <summary>
/// Retrieves mindshielding data of an entity. Works via <see cref="MindShieldStatusComponent"/>, and so requires proper dirtying on the part of mindshield providers.
/// </summary>
/// <param name="entity">The entity to check the mindshield status of.</param>
/// <param name="isMindshielded">If the entity has a functional mind shield</param>
/// <param name="isVisible">Wether the entity shows a mindshield icon on the sec HUD</param>
/// <remarks>You should never look for a mindshield component and instead use this function.</remarks>
public void GetMindshieldStatus(EntityUid entity, out bool isMindshielded, out bool isVisible)
{
if (TryComp<MindShieldStatusComponent>(entity, out var comp))
{
isMindshielded = comp.IsMindshielded;
isVisible = comp.IsVisible;
}
else
{
isMindshielded = isVisible = false;
}
}
}
/// <summary>
/// Raised in order to get whether an entity is mindshielded visually, mechanically or both.
/// </summary>
[ByRefEvent]
public sealed class GetMindShieldStatusEvent : EntityEventArgs, IInventoryRelayEvent
{
public SlotFlags TargetSlots => SlotFlags.WITHOUT_POCKET;
/// <summary>
/// Whether the entity is mindshielded.
/// </summary>
public bool IsMindshielded;
/// <summary>
/// Whether a mindshield icon is present
/// </summary>
public bool IsVisible;
}