Files
Delta-v/Content.Shared/Stealth/SharedStealthSystem.cs
T
CorynandJanet Blackquill cb62b27fcf Nubody (2/3) - ShitMed removal (#5844)
* Reapply "Nubody Merge" (#5807)

This reverts commit d62f7cef10.

* Revert "Nubody Merge (#5670)"

This reverts commit b465cfb3fd.

* Revert "IPC fibers (#4968)"

This reverts commit c2b42211f0.

* Revert "IPC Polymorph fix (#4545)"

This reverts commit fa03d8c655.

* Revert "fix IPC not having humanoid emotes (#4445)"

This reverts commit 216fdf999f.

* Revert "ipc heat/cold (#4306)"

This reverts commit fafd5cf816.

* Revert "ipc cables (#4283)"

This reverts commit 54958039a1.

* Revert "feat: ipcs now have dynamic power draw based off movement speed (#3917)"

This reverts commit 71e8b7e64b.

* Revert "fix ipcs not being able to disarm (#3374)"

This reverts commit 764c4dcf54.

* Revert "make steel heal caustic for ipcs (#3206)"

This reverts commit 450ac82550.

* Revert "add missing ipc survival boxes (#3065)"

This reverts commit 888c9cdb00.

* Revert "make borgs use ipc repairing (#3064)"

This reverts commit f77a49dd0b.

* Revert "Update hud.yml to add ipcs to diagnostic hud (#3019)"

This reverts commit 7220643531.

* Revert "Tweak IPCs (#2979)"

This reverts commit 98b47476de.

* Revert "fix nukies ipc test fail (#2957)"

This reverts commit 4a1acbf863.

* Revert "fix ipc nukies not getting comms (#2884)"

This reverts commit 8a2254770e.

* Revert "fix ipc encryption key mispredict (#2879)"

This reverts commit f08726efc1.

* Revert "Merge pull request #2800 from Spielern/port-ipc"

This reverts commit 822fa4312c, reversing
changes made to fe4c23c702.

* Remove and Fix rest of IPC Hangons causing crashes

* Integration test Errors

* Expand migration file with removed IPC stuff

* IPC Leg was found and migrated to naught

* Revert "Merge pull request #2542 from deltanedas/shitmed-ops"

This reverts commit 83a8002922, reversing
changes made to baa89b0052.

* Revert "Set up surgical augments infrastructure & add tool panel augments (#3059)"

This reverts commit a40f0be6fd.

* Revert "Psionic Prosthetics (#4689)"

This reverts commit 2679bb238a.

* Revert "Add surgical cleanliness and sanitation (#2847)"

This reverts commit 64565ba4f7.

* Remove unremoved mentions

* Revert "Add autoclave to easily sanitize large amounts of items and faster (#2933)"

This reverts commit d0da90fa2e.

* Shit Med Removed

* Remove _ShitMed Folders and fix Errors in Console

* Add OrganAnimalBrain into the mirgraiton file

* Heads no Input Mover

* Monke

* Full migration file I guess

* oops

* shiv state fix

* Restore accidental deleted recipe

* Forgot one flt mention

* Fix more issues

* Comment out Damage Visual for motorkind for now

* Motorkind...

* Commenting stuff out for now

* thought there'd be more of this to gut

---------

Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
2026-05-21 20:27:04 -04:00

212 lines
7.8 KiB
C#

using Content.Shared.Examine;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Content.Shared.Stealth.Components;
using Robust.Shared.GameStates;
using Robust.Shared.Timing;
namespace Content.Shared.Stealth;
public abstract class SharedStealthSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StealthComponent, ComponentGetState>(OnStealthGetState);
SubscribeLocalEvent<StealthComponent, ComponentHandleState>(OnStealthHandleState);
SubscribeLocalEvent<StealthOnMoveComponent, MoveEvent>(OnMove);
SubscribeLocalEvent<StealthOnMoveComponent, GetVisibilityModifiersEvent>(OnGetVisibilityModifiers);
SubscribeLocalEvent<StealthComponent, EntityPausedEvent>(OnPaused);
SubscribeLocalEvent<StealthComponent, EntityUnpausedEvent>(OnUnpaused);
SubscribeLocalEvent<StealthComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<StealthComponent, ExamineAttemptEvent>(OnExamineAttempt);
SubscribeLocalEvent<StealthComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<StealthComponent, MobStateChangedEvent>(OnMobStateChanged);
}
private void OnExamineAttempt(EntityUid uid, StealthComponent component, ExamineAttemptEvent args)
{
if (!component.Enabled || GetVisibility(uid, component) > component.ExamineThreshold)
return;
// Don't block examine for owner or children of the cloaked entity.
// Containers and the like should already block examining, so not bothering to check for occluding containers.
var source = args.Examiner;
do
{
if (source == uid)
return;
source = Transform(source).ParentUid;
}
while (source.IsValid());
args.Cancel();
}
private void OnExamined(EntityUid uid, StealthComponent component, ExaminedEvent args)
{
if (component.Enabled)
args.PushMarkup(Loc.GetString(component.ExaminedDesc, ("target", uid)));
}
public virtual void SetEnabled(EntityUid uid, bool value, StealthComponent? component = null)
{
if (!Resolve(uid, ref component, false) || component.Enabled == value)
return;
component.Enabled = value;
Dirty(uid, component);
}
private void OnMobStateChanged(EntityUid uid, StealthComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
{
component.Enabled = component.EnabledOnDeath;
}
else
{
component.Enabled = true;
}
Dirty(uid, component);
}
private void OnPaused(EntityUid uid, StealthComponent component, ref EntityPausedEvent args)
{
component.LastVisibility = GetVisibility(uid, component);
component.LastUpdated = null;
Dirty(uid, component);
}
private void OnUnpaused(EntityUid uid, StealthComponent component, ref EntityUnpausedEvent args)
{
component.LastUpdated = _timing.CurTime;
Dirty(uid, component);
}
protected virtual void OnInit(EntityUid uid, StealthComponent component, ComponentInit args)
{
if (component.LastUpdated != null || Paused(uid))
return;
component.LastUpdated = _timing.CurTime;
}
private void OnStealthGetState(EntityUid uid, StealthComponent component, ref ComponentGetState args)
{
args.State = new StealthComponentState(component.LastVisibility, component.LastUpdated, component.Enabled);
}
private void OnStealthHandleState(EntityUid uid, StealthComponent component, ref ComponentHandleState args)
{
if (args.Current is not StealthComponentState cast)
return;
SetEnabled(uid, cast.Enabled, component);
component.LastVisibility = cast.Visibility;
component.LastUpdated = cast.LastUpdated;
}
private void OnMove(EntityUid uid, StealthOnMoveComponent component, ref MoveEvent args)
{
if (_timing.ApplyingState)
return;
if (args.NewPosition.EntityId != args.OldPosition.EntityId)
return;
var delta = component.MovementVisibilityRate * (args.NewPosition.Position - args.OldPosition.Position).Length();
ModifyVisibility(uid, delta);
}
private void OnGetVisibilityModifiers(EntityUid uid, StealthOnMoveComponent component, GetVisibilityModifiersEvent args)
{
var mod = args.SecondsSinceUpdate * component.PassiveVisibilityRate;
args.FlatModifier += mod;
}
/// <summary>
/// Modifies the visibility based on the delta provided.
/// </summary>
/// <param name="delta">The delta to be used in visibility calculation.</param>
public void ModifyVisibility(EntityUid uid, float delta, StealthComponent? component = null)
{
if (delta == 0 || !Resolve(uid, ref component))
return;
if (component.LastUpdated != null)
{
component.LastVisibility = GetVisibility(uid, component);
component.LastUpdated = _timing.CurTime;
}
component.LastVisibility = Math.Clamp(component.LastVisibility + delta, component.MinVisibility, component.MaxVisibility);
Dirty(uid, component);
}
/// <summary>
/// Sets the visibility directly with no modifications
/// </summary>
/// <param name="value">The value to set the visibility to. -1 is fully invisible, 1 is fully visible</param>
public void SetVisibility(EntityUid uid, float value, StealthComponent? component = null)
{
if (!Resolve(uid, ref component))
return;
component.LastVisibility = Math.Clamp(value, component.MinVisibility, component.MaxVisibility);
if (component.LastUpdated != null)
component.LastUpdated = _timing.CurTime;
Dirty(uid, component);
}
/// <summary>
/// Gets the current visibility from the <see cref="StealthComponent"/>
/// Use this instead of getting LastVisibility from the component directly.
/// </summary>
/// <returns>Returns a calculation that accounts for any stealth change that happened since last update, otherwise
/// returns based on if it can resolve the component. Note that the returned value may be larger than the components
/// maximum stealth value if it is currently disabled.</returns>
public float GetVisibility(EntityUid uid, StealthComponent? component = null)
{
if (!Resolve(uid, ref component) || !component.Enabled)
return 1;
if (component.LastUpdated == null)
return component.LastVisibility;
var deltaTime = _timing.CurTime - component.LastUpdated.Value;
var ev = new GetVisibilityModifiersEvent(uid, component, (float) deltaTime.TotalSeconds, 0f);
RaiseLocalEvent(uid, ev, false);
return Math.Clamp(component.LastVisibility + ev.FlatModifier, component.MinVisibility, component.MaxVisibility);
}
/// <summary>
/// Used to run through any stealth effecting components on the entity.
/// </summary>
private sealed class GetVisibilityModifiersEvent : EntityEventArgs
{
public readonly StealthComponent Stealth;
public readonly float SecondsSinceUpdate;
/// <summary>
/// Calculate this and add to it. Do not divide, multiply, or overwrite.
/// The sum will be added to the stealth component's visibility.
/// </summary>
public float FlatModifier;
public GetVisibilityModifiersEvent(EntityUid uid, StealthComponent stealth, float secondsSinceUpdate, float flatModifier)
{
Stealth = stealth;
SecondsSinceUpdate = secondsSinceUpdate;
FlatModifier = flatModifier;
}
}
}