Files
wwdpublic/Content.Shared/Psionics/Abilities/PsionicInvisibility/PsionicInvisibleContactsSystem.cs
VMSolidus 687faec813 Fix Psionic Invisibility (#2223)
# Description

This PR fixes, refactors, and reworks the old Psionic Invisibility
Power, in order to make it comply with standards set by Psionic Refactor
V2. It's not at the level of V3, but I honestly don't care to since V3
is also deprecated now anyways. The newly reworked invisibility has
actual casting stat scaling with psionic amplification and dampening,
with a variably set duration and casting cooldown. It also now has new
exit conditions that deprecates the need to make it pacify the caster.

Yes I actually have tested and verified that this power works correctly.

# Changelog

🆑
- add: Reworked and fixed Psionic Invisibility. It now has actual
psychic casting stat scaling.

(cherry picked from commit 6674ec31a1d13be2d7d3ebb7ef452710d85bfe90)
2025-04-18 19:17:11 +03:00

68 lines
2.3 KiB
C#

using Content.Shared.Stealth;
using Content.Shared.Stealth.Components;
using Content.Shared.Whitelist;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
namespace Content.Shared.Psionics;
/// <summary>
/// Allows an entity to become psionically invisible when touching certain entities.
/// </summary>
public sealed class PsionicInvisibleContactsSystem : EntitySystem
{
[Dependency] private readonly SharedStealthSystem _stealth = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PsionicInvisibleContactsComponent, StartCollideEvent>(OnEntityEnter);
SubscribeLocalEvent<PsionicInvisibleContactsComponent, EndCollideEvent>(OnEntityExit);
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
}
private void OnEntityEnter(EntityUid uid, PsionicInvisibleContactsComponent component, ref StartCollideEvent args)
{
var otherUid = args.OtherEntity;
var ourEntity = args.OurEntity;
if (_whitelistSystem.IsWhitelistFail(component.Whitelist, otherUid))
return;
// This will go up twice per web hit, since webs also have a flammable fixture.
// It goes down twice per web exit, so everything's fine.
++component.Stages;
if (HasComp<PsionicallyInvisibleComponent>(ourEntity))
return;
EnsureComp<PsionicallyInvisibleComponent>(ourEntity);
var stealth = EnsureComp<StealthComponent>(ourEntity);
_stealth.SetVisibility(ourEntity, 0.66f, stealth);
}
private void OnEntityExit(EntityUid uid, PsionicInvisibleContactsComponent component, ref EndCollideEvent args)
{
var otherUid = args.OtherEntity;
var ourEntity = args.OurEntity;
if (_whitelistSystem.IsWhitelistFail(component.Whitelist, otherUid))
return;
if (!HasComp<PsionicallyInvisibleComponent>(ourEntity))
return;
if (--component.Stages > 0)
return;
RemComp<PsionicallyInvisibleComponent>(ourEntity);
var stealth = EnsureComp<StealthComponent>(ourEntity);
// Just to be sure...
_stealth.SetVisibility(ourEntity, 1f, stealth);
RemComp<StealthComponent>(ourEntity);
}
}