2022-03-12 16:20:31 -06:00
|
|
|
using Content.Shared.Audio;
|
2025-03-21 02:43:35 -07:00
|
|
|
using Content.Shared.Construction.Components;
|
2023-07-05 03:29:57 +03:00
|
|
|
using Content.Shared.Explosion;
|
2025-03-21 00:57:04 +11:00
|
|
|
using Content.Shared.Eye;
|
2022-02-16 15:34:31 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2019-04-04 15:09:06 +02:00
|
|
|
using Content.Shared.Maps;
|
2025-03-21 02:43:35 -07:00
|
|
|
using Content.Shared.Popups;
|
2021-04-09 16:46:45 +02:00
|
|
|
using JetBrains.Annotations;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.Map;
|
2022-11-22 13:12:04 +11:00
|
|
|
using Robust.Shared.Map.Components;
|
2021-08-01 04:50:36 +02:00
|
|
|
using Robust.Shared.Serialization;
|
2019-04-04 15:09:06 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.SubFloor
|
2019-04-04 15:09:06 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Entity system backing <see cref="SubFloorHideComponent"/>.
|
|
|
|
|
/// </summary>
|
2021-04-09 16:46:45 +02:00
|
|
|
[UsedImplicitly]
|
2022-02-14 16:20:35 +13:00
|
|
|
public abstract class SharedSubFloorHideSystem : EntitySystem
|
2019-04-04 15:09:06 +02:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
2022-03-12 16:20:31 -06:00
|
|
|
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
|
2024-09-29 02:27:47 +03:00
|
|
|
[Dependency] protected readonly SharedMapSystem Map = default!;
|
2022-08-28 13:26:35 +10:00
|
|
|
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
2025-03-21 00:57:04 +11:00
|
|
|
[Dependency] private readonly SharedVisibilitySystem _visibility = default!;
|
2025-03-21 02:43:35 -07:00
|
|
|
[Dependency] protected readonly SharedPopupSystem _popup = default!;
|
2025-03-21 00:57:04 +11:00
|
|
|
|
|
|
|
|
private EntityQuery<SubFloorHideComponent> _hideQuery;
|
2020-04-20 09:44:21 +02:00
|
|
|
|
2019-04-04 15:09:06 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2025-03-21 00:57:04 +11:00
|
|
|
_hideQuery = GetEntityQuery<SubFloorHideComponent>();
|
|
|
|
|
|
2022-03-28 08:23:33 +02:00
|
|
|
SubscribeLocalEvent<TileChangedEvent>(OnTileChanged);
|
2021-05-27 11:11:56 +02:00
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, ComponentStartup>(OnSubFloorStarted);
|
|
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, ComponentShutdown>(OnSubFloorTerminating);
|
2022-04-24 13:54:25 +10:00
|
|
|
// Like 80% sure this doesn't need to handle re-anchoring.
|
2021-06-19 19:41:26 -07:00
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, AnchorStateChangedEvent>(HandleAnchorChanged);
|
2022-02-16 15:34:31 +13:00
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, GettingInteractedWithAttemptEvent>(OnInteractionAttempt);
|
2022-12-17 14:47:15 +11:00
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, GettingAttackedAttemptEvent>(OnAttackAttempt);
|
2023-07-05 03:29:57 +03:00
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, GetExplosionResistanceEvent>(OnGetExplosionResistance);
|
2025-03-21 02:43:35 -07:00
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, AnchorAttemptEvent>(OnAnchorAttempt);
|
|
|
|
|
SubscribeLocalEvent<SubFloorHideComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAnchorAttempt(EntityUid uid, SubFloorHideComponent component, AnchorAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
// No teleporting entities through floor tiles when anchoring them.
|
|
|
|
|
var xform = Transform(uid);
|
|
|
|
|
|
|
|
|
|
if (TryComp<MapGridComponent>(xform.GridUid, out var grid)
|
|
|
|
|
&& HasFloorCover(xform.GridUid.Value, grid, Map.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates)))
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupClient(Loc.GetString("subfloor-anchor-failure", ("entity", uid)), args.User);
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUnanchorAttempt(EntityUid uid, SubFloorHideComponent component, UnanchorAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
// No un-anchoring things under the floor. Only required for something like vents, which are still interactable
|
|
|
|
|
// despite being partially under the floor.
|
|
|
|
|
if (component.IsUnderCover)
|
|
|
|
|
{
|
|
|
|
|
_popup.PopupClient(Loc.GetString("subfloor-unanchor-failure", ("entity", uid)), args.User);
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
2023-07-05 03:29:57 +03:00
|
|
|
}
|
|
|
|
|
|
2023-09-17 19:04:04 +10:00
|
|
|
private void OnGetExplosionResistance(EntityUid uid, SubFloorHideComponent component, ref GetExplosionResistanceEvent args)
|
2023-07-05 03:29:57 +03:00
|
|
|
{
|
|
|
|
|
if (component.BlockInteractions && component.IsUnderCover)
|
|
|
|
|
args.DamageCoefficient = 0;
|
2022-12-17 14:47:15 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAttackAttempt(EntityUid uid, SubFloorHideComponent component, ref GettingAttackedAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (component.BlockInteractions && component.IsUnderCover)
|
|
|
|
|
args.Cancelled = true;
|
2021-04-09 16:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-19 02:30:41 +12:00
|
|
|
private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, ref GettingInteractedWithAttemptEvent args)
|
2021-12-13 23:46:47 -08:00
|
|
|
{
|
2022-02-16 15:34:31 +13:00
|
|
|
// No interactions with entities hidden under floor tiles.
|
|
|
|
|
if (component.BlockInteractions && component.IsUnderCover)
|
2024-06-19 02:30:41 +12:00
|
|
|
args.Cancelled = true;
|
2021-12-13 23:46:47 -08:00
|
|
|
}
|
|
|
|
|
|
2021-05-27 11:11:56 +02:00
|
|
|
private void OnSubFloorStarted(EntityUid uid, SubFloorHideComponent component, ComponentStartup _)
|
2019-04-04 15:09:06 +02:00
|
|
|
{
|
2022-02-12 12:00:33 +13:00
|
|
|
UpdateFloorCover(uid, component);
|
|
|
|
|
UpdateAppearance(uid, component);
|
2021-10-10 13:17:07 +11:00
|
|
|
EntityManager.EnsureComponent<CollideOnAnchorComponent>(uid);
|
2021-04-09 16:46:45 +02:00
|
|
|
}
|
2020-06-22 21:02:50 -04:00
|
|
|
|
2021-05-27 11:11:56 +02:00
|
|
|
private void OnSubFloorTerminating(EntityUid uid, SubFloorHideComponent component, ComponentShutdown _)
|
2021-04-09 16:46:45 +02:00
|
|
|
{
|
2021-10-10 13:17:07 +11:00
|
|
|
// If component is being deleted don't need to worry about updating any component stuff because it won't matter very shortly.
|
2021-12-04 14:14:22 +01:00
|
|
|
if (EntityManager.GetComponent<MetaDataComponent>(uid).EntityLifeStage >= EntityLifeStage.Terminating)
|
|
|
|
|
return;
|
2021-10-10 13:17:07 +11:00
|
|
|
|
2021-07-10 11:04:16 +02:00
|
|
|
// Regardless of whether we're on a subfloor or not, unhide.
|
2025-03-21 00:57:04 +11:00
|
|
|
SetUnderCover((uid, component), false);
|
2022-02-12 12:00:33 +13:00
|
|
|
UpdateAppearance(uid, component);
|
2021-04-09 16:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-21 11:49:31 +02:00
|
|
|
private void HandleAnchorChanged(EntityUid uid, SubFloorHideComponent component, ref AnchorStateChangedEvent args)
|
2021-04-09 16:46:45 +02:00
|
|
|
{
|
2022-02-12 12:00:33 +13:00
|
|
|
if (args.Anchored)
|
|
|
|
|
{
|
|
|
|
|
var xform = Transform(uid);
|
|
|
|
|
UpdateFloorCover(uid, component, xform);
|
|
|
|
|
}
|
|
|
|
|
else if (component.IsUnderCover)
|
|
|
|
|
{
|
2025-03-21 00:57:04 +11:00
|
|
|
SetUnderCover((uid, component), false);
|
2022-02-12 12:00:33 +13:00
|
|
|
UpdateAppearance(uid, component);
|
|
|
|
|
}
|
2019-04-04 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-09 13:45:21 +11:00
|
|
|
private void OnTileChanged(ref TileChangedEvent args)
|
2021-08-02 13:53:33 +02:00
|
|
|
{
|
2025-05-15 06:26:47 -04:00
|
|
|
foreach (var change in args.Changes)
|
|
|
|
|
{
|
|
|
|
|
if (change.OldTile.IsEmpty)
|
2025-05-16 22:22:20 +10:00
|
|
|
continue; // Nothing is anchored here anyways.
|
2021-08-02 13:53:33 +02:00
|
|
|
|
2025-05-15 06:26:47 -04:00
|
|
|
if (change.NewTile.IsEmpty)
|
2025-05-16 22:22:20 +10:00
|
|
|
continue; // Anything that was here will be unanchored anyways.
|
2021-08-02 13:53:33 +02:00
|
|
|
|
2025-05-15 06:26:47 -04:00
|
|
|
UpdateTile(args.Entity, args.Entity.Comp, change.GridIndices);
|
|
|
|
|
}
|
2019-04-04 15:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 12:00:33 +13:00
|
|
|
/// <summary>
|
|
|
|
|
/// Update whether a given entity is currently covered by a floor tile.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void UpdateFloorCover(EntityUid uid, SubFloorHideComponent? component = null, TransformComponent? xform = null)
|
2021-04-09 16:46:45 +02:00
|
|
|
{
|
2022-02-12 12:00:33 +13:00
|
|
|
if (!Resolve(uid, ref component, ref xform))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-03-22 03:08:40 -04:00
|
|
|
if (xform.Anchored && TryComp<MapGridComponent>(xform.GridUid, out var grid))
|
2025-03-21 00:57:04 +11:00
|
|
|
SetUnderCover((uid, component), HasFloorCover(xform.GridUid.Value, grid, Map.TileIndicesFor(xform.GridUid.Value, grid, xform.Coordinates)));
|
2022-02-12 12:00:33 +13:00
|
|
|
else
|
2025-03-21 00:57:04 +11:00
|
|
|
SetUnderCover((uid, component), false);
|
2022-02-12 12:00:33 +13:00
|
|
|
|
|
|
|
|
UpdateAppearance(uid, component);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 00:57:04 +11:00
|
|
|
private void SetUnderCover(Entity<SubFloorHideComponent> entity, bool value)
|
|
|
|
|
{
|
|
|
|
|
// If it's not undercover or it always has visible layers then normal visibility.
|
|
|
|
|
_visibility.SetLayer(entity.Owner, value && entity.Comp.VisibleLayers.Count == 0 ? (ushort) VisibilityFlags.Subfloor : (ushort) VisibilityFlags.Normal);
|
|
|
|
|
|
|
|
|
|
if (entity.Comp.IsUnderCover == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
entity.Comp.IsUnderCover = value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-29 02:27:47 +03:00
|
|
|
public bool HasFloorCover(EntityUid gridUid, MapGridComponent grid, Vector2i position)
|
2022-02-12 12:00:33 +13:00
|
|
|
{
|
|
|
|
|
// TODO Redo this function. Currently wires on an asteroid are always "below the floor"
|
2024-09-29 02:27:47 +03:00
|
|
|
var tileDef = (ContentTileDefinition) _tileDefinitionManager[Map.GetTileRef(gridUid, grid, position).Tile.TypeId];
|
2022-02-12 12:00:33 +13:00
|
|
|
return !tileDef.IsSubFloor;
|
2021-07-10 11:04:16 +02:00
|
|
|
}
|
2021-04-09 16:46:45 +02:00
|
|
|
|
2024-09-29 02:27:47 +03:00
|
|
|
private void UpdateTile(EntityUid gridUid, MapGridComponent grid, Vector2i position)
|
2019-04-04 15:09:06 +02:00
|
|
|
{
|
2024-09-29 02:27:47 +03:00
|
|
|
var covered = HasFloorCover(gridUid, grid, position);
|
2021-07-10 11:04:16 +02:00
|
|
|
|
2024-09-29 02:27:47 +03:00
|
|
|
foreach (var uid in Map.GetAnchoredEntities(gridUid, grid, position))
|
2021-07-10 11:04:16 +02:00
|
|
|
{
|
2025-03-21 00:57:04 +11:00
|
|
|
if (!_hideQuery.TryComp(uid, out var hideComp))
|
2022-02-12 12:00:33 +13:00
|
|
|
continue;
|
2021-07-10 11:04:16 +02:00
|
|
|
|
2022-02-12 12:00:33 +13:00
|
|
|
if (hideComp.IsUnderCover == covered)
|
|
|
|
|
continue;
|
2021-07-30 12:25:58 +02:00
|
|
|
|
2025-03-21 00:57:04 +11:00
|
|
|
SetUnderCover((uid, hideComp), covered);
|
2022-02-12 12:00:33 +13:00
|
|
|
UpdateAppearance(uid, hideComp);
|
2019-04-04 15:09:06 +02:00
|
|
|
}
|
2021-07-10 11:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-14 16:20:35 +13:00
|
|
|
public void UpdateAppearance(
|
|
|
|
|
EntityUid uid,
|
|
|
|
|
SubFloorHideComponent? hideComp = null,
|
|
|
|
|
AppearanceComponent? appearance = null)
|
2022-02-12 12:00:33 +13:00
|
|
|
{
|
2022-08-28 13:26:35 +10:00
|
|
|
if (!Resolve(uid, ref hideComp, false))
|
2022-02-12 12:00:33 +13:00
|
|
|
return;
|
2021-12-13 23:46:47 -08:00
|
|
|
|
2022-03-12 16:20:31 -06:00
|
|
|
if (hideComp.BlockAmbience && hideComp.IsUnderCover)
|
|
|
|
|
_ambientSoundSystem.SetAmbience(uid, false);
|
|
|
|
|
else if (hideComp.BlockAmbience && !hideComp.IsUnderCover)
|
|
|
|
|
_ambientSoundSystem.SetAmbience(uid, true);
|
2022-08-28 13:26:35 +10:00
|
|
|
|
|
|
|
|
if (Resolve(uid, ref appearance, false))
|
|
|
|
|
{
|
|
|
|
|
Appearance.SetData(uid, SubFloorVisuals.Covered, hideComp.IsUnderCover, appearance);
|
|
|
|
|
}
|
2021-12-13 23:46:47 -08:00
|
|
|
}
|
2025-03-21 00:57:04 +11:00
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
protected sealed class ShowSubfloorRequestEvent : EntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
public bool Value;
|
|
|
|
|
}
|
2019-04-04 15:09:06 +02:00
|
|
|
}
|
2021-08-01 04:50:36 +02:00
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
public enum SubFloorVisuals : byte
|
|
|
|
|
{
|
2023-03-31 14:40:38 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Is there a floor tile over this entity
|
|
|
|
|
/// </summary>
|
|
|
|
|
Covered,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Is this entity revealed by a scanner or some other entity?
|
|
|
|
|
/// </summary>
|
|
|
|
|
ScannerRevealed,
|
2021-08-01 04:50:36 +02:00
|
|
|
}
|
2022-07-09 21:59:39 +12:00
|
|
|
|
|
|
|
|
public enum SubfloorLayers : byte
|
|
|
|
|
{
|
|
|
|
|
FirstLayer
|
|
|
|
|
}
|
2019-04-04 15:09:06 +02:00
|
|
|
}
|