Misc stealth and box changes (#11809)
* git mv * Disable shader while box is open * Hide entity menu / prevent examine * fix recursion fix recursion fix recursion fix recursion * Better visibility checks * min and max visibility fields * fix reference point
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Client.Verbs;
|
|||||||
using Content.Client.Viewport;
|
using Content.Client.Viewport;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.CombatMode;
|
using Content.Shared.CombatMode;
|
||||||
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
@@ -20,6 +21,7 @@ using Robust.Shared.Input;
|
|||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ namespace Content.Client.ContextMenu.UI
|
|||||||
|
|
||||||
private readonly VerbSystem _verbSystem;
|
private readonly VerbSystem _verbSystem;
|
||||||
private readonly ExamineSystem _examineSystem;
|
private readonly ExamineSystem _examineSystem;
|
||||||
|
private readonly TransformSystem _xform;
|
||||||
private readonly SharedCombatModeSystem _combatMode;
|
private readonly SharedCombatModeSystem _combatMode;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,6 +67,7 @@ namespace Content.Client.ContextMenu.UI
|
|||||||
_verbSystem = verbSystem;
|
_verbSystem = verbSystem;
|
||||||
_examineSystem = _entityManager.EntitySysManager.GetEntitySystem<ExamineSystem>();
|
_examineSystem = _entityManager.EntitySysManager.GetEntitySystem<ExamineSystem>();
|
||||||
_combatMode = _entityManager.EntitySysManager.GetEntitySystem<CombatModeSystem>();
|
_combatMode = _entityManager.EntitySysManager.GetEntitySystem<CombatModeSystem>();
|
||||||
|
_xform = _entityManager.EntitySysManager.GetEntitySystem<TransformSystem>();
|
||||||
|
|
||||||
_cfg.OnValueChanged(CCVars.EntityMenuGroupingType, OnGroupingChanged, true);
|
_cfg.OnValueChanged(CCVars.EntityMenuGroupingType, OnGroupingChanged, true);
|
||||||
|
|
||||||
@@ -191,9 +195,24 @@ namespace Content.Client.ContextMenu.UI
|
|||||||
var ignoreFov = !_eyeManager.CurrentEye.DrawFov ||
|
var ignoreFov = !_eyeManager.CurrentEye.DrawFov ||
|
||||||
(_verbSystem.Visibility & MenuVisibility.NoFov) == MenuVisibility.NoFov;
|
(_verbSystem.Visibility & MenuVisibility.NoFov) == MenuVisibility.NoFov;
|
||||||
|
|
||||||
|
_entityManager.TryGetComponent(player, out ExaminerComponent? examiner);
|
||||||
|
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
foreach (var entity in Elements.Keys.ToList())
|
foreach (var entity in Elements.Keys.ToList())
|
||||||
{
|
{
|
||||||
if (_entityManager.Deleted(entity) || !ignoreFov && !_examineSystem.CanExamine(player, entity))
|
if (!xformQuery.TryGetComponent(entity, out var xform))
|
||||||
|
{
|
||||||
|
// entity was deleted
|
||||||
|
RemoveEntity(entity);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ignoreFov)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var pos = new MapCoordinates(_xform.GetWorldPosition(xform, xformQuery), xform.MapID);
|
||||||
|
|
||||||
|
if (!_examineSystem.CanExamine(player, pos, e => e == player || e == entity, entity, examiner))
|
||||||
RemoveEntity(entity);
|
RemoveEntity(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,13 +63,23 @@ namespace Content.Client.Examine
|
|||||||
base.Shutdown();
|
base.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null)
|
public override bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null, EntityUid? examined = null, ExaminerComponent? examinerComp = null)
|
||||||
{
|
{
|
||||||
var b = _eyeManager.GetWorldViewbounds();
|
if (!Resolve(examiner, ref examinerComp, false))
|
||||||
if (!b.Contains(target.Position))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return base.CanExamine(examiner, target, predicate);
|
if (examinerComp.SkipChecks)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (examinerComp.CheckInRangeUnOccluded)
|
||||||
|
{
|
||||||
|
// TODO fix this. This should be using the examiner's eye component, not eye manager.
|
||||||
|
var b = _eyeManager.GetWorldViewbounds();
|
||||||
|
if (!b.Contains(target.Position))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.CanExamine(examiner, target, predicate, examined, examinerComp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HandleExamine(in PointerInputCmdHandler.PointerInputCmdArgs args)
|
private bool HandleExamine(in PointerInputCmdHandler.PointerInputCmdArgs args)
|
||||||
|
|||||||
@@ -22,35 +22,48 @@ public sealed class StealthSystem : SharedStealthSystem
|
|||||||
SubscribeLocalEvent<StealthComponent, BeforePostShaderRenderEvent>(OnShaderRender);
|
SubscribeLocalEvent<StealthComponent, BeforePostShaderRenderEvent>(OnShaderRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnInit(EntityUid uid, StealthComponent component, ComponentInit args)
|
public override void SetEnabled(EntityUid uid, bool value, StealthComponent? component = null)
|
||||||
{
|
{
|
||||||
base.OnInit(uid, component, args);
|
if (!Resolve(uid, ref component) || component.Enabled == value)
|
||||||
if (!TryComp(uid, out SpriteComponent? sprite))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprite.PostShader = _shader;
|
base.SetEnabled(uid, value, component);
|
||||||
sprite.GetScreenTexture = true;
|
SetShader(uid, value, component);
|
||||||
sprite.RaiseShaderEvent = true;
|
}
|
||||||
|
|
||||||
|
private void SetShader(EntityUid uid, bool enabled, StealthComponent? component = null, SpriteComponent? sprite = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component, ref sprite, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
sprite.Color = Color.White;
|
||||||
|
sprite.PostShader = enabled ? _shader : null;
|
||||||
|
sprite.GetScreenTexture = enabled;
|
||||||
|
sprite.RaiseShaderEvent = enabled;
|
||||||
|
|
||||||
|
if (!enabled)
|
||||||
|
{
|
||||||
|
if (component.HadOutline)
|
||||||
|
AddComp<InteractionOutlineComponent>(uid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (TryComp(uid, out InteractionOutlineComponent? outline))
|
if (TryComp(uid, out InteractionOutlineComponent? outline))
|
||||||
{
|
{
|
||||||
RemComp(uid, outline);
|
RemCompDeferred(uid, outline);
|
||||||
component.HadOutline = true;
|
component.HadOutline = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnInit(EntityUid uid, StealthComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
base.OnInit(uid, component, args);
|
||||||
|
SetShader(uid, component.Enabled, component);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnRemove(EntityUid uid, StealthComponent component, ComponentRemove args)
|
private void OnRemove(EntityUid uid, StealthComponent component, ComponentRemove args)
|
||||||
{
|
{
|
||||||
if (!TryComp(uid, out SpriteComponent? sprite))
|
SetShader(uid, false, component);
|
||||||
return;
|
|
||||||
|
|
||||||
sprite.PostShader = null;
|
|
||||||
sprite.GetScreenTexture = false;
|
|
||||||
sprite.RaiseShaderEvent = false;
|
|
||||||
sprite.Color = Color.White;
|
|
||||||
|
|
||||||
if (component.HadOutline)
|
|
||||||
AddComp<InteractionOutlineComponent>(uid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnShaderRender(EntityUid uid, StealthComponent component, BeforePostShaderRenderEvent args)
|
private void OnShaderRender(EntityUid uid, StealthComponent component, BeforePostShaderRenderEvent args)
|
||||||
@@ -61,9 +74,17 @@ public sealed class StealthSystem : SharedStealthSystem
|
|||||||
// So we need to use relative screen coordinates. The reference frame we use is the parent's position on screen.
|
// So we need to use relative screen coordinates. The reference frame we use is the parent's position on screen.
|
||||||
// this ensures that if the Stealth is not moving relative to the parent, its relative screen position remains
|
// this ensures that if the Stealth is not moving relative to the parent, its relative screen position remains
|
||||||
// unchanged.
|
// unchanged.
|
||||||
var parentXform = Transform(Transform(uid).ParentUid);
|
var parent = Transform(uid).ParentUid;
|
||||||
|
if (!parent.IsValid())
|
||||||
|
return; // should never happen, but lets not kill the client.
|
||||||
|
var parentXform = Transform(parent);
|
||||||
var reference = args.Viewport.WorldToLocal(parentXform.WorldPosition);
|
var reference = args.Viewport.WorldToLocal(parentXform.WorldPosition);
|
||||||
|
reference.X = -reference.X;
|
||||||
var visibility = GetVisibility(uid, component);
|
var visibility = GetVisibility(uid, component);
|
||||||
|
|
||||||
|
// actual visual visibility effect is limited to +/- 1.
|
||||||
|
visibility = Math.Clamp(visibility, -1f, 1f);
|
||||||
|
|
||||||
_shader.SetParameter("reference", reference);
|
_shader.SetParameter("reference", reference);
|
||||||
_shader.SetParameter("visibility", visibility);
|
_shader.SetParameter("visibility", visibility);
|
||||||
|
|
||||||
|
|||||||
@@ -108,18 +108,34 @@ namespace Content.Client.Verbs
|
|||||||
? Visibility
|
? Visibility
|
||||||
: Visibility | MenuVisibility.NoFov;
|
: Visibility | MenuVisibility.NoFov;
|
||||||
|
|
||||||
|
|
||||||
|
// Get entities
|
||||||
|
List<EntityUid> entities;
|
||||||
|
|
||||||
// Do we have to do FoV checks?
|
// Do we have to do FoV checks?
|
||||||
if ((visibility & MenuVisibility.NoFov) == 0)
|
if ((visibility & MenuVisibility.NoFov) == 0)
|
||||||
{
|
{
|
||||||
var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos);
|
var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos);
|
||||||
bool Predicate(EntityUid e) => e == player || entitiesUnderMouse.Contains(e);
|
bool Predicate(EntityUid e) => e == player || entitiesUnderMouse.Contains(e);
|
||||||
|
|
||||||
|
// first check the general location.
|
||||||
if (!_examineSystem.CanExamine(player.Value, targetPos, Predicate))
|
if (!_examineSystem.CanExamine(player.Value, targetPos, Predicate))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Get entities
|
TryComp(player.Value, out ExaminerComponent? examiner);
|
||||||
var entities = _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize)
|
|
||||||
.ToList();
|
// Then check every entity
|
||||||
|
entities = new();
|
||||||
|
foreach (var ent in _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize))
|
||||||
|
{
|
||||||
|
if (_examineSystem.CanExamine(player.Value, targetPos, Predicate, ent, examiner))
|
||||||
|
entities.Add(ent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entities = _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
if (entities.Count == 0)
|
if (entities.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.CardboardBox.Components;
|
using Content.Shared.CardboardBox.Components;
|
||||||
using Content.Server.Storage.Components;
|
using Content.Server.Storage.Components;
|
||||||
using Content.Shared.CardboardBox;
|
using Content.Shared.CardboardBox;
|
||||||
@@ -6,6 +6,8 @@ using Content.Shared.Movement.Components;
|
|||||||
using Content.Shared.Movement.Systems;
|
using Content.Shared.Movement.Systems;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
using Content.Shared.Stealth.Components;
|
||||||
|
using Content.Shared.Stealth;
|
||||||
|
|
||||||
namespace Content.Server.CardboardBox;
|
namespace Content.Server.CardboardBox;
|
||||||
|
|
||||||
@@ -14,12 +16,14 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
|
|||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly SharedMoverController _mover = default!;
|
[Dependency] private readonly SharedMoverController _mover = default!;
|
||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
[Dependency] private readonly SharedStealthSystem _stealth = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<CardboardBoxComponent, StorageBeforeCloseEvent>(OnBeforeStorageClosed);
|
SubscribeLocalEvent<CardboardBoxComponent, StorageBeforeCloseEvent>(OnBeforeStorageClosed);
|
||||||
SubscribeLocalEvent<CardboardBoxComponent, StorageAfterOpenEvent>(AfterStorageOpen);
|
SubscribeLocalEvent<CardboardBoxComponent, StorageAfterOpenEvent>(AfterStorageOpen);
|
||||||
|
SubscribeLocalEvent<CardboardBoxComponent, StorageAfterCloseEvent>(AfterStorageClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBeforeStorageClosed(EntityUid uid, CardboardBoxComponent component, StorageBeforeCloseEvent args)
|
private void OnBeforeStorageClosed(EntityUid uid, CardboardBoxComponent component, StorageBeforeCloseEvent args)
|
||||||
@@ -57,5 +61,18 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
component.Mover = null;
|
component.Mover = null;
|
||||||
|
|
||||||
|
// If this box has a stealth/chameleon effect, disable the stealth effect while the box is open.
|
||||||
|
_stealth.SetEnabled(uid, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AfterStorageClosed(EntityUid uid, CardboardBoxComponent component, StorageAfterCloseEvent args)
|
||||||
|
{
|
||||||
|
// If this box has a stealth/chameleon effect, enable the stealth effect.
|
||||||
|
if (TryComp(uid, out StealthComponent? stealth))
|
||||||
|
{
|
||||||
|
_stealth.SetVisibility(uid, stealth.MaxVisibility, stealth);
|
||||||
|
_stealth.SetEnabled(uid, true, stealth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,16 +67,28 @@ namespace Content.Shared.Examine
|
|||||||
public bool CanExamine(EntityUid examiner, EntityUid examined)
|
public bool CanExamine(EntityUid examiner, EntityUid examined)
|
||||||
{
|
{
|
||||||
return !Deleted(examined) && CanExamine(examiner, EntityManager.GetComponent<TransformComponent>(examined).MapPosition,
|
return !Deleted(examined) && CanExamine(examiner, EntityManager.GetComponent<TransformComponent>(examined).MapPosition,
|
||||||
entity => entity == examiner || entity == examined);
|
entity => entity == examiner || entity == examined, examined);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Pure]
|
[Pure]
|
||||||
public virtual bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null)
|
public virtual bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null, EntityUid? examined = null, ExaminerComponent? examinerComp = null)
|
||||||
{
|
{
|
||||||
if (!EntityManager.TryGetComponent(examiner, out ExaminerComponent? examinerComponent))
|
if (!Resolve(examiner, ref examinerComp, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!examinerComponent.DoRangeCheck)
|
// Ghosts and admins skip examine checks.
|
||||||
|
if (examinerComp.SkipChecks)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (examined != null)
|
||||||
|
{
|
||||||
|
var ev = new ExamineAttemptEvent(examiner);
|
||||||
|
RaiseLocalEvent(examined.Value, ev);
|
||||||
|
if (ev.Cancelled)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!examinerComp.CheckInRangeUnOccluded)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (EntityManager.GetComponent<TransformComponent>(examiner).MapID != target.MapId)
|
if (EntityManager.GetComponent<TransformComponent>(examiner).MapID != target.MapId)
|
||||||
@@ -326,4 +338,17 @@ namespace Content.Shared.Examine
|
|||||||
PushMessage(msg);
|
PushMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event raised directed at an entity that someone is attempting to examine
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ExamineAttemptEvent : CancellableEntityEventArgs
|
||||||
|
{
|
||||||
|
public readonly EntityUid Examiner;
|
||||||
|
|
||||||
|
public ExamineAttemptEvent(EntityUid examiner)
|
||||||
|
{
|
||||||
|
Examiner = examiner;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,11 @@ namespace Content.Shared.Examine
|
|||||||
public sealed class ExaminerComponent : Component
|
public sealed class ExaminerComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("DoRangeCheck")]
|
[DataField("skipChecks")]
|
||||||
private bool _doRangeCheck = true;
|
public bool SkipChecks = false;
|
||||||
|
|
||||||
/// <summary>
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
/// Whether to do a distance check on examine.
|
[DataField("checkInRangeUnOccluded")]
|
||||||
/// If false, the user can theoretically examine from infinitely far away.
|
public bool CheckInRangeUnOccluded = true;
|
||||||
/// </summary>
|
|
||||||
public bool DoRangeCheck => _doRangeCheck;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ namespace Content.Shared.Stealth.Components;
|
|||||||
[Access(typeof(SharedStealthSystem))]
|
[Access(typeof(SharedStealthSystem))]
|
||||||
public sealed class StealthComponent : Component
|
public sealed class StealthComponent : Component
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not the stealth effect should currently be applied.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("enabled")]
|
||||||
|
public bool Enabled = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not the entity previously had an interaction outline prior to cloaking.
|
/// Whether or not the entity previously had an interaction outline prior to cloaking.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,12 +25,21 @@ public sealed class StealthComponent : Component
|
|||||||
public bool HadOutline;
|
public bool HadOutline;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Last set level of visibility. Ranges from 1 (fully visible) and -1 (fully hidden). To get the actual current
|
/// Minimum visibility before the entity becomes unexaminable (and thus no longer appears on context menus).
|
||||||
/// visibility, use <see cref="SharedStealthSystem.GetVisibility(EntityUid, StealthComponent?)"/>
|
/// </summary>
|
||||||
|
[DataField("examineThreshold")]
|
||||||
|
public readonly float ExamineThreshold = 0.5f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Last set level of visibility. The visual effect ranges from 1 (fully visible) and -1 (fully hidden). Values
|
||||||
|
/// 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?)"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("lastVisibility")]
|
[DataField("lastVisibility")]
|
||||||
[Access(typeof(SharedStealthSystem), Other = AccessPermissions.None)]
|
[Access(typeof(SharedStealthSystem), Other = AccessPermissions.None)]
|
||||||
public float LastVisibility;
|
public float LastVisibility = 1;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Time at which <see cref="LastVisibility"/> was set. Null implies the entity is currently paused and not
|
/// Time at which <see cref="LastVisibility"/> was set. Null implies the entity is currently paused and not
|
||||||
@@ -44,17 +59,31 @@ public sealed class StealthComponent : Component
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("movementVisibilityRate")]
|
[DataField("movementVisibilityRate")]
|
||||||
public readonly float MovementVisibilityRate = 0.2f;
|
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>
|
||||||
|
[DataField("minVisibility")]
|
||||||
|
public readonly float MinVisibility = -1f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum visibility. Note that the visual effect caps out at +1, but this value is allowed to be larger or smaller.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("maxVisibility")]
|
||||||
|
public readonly float MaxVisibility = 1.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class StealthComponentState : ComponentState
|
public sealed class StealthComponentState : ComponentState
|
||||||
{
|
{
|
||||||
public float Visibility;
|
public readonly float Visibility;
|
||||||
public TimeSpan? LastUpdated;
|
public readonly TimeSpan? LastUpdated;
|
||||||
|
public readonly bool Enabled;
|
||||||
|
|
||||||
public StealthComponentState(float stealthLevel, TimeSpan? lastUpdated)
|
public StealthComponentState(float stealthLevel, TimeSpan? lastUpdated, bool enabled)
|
||||||
{
|
{
|
||||||
Visibility = stealthLevel;
|
Visibility = stealthLevel;
|
||||||
LastUpdated = lastUpdated;
|
LastUpdated = lastUpdated;
|
||||||
|
Enabled = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Stealth.Components;
|
using Content.Shared.Stealth.Components;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -17,6 +18,35 @@ public abstract class SharedStealthSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<StealthComponent, MoveEvent>(OnMove);
|
SubscribeLocalEvent<StealthComponent, MoveEvent>(OnMove);
|
||||||
SubscribeLocalEvent<StealthComponent, EntityPausedEvent>(OnPaused);
|
SubscribeLocalEvent<StealthComponent, EntityPausedEvent>(OnPaused);
|
||||||
SubscribeLocalEvent<StealthComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<StealthComponent, ComponentInit>(OnInit);
|
||||||
|
SubscribeLocalEvent<StealthComponent, ExamineAttemptEvent>(OnExamine);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnExamine(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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPaused(EntityUid uid, StealthComponent component, EntityPausedEvent args)
|
private void OnPaused(EntityUid uid, StealthComponent component, EntityPausedEvent args)
|
||||||
@@ -44,7 +74,7 @@ public abstract class SharedStealthSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnStealthGetState(EntityUid uid, StealthComponent component, ref ComponentGetState args)
|
private void OnStealthGetState(EntityUid uid, StealthComponent component, ref ComponentGetState args)
|
||||||
{
|
{
|
||||||
args.State = new StealthComponentState(component.LastVisibility, component.LastUpdated);
|
args.State = new StealthComponentState(component.LastVisibility, component.LastUpdated, component.Enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStealthHandleState(EntityUid uid, StealthComponent component, ref ComponentHandleState args)
|
private void OnStealthHandleState(EntityUid uid, StealthComponent component, ref ComponentHandleState args)
|
||||||
@@ -52,6 +82,7 @@ public abstract class SharedStealthSystem : EntitySystem
|
|||||||
if (args.Current is not StealthComponentState cast)
|
if (args.Current is not StealthComponentState cast)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
SetEnabled(uid, cast.Enabled, component);
|
||||||
component.LastVisibility = cast.Visibility;
|
component.LastVisibility = cast.Visibility;
|
||||||
component.LastUpdated = cast.LastUpdated;
|
component.LastUpdated = cast.LastUpdated;
|
||||||
}
|
}
|
||||||
@@ -83,7 +114,7 @@ public abstract class SharedStealthSystem : EntitySystem
|
|||||||
component.LastUpdated = _timing.CurTime;
|
component.LastUpdated = _timing.CurTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
component.LastVisibility = Math.Clamp(component.LastVisibility + delta, -1f, 1f);
|
component.LastVisibility = Math.Clamp(component.LastVisibility + delta, component.MinVisibility, component.MaxVisibility);
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +127,7 @@ public abstract class SharedStealthSystem : EntitySystem
|
|||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
component.LastVisibility = value;
|
component.LastVisibility = Math.Clamp(value, component.MinVisibility, component.MaxVisibility);
|
||||||
if (component.LastUpdated != null)
|
if (component.LastUpdated != null)
|
||||||
component.LastUpdated = _timing.CurTime;
|
component.LastUpdated = _timing.CurTime;
|
||||||
|
|
||||||
@@ -107,16 +138,18 @@ public abstract class SharedStealthSystem : EntitySystem
|
|||||||
/// Gets the current visibility from the <see cref="StealthComponent"/>
|
/// Gets the current visibility from the <see cref="StealthComponent"/>
|
||||||
/// Use this instead of getting LastVisibility from the component directly.
|
/// Use this instead of getting LastVisibility from the component directly.
|
||||||
/// </summary>
|
/// </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.</returns>
|
/// <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)
|
public float GetVisibility(EntityUid uid, StealthComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component) || !component.Enabled)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (component.LastUpdated == null)
|
if (component.LastUpdated == null)
|
||||||
return component.LastVisibility;
|
return component.LastVisibility;
|
||||||
|
|
||||||
var deltaTime = _timing.CurTime - component.LastUpdated.Value;
|
var deltaTime = _timing.CurTime - component.LastUpdated.Value;
|
||||||
return Math.Clamp(component.LastVisibility + (float) deltaTime.TotalSeconds * component.PassiveVisibilityRate, -1f, 1f);
|
return Math.Clamp(component.LastVisibility + (float) deltaTime.TotalSeconds * component.PassiveVisibilityRate, component.MinVisibility, component.MaxVisibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
- type: Input
|
- type: Input
|
||||||
context: "ghost"
|
context: "ghost"
|
||||||
- type: Examiner
|
- type: Examiner
|
||||||
DoRangeCheck: false
|
skipChecks: true
|
||||||
- type: Ghost
|
- type: Ghost
|
||||||
- type: IntrinsicRadio
|
- type: IntrinsicRadio
|
||||||
channels:
|
channels:
|
||||||
|
|||||||
@@ -49,6 +49,7 @@
|
|||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: StealthBox
|
id: StealthBox
|
||||||
|
suffix: stealth
|
||||||
parent: BaseBigBox
|
parent: BaseBigBox
|
||||||
name: cardboard box #it's still just a box
|
name: cardboard box #it's still just a box
|
||||||
description: Kept ya waiting, huh?
|
description: Kept ya waiting, huh?
|
||||||
@@ -74,6 +75,7 @@
|
|||||||
- type: entity
|
- type: entity
|
||||||
id: GhostBox
|
id: GhostBox
|
||||||
parent: StealthBox
|
parent: StealthBox
|
||||||
|
suffix:
|
||||||
name: ghost box
|
name: ghost box
|
||||||
description: Beware!
|
description: Beware!
|
||||||
components:
|
components:
|
||||||
|
|||||||
Reference in New Issue
Block a user