CatStation/Content.Shared/Mindshield/FakeMindshieldSystem.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

200 lines
7.7 KiB
C#

using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Clothing;
using Content.Shared.Implants;
using Content.Shared.Inventory;
using Content.Shared.Mindshield.Components;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Shared.Mindshield;
/// <summary>
/// This system handles fake mindshields represented by <see cref="FakeMindShieldComponent"/>. Works using <see cref="SharedMindshieldSystem"/>'s <see cref="RefreshMindshieldStatus"/>
/// </summary>
public sealed partial class FakeMindShieldSystem : EntitySystem
{
[Dependency] private SharedActionsSystem _actions = default!;
[Dependency] private TagSystem _tag = default!;
[Dependency] private IGameTiming _timing = default!;
[Dependency] private MindShieldSystem _mindShields = default!;
[Dependency] private SharedPopupSystem _popups = default!;
public override void Initialize()
{
base.Initialize();
// Other events
SubscribeLocalEvent<FakeMindShieldComponent, ImplantRelayEvent<ChameleonControllerOutfitSelectedEvent>>((ent, ref relay) => OnChameleonControllerOutfitSelectedImplant(ent, ref relay.Args, relay.ImplantedEntity));
// Toggle events
SubscribeLocalEvent<FakeMindShieldComponent, InventoryRelayedEvent<FakeMindShieldToggleEvent>>((e, ref sk) => OnToggleMindshield(e, ref sk.Args));
SubscribeLocalEvent<FakeMindShieldComponent, ImplantRelayEvent<FakeMindShieldToggleEvent>>((e, ref sk) => OnToggleMindshield(e, ref sk.Args));
// Mindshield events
SubscribeLocalEvent<FakeMindShieldComponent, ImplantRelayEvent<GetMindShieldStatusEvent>>((a, ref k) => OnQueryStatus(a, ref k.Args));
SubscribeLocalEvent<FakeMindShieldComponent, InventoryRelayedEvent<GetMindShieldStatusEvent>>((a, ref k) => OnQueryStatus(a, ref k.Args));
}
/// <summary>
/// Displays a popup to inform the player of activation or deactivation.
/// </summary>
/// <param name="ent">
/// An associated tuple. The state in <see cref="FakeMindShieldComponent"/> will be used
/// to display the appropriate popup.
/// </param>
/// <param name="performer">The entity that toggled the fake mindshield.</param>
private void ShowTogglePopup(Entity<FakeMindShieldComponent> ent, EntityUid performer)
{
var message = ent.Comp.IsEnabled
? Loc.GetString(ent.Comp.EnabledPopup)
: Loc.GetString(ent.Comp.DisabledPopup);
_popups.PopupEntity(message, performer, performer);
}
[SubscribeLocalEvent]
private void OnFakeMindshieldEquip(Entity<FakeMindShieldComponent> ent, ref ClothingGotEquippedEvent args)
{
_mindShields.RefreshMindshieldStatus(args.Wearer);
}
[SubscribeLocalEvent]
private void OnFakeMindshieldUnequip(Entity<FakeMindShieldComponent> ent, ref ClothingGotUnequippedEvent args)
{
_mindShields.RefreshMindshieldStatus(args.Wearer);
}
[SubscribeLocalEvent]
private void OnFakeMindshieldRemoved(Entity<FakeMindShieldComponent> ent, ref ComponentRemove args)
{
if (!ent.Comp.IsInnate)
return;
_mindShields.RefreshMindshieldStatus(ent.Owner);
}
[SubscribeLocalEvent]
private void OnFakeMindshieldImplantRemoved(Entity<FakeMindShieldComponent> ent, ref ImplantRemovedEvent args)
{
// when we reinject the mindshield, the action will be disabled (since its a fresh action)
// which would cause it to be desynced with the state of the mindshield
// so we just disable it here
ent.Comp.IsEnabled = false;
Dirty(ent);
_mindShields.RefreshMindshieldStatus(args.Implanted);
}
[SubscribeLocalEvent]
private void OnFakeMindshieldImplanted(Entity<FakeMindShieldComponent> ent, ref ImplantImplantedEvent args)
{
_mindShields.RefreshMindshieldStatus(args.Implanted);
}
[SubscribeLocalEvent]
private void OnMapInit(Entity<FakeMindShieldComponent> ent, ref MapInitEvent args)
{
if (!ent.Comp.IsInnate)
return;
_actions.AddAction(ent.Owner, ent.Comp.Action);
_mindShields.RefreshMindshieldStatus(ent.Owner);
}
[SubscribeLocalEvent]
private void OnQueryStatus(Entity<FakeMindShieldComponent> ent, ref GetMindShieldStatusEvent args)
{
args.IsVisible |= ent.Comp.IsEnabled;
}
[SubscribeLocalEvent]
private void OnToggleMindshield(Entity<FakeMindShieldComponent> ent, ref FakeMindShieldToggleEvent args)
{
if (args.ActionTag != ent.Comp.ActionTag)
return;
ent.Comp.IsEnabled = !ent.Comp.IsEnabled;
args.Toggle = true;
args.Handled = true;
ShowTogglePopup(ent, args.Performer);
Dirty(ent.Owner, ent.Comp);
_mindShields.RefreshMindshieldStatus(args.Performer);
}
[SubscribeLocalEvent]
private void OnChameleonControllerOutfitSelected(Entity<FakeMindShieldComponent> ent, ref ChameleonControllerOutfitSelectedEvent args)
{
HandleChameleonOutfit(ent, ent.Comp, ent.Owner, ent.Owner, ref args);
}
private void OnChameleonControllerOutfitSelectedImplant(Entity<FakeMindShieldComponent> ent, ref ChameleonControllerOutfitSelectedEvent args, EntityUid implantedEntity)
{
HandleChameleonOutfit(ent, ent.Comp, implantedEntity, implantedEntity, ref args);
}
private void HandleChameleonOutfit(EntityUid fakeMindshieldUid, FakeMindShieldComponent component, EntityUid actionOwner, EntityUid statusOwner, ref ChameleonControllerOutfitSelectedEvent args)
{
if (!component.ChameleonControllable)
return;
if (component.IsEnabled == args.ChameleonOutfit.HasMindShield)
return;
// This assumes there is only one fake mindshield action per entity (This is currently enforced)
if (!TryComp<ActionsComponent>(actionOwner, out var actionsComp))
return;
// In case the fake mindshield ever doesn't have an action.
var actionFound = false;
foreach (var action in actionsComp.Actions)
{
if (!_tag.HasTag(action, component.ActionTag))
continue;
if (!TryComp<ActionComponent>(action, out var actionComp))
continue;
actionFound = true;
if (_actions.IsCooldownActive(actionComp, _timing.CurTime))
continue;
component.IsEnabled = args.ChameleonOutfit.HasMindShield;
_actions.SetToggled(action, args.ChameleonOutfit.HasMindShield);
Dirty(fakeMindshieldUid, component);
if (actionComp.UseDelay != null)
_actions.SetCooldown(action, actionComp.UseDelay.Value);
_mindShields.RefreshMindshieldStatus(statusOwner);
return;
}
// If they don't have the action for some reason, still set it correctly.
if (!actionFound)
{
component.IsEnabled = args.ChameleonOutfit.HasMindShield;
Dirty(fakeMindshieldUid, component);
_mindShields.RefreshMindshieldStatus(statusOwner);
}
}
}
/// <summary>
/// Inventory relayed event telling all fake mindshields with the same ActionTag to try to toggle themselves.
/// </summary>
public sealed partial class FakeMindShieldToggleEvent : InstantActionEvent, IInventoryRelayEvent
{
public SlotFlags TargetSlots => SlotFlags.WITHOUT_POCKET;
/// <summary>
/// The tag the fake mindshield needs to have to be successfully toggled.
/// We seperate it out to allow an entity to, for example, have an implant one and a store bought one without conflicts.
/// </summary>
[DataField]
public ProtoId<TagPrototype> ActionTag = "FakeMindShieldImplant";
}