seperate Stealth and StealthOnMove (#12035)
This commit is contained in:
@@ -5,8 +5,9 @@ using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
namespace Content.Shared.Stealth.Components;
|
||||
/// <summary>
|
||||
/// Add this component to an entity that you want to be cloaked.
|
||||
/// It overlays a shader on the entity to give them an invisibility cloaked effect
|
||||
/// It also turns the entity invisible
|
||||
/// It overlays a shader on the entity to give them an invisibility cloaked effect.
|
||||
/// It also turns the entity invisible.
|
||||
/// Use other components (like StealthOnMove) to modify this component's visibility based on certain conditions.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedStealthSystem))]
|
||||
@@ -35,6 +36,7 @@ public sealed class StealthComponent : Component
|
||||
/// outside of this range simply act as a buffer for the visual effect (i.e., a delay before turning invisible). To
|
||||
/// get the actual current visibility, use <see cref="SharedStealthSystem.GetVisibility(EntityUid,
|
||||
/// StealthComponent?)"/>
|
||||
/// If you don't have anything else updating the stealth, this will just stay at a constant value, which can be useful.
|
||||
/// </summary>
|
||||
[DataField("lastVisibility")]
|
||||
[Access(typeof(SharedStealthSystem), Other = AccessPermissions.None)]
|
||||
@@ -48,18 +50,6 @@ public sealed class StealthComponent : Component
|
||||
[DataField("lastUpdate", customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan? LastUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Rate that effects how fast an entity's visibility passively changes.
|
||||
/// </summary>
|
||||
[DataField("passiveVisibilityRate")]
|
||||
public readonly float PassiveVisibilityRate = -0.15f;
|
||||
|
||||
/// <summary>
|
||||
/// Rate for movement induced visibility changes. Scales with distance moved.
|
||||
/// </summary>
|
||||
[DataField("movementVisibilityRate")]
|
||||
public readonly float MovementVisibilityRate = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum visibility. Note that the visual effect caps out at -1, but this value is allowed to be larger or smaller.
|
||||
/// </summary>
|
||||
|
||||
22
Content.Shared/Stealth/Components/StealthOnMoveComponent.cs
Normal file
22
Content.Shared/Stealth/Components/StealthOnMoveComponent.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace Content.Shared.Stealth.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// When added to an entity with stealth component, this component will change the visibility
|
||||
/// based on the entity's (lack of) movement.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class StealthOnMoveComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Rate that effects how fast an entity's visibility passively changes.
|
||||
/// </summary>
|
||||
[DataField("passiveVisibilityRate")]
|
||||
public readonly float PassiveVisibilityRate = -0.15f;
|
||||
|
||||
/// <summary>
|
||||
/// Rate for movement induced visibility changes. Scales with distance moved.
|
||||
/// </summary>
|
||||
[DataField("movementVisibilityRate")]
|
||||
public readonly float MovementVisibilityRate = 0.2f;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ public abstract class SharedStealthSystem : EntitySystem
|
||||
|
||||
SubscribeLocalEvent<StealthComponent, ComponentGetState>(OnStealthGetState);
|
||||
SubscribeLocalEvent<StealthComponent, ComponentHandleState>(OnStealthHandleState);
|
||||
SubscribeLocalEvent<StealthComponent, MoveEvent>(OnMove);
|
||||
SubscribeLocalEvent<StealthOnMoveComponent, MoveEvent>(OnMove);
|
||||
SubscribeLocalEvent<StealthOnMoveComponent, GetVisibilityModifiersEvent>(OnGetVisibilityModifiers);
|
||||
SubscribeLocalEvent<StealthComponent, EntityPausedEvent>(OnPaused);
|
||||
SubscribeLocalEvent<StealthComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<StealthComponent, ExamineAttemptEvent>(OnExamine);
|
||||
@@ -87,7 +88,7 @@ public abstract class SharedStealthSystem : EntitySystem
|
||||
component.LastUpdated = cast.LastUpdated;
|
||||
}
|
||||
|
||||
private void OnMove(EntityUid uid, StealthComponent component, ref MoveEvent args)
|
||||
private void OnMove(EntityUid uid, StealthOnMoveComponent component, ref MoveEvent args)
|
||||
{
|
||||
if (args.FromStateHandling)
|
||||
return;
|
||||
@@ -96,7 +97,13 @@ public abstract class SharedStealthSystem : EntitySystem
|
||||
return;
|
||||
|
||||
var delta = component.MovementVisibilityRate * (args.NewPosition.Position - args.OldPosition.Position).Length;
|
||||
ModifyVisibility(uid, delta, component);
|
||||
ModifyVisibility(uid, delta);
|
||||
}
|
||||
|
||||
private void OnGetVisibilityModifiers(EntityUid uid, StealthOnMoveComponent component, GetVisibilityModifiersEvent args)
|
||||
{
|
||||
var mod = args.SecondsSinceUpdate * component.PassiveVisibilityRate;
|
||||
args.FlatModifier += mod;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,6 +157,32 @@ public abstract class SharedStealthSystem : EntitySystem
|
||||
return component.LastVisibility;
|
||||
|
||||
var deltaTime = _timing.CurTime - component.LastUpdated.Value;
|
||||
return Math.Clamp(component.LastVisibility + (float) deltaTime.TotalSeconds * component.PassiveVisibilityRate, component.MinVisibility, component.MaxVisibility);
|
||||
|
||||
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 = default!;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
state: agentbox
|
||||
state_open: cardboard_open
|
||||
- type: Stealth
|
||||
- type: StealthOnMove
|
||||
passiveVisibilityRate: -0.24
|
||||
movementVisibilityRate: 0.10
|
||||
|
||||
|
||||
Reference in New Issue
Block a user