From 4e66cc69faafc06738a06203921b79beed749dab Mon Sep 17 00:00:00 2001 From: NR <66198468+withoutcode333@users.noreply.github.com> Date: Fri, 21 Mar 2025 02:20:37 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content.Client/Ghost/GhostSystem.cs | 21 +++++-- .../Commands/ShowGhostsCommand.cs | 6 +- Content.Server/Ghost/GhostSystem.cs | 62 +++++++++++-------- .../Revenant/EntitySystems/CorporealSystem.cs | 32 +--------- .../Revenant/EntitySystems/RevenantSystem.cs | 31 ---------- Content.Shared/Ghost/GhostComponent.cs | 7 ++- Content.Shared/Ghost/SharedGhostSystem.cs | 8 +++ .../Revenant/Components/CorporealComponent.cs | 3 + .../EntitySystems/SharedCorporealSystem.cs | 11 ++++ 9 files changed, 79 insertions(+), 102 deletions(-) diff --git a/Content.Client/Ghost/GhostSystem.cs b/Content.Client/Ghost/GhostSystem.cs index f8f0d0206a..8d930ccd5f 100644 --- a/Content.Client/Ghost/GhostSystem.cs +++ b/Content.Client/Ghost/GhostSystem.cs @@ -18,7 +18,7 @@ namespace Content.Client.Ghost public int AvailableGhostRoleCount { get; private set; } - private bool _ghostVisibility = true; + private bool _ghostVisibility; private bool GhostVisibility { @@ -33,9 +33,9 @@ namespace Content.Client.Ghost _ghostVisibility = value; var query = AllEntityQuery(); - while (query.MoveNext(out var uid, out _, out var sprite)) + while (query.MoveNext(out var uid, out var ghost, out var sprite)) { - sprite.Visible = value || uid == _playerManager.LocalEntity; + UpdateVisibility((uid, ghost, sprite)); } } } @@ -71,8 +71,15 @@ namespace Content.Client.Ghost private void OnStartup(EntityUid uid, GhostComponent component, ComponentStartup args) { - if (TryComp(uid, out SpriteComponent? sprite)) - sprite.Visible = GhostVisibility || uid == _playerManager.LocalEntity; + UpdateVisibility((uid, component)); + } + + private void UpdateVisibility(Entity ghost) + { + if (!Resolve(ghost.Owner, ref ghost.Comp1, ref ghost.Comp2)) + return; + + ghost.Comp2.Visible = GhostVisibility || ghost.Comp1.Visible || ghost.Owner == _playerManager.LocalEntity; } private void OnToggleLighting(EntityUid uid, EyeComponent component, ToggleLightingActionEvent args) @@ -131,7 +138,9 @@ namespace Content.Client.Ghost private void OnGhostState(EntityUid uid, GhostComponent component, ref AfterAutoHandleStateEvent args) { if (TryComp(uid, out var sprite)) - sprite.LayerSetColor(0, component.color); + sprite.LayerSetColor(0, component.Color); + + UpdateVisibility((uid, component, null)); if (uid != _playerManager.LocalEntity) return; diff --git a/Content.Server/Administration/Commands/ShowGhostsCommand.cs b/Content.Server/Administration/Commands/ShowGhostsCommand.cs index 2f8bf79e69..e1fb5e7a02 100644 --- a/Content.Server/Administration/Commands/ShowGhostsCommand.cs +++ b/Content.Server/Administration/Commands/ShowGhostsCommand.cs @@ -28,11 +28,7 @@ namespace Content.Server.Administration.Commands return; } - var ghostSys = _entities.EntitySysManager.GetEntitySystem(); - var revSys = _entities.EntitySysManager.GetEntitySystem(); - - ghostSys.MakeVisible(visible); - revSys.MakeVisible(visible); + _entities.System().MakeVisible(visible); } } } diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index 7d0123c70b..851098171b 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -208,6 +208,33 @@ namespace Content.Server.Ghost Dirty(uid, component); } + public override void SetVisible(Entity ghost, bool visible) + { + if (!Resolve(ghost.Owner, ref ghost.Comp)) + return; + + if (ghost.Comp.Visible == visible) + return; + + base.SetVisible(ghost, visible); + + if (!TryComp(ghost.Owner, out VisibilityComponent? visibility)) + return; + + if (visible) + { + _visibilitySystem.RemoveLayer((ghost.Owner, visibility), (int)VisibilityFlags.Ghost, false); + _visibilitySystem.AddLayer((ghost.Owner, visibility), (int)VisibilityFlags.Normal, false); + _visibilitySystem.RefreshVisibility(ghost.Owner, visibility); + } + else + { + _visibilitySystem.AddLayer((ghost.Owner, visibility), (int)VisibilityFlags.Ghost, false); + _visibilitySystem.RemoveLayer((ghost.Owner, visibility), (int)VisibilityFlags.Normal, false); + _visibilitySystem.RefreshVisibility(ghost.Owner, visibility); + } + } + private void OnActionPerform(EntityUid uid, GhostComponent component, BooActionEvent args) { if (args.Handled) @@ -257,7 +284,7 @@ namespace Content.Server.Ghost // Allow this entity to be seen by other ghosts. var visibility = EnsureComp(uid); - if (_ticker.RunLevel != GameRunLevel.PostRound) + if (_ticker.RunLevel != GameRunLevel.PostRound && !component.Visible) { _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Ghost, false); _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false); @@ -277,7 +304,7 @@ namespace Content.Server.Ghost return; // Entity can't be seen by ghosts anymore. - if (TryComp(uid, out VisibilityComponent? visibility)) + if (TryComp(uid, out VisibilityComponent? visibility) && !component.Visible) { _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Ghost, false); _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false); @@ -330,24 +357,16 @@ namespace Content.Server.Ghost private void OnMindRemovedMessage(EntityUid uid, GhostComponent component, MindRemovedMessage args) { - DeleteEntity(uid); + QueueDel(uid); } private void OnMindUnvisitedMessage(EntityUid uid, GhostComponent component, MindUnvisitedMessage args) { - DeleteEntity(uid); + QueueDel(uid); } private void OnPlayerDetached(EntityUid uid, GhostComponent component, PlayerDetachedEvent args) { - DeleteEntity(uid); - } - - private void DeleteEntity(EntityUid uid) - { - if (Deleted(uid) || Terminating(uid)) - return; - QueueDel(uid); } @@ -543,25 +562,14 @@ namespace Content.Server.Ghost /// public void MakeVisible(bool visible) { - var entityQuery = EntityQueryEnumerator(); - while (entityQuery.MoveNext(out var uid, out _, out var vis)) + var entityQuery = EntityQueryEnumerator(); + while (entityQuery.MoveNext(out var uid, out var ghost)) { // WD - if (EntityManager.TryGetComponent(vis.Owner, out InvisibilityComponent? invis) && invis.Invisible) + if (EntityManager.TryGetComponent(uid, out InvisibilityComponent? invis) && invis.Invisible) continue; - if (visible) - { - _visibilitySystem.AddLayer(uid, vis, (int) VisibilityFlags.Normal, false); - _visibilitySystem.RemoveLayer(uid, vis, (int) VisibilityFlags.Ghost, false); - } - else - { - _visibilitySystem.AddLayer(uid, vis, (int) VisibilityFlags.Ghost, false); - _visibilitySystem.RemoveLayer(uid, vis, (int) VisibilityFlags.Normal, false); - } - - _visibilitySystem.RefreshVisibility(uid, visibilityComponent: vis); + SetVisible((uid, ghost), visible); } } diff --git a/Content.Server/Revenant/EntitySystems/CorporealSystem.cs b/Content.Server/Revenant/EntitySystems/CorporealSystem.cs index 1d43cb3ac8..9943892d67 100644 --- a/Content.Server/Revenant/EntitySystems/CorporealSystem.cs +++ b/Content.Server/Revenant/EntitySystems/CorporealSystem.cs @@ -1,37 +1,7 @@ -using Content.Server.GameTicking; -using Content.Shared.Eye; -using Content.Shared.Revenant.Components; -using Content.Shared.Revenant.EntitySystems; -using Robust.Server.GameObjects; +using Content.Shared.Revenant.EntitySystems; namespace Content.Server.Revenant.EntitySystems; public sealed class CorporealSystem : SharedCorporealSystem { - [Dependency] private readonly VisibilitySystem _visibilitySystem = default!; - [Dependency] private readonly GameTicker _ticker = default!; - - public override void OnStartup(EntityUid uid, CorporealComponent component, ComponentStartup args) - { - base.OnStartup(uid, component, args); - - if (TryComp(uid, out var visibility)) - { - _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Ghost, false); - _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false); - _visibilitySystem.RefreshVisibility(uid, visibility); - } - } - - public override void OnShutdown(EntityUid uid, CorporealComponent component, ComponentShutdown args) - { - base.OnShutdown(uid, component, args); - - if (TryComp(uid, out var visibility) && _ticker.RunLevel != GameRunLevel.PostRound) - { - _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Ghost, false); - _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false); - _visibilitySystem.RefreshVisibility(uid, visibility); - } - } } diff --git a/Content.Server/Revenant/EntitySystems/RevenantSystem.cs b/Content.Server/Revenant/EntitySystems/RevenantSystem.cs index 0d885b65cf..438c06b8ee 100644 --- a/Content.Server/Revenant/EntitySystems/RevenantSystem.cs +++ b/Content.Server/Revenant/EntitySystems/RevenantSystem.cs @@ -35,7 +35,6 @@ public sealed partial class RevenantSystem : EntitySystem [Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly DamageableSystem _damage = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; - [Dependency] private readonly GameTicker _ticker = default!; [Dependency] private readonly MobStateSystem _mobState = default!; [Dependency] private readonly PhysicsSystem _physics = default!; [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; @@ -46,7 +45,6 @@ public sealed partial class RevenantSystem : EntitySystem [Dependency] private readonly SharedStunSystem _stun = default!; [Dependency] private readonly StoreSystem _store = default!; [Dependency] private readonly TagSystem _tag = default!; - [Dependency] private readonly VisibilitySystem _visibility = default!; [ValidatePrototypeId] private const string RevenantShopId = "ActionRevenantShop"; @@ -63,7 +61,6 @@ public sealed partial class RevenantSystem : EntitySystem SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnStatusAdded); SubscribeLocalEvent(OnStatusEnded); - SubscribeLocalEvent(_ => MakeVisible(true)); SubscribeLocalEvent(OnAttacked); // WD EDIT @@ -90,18 +87,9 @@ public sealed partial class RevenantSystem : EntitySystem _appearance.SetData(uid, RevenantVisuals.Harvesting, false); _appearance.SetData(uid, RevenantVisuals.Stunned, false); - if (_ticker.RunLevel == GameRunLevel.PostRound && TryComp(uid, out var visibility)) - { - _visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Ghost, false); - _visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false); - _visibility.RefreshVisibility(uid, visibility); - } - //ghost vision if (TryComp(uid, out EyeComponent? eye)) - { _eye.SetVisibilityMask(uid, eye.VisibilityMask | (int) (VisibilityFlags.Ghost), eye); - } } private void OnMapInit(EntityUid uid, RevenantComponent component, MapInitEvent args) @@ -199,25 +187,6 @@ public sealed partial class RevenantSystem : EntitySystem _store.ToggleUi(uid, uid, store); } - public void MakeVisible(bool visible) - { - var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out _, out var vis)) - { - if (visible) - { - _visibility.AddLayer(uid, vis, (int) VisibilityFlags.Normal, false); - _visibility.RemoveLayer(uid, vis, (int) VisibilityFlags.Ghost, false); - } - else - { - _visibility.AddLayer(uid, vis, (int) VisibilityFlags.Ghost, false); - _visibility.RemoveLayer(uid, vis, (int) VisibilityFlags.Normal, false); - } - _visibility.RefreshVisibility(uid, vis); - } - } - public override void Update(float frameTime) { base.Update(frameTime); diff --git a/Content.Shared/Ghost/GhostComponent.cs b/Content.Shared/Ghost/GhostComponent.cs index f7717e8d23..00ec313290 100644 --- a/Content.Shared/Ghost/GhostComponent.cs +++ b/Content.Shared/Ghost/GhostComponent.cs @@ -82,12 +82,15 @@ public sealed partial class GhostComponent : Component } } + [DataField, AutoNetworkedField] + public bool Visible; + /// /// Ghost color /// /// Used to allow admins to change ghost colors. Should be removed if the capability to edit existing sprite colors is ever added back. - [DataField("color"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] - public Color color = Color.White; + [DataField("color"), AutoNetworkedField] + public Color Color = Color.White; [DataField("canReturnToBody"), AutoNetworkedField] private bool _canReturnToBody; diff --git a/Content.Shared/Ghost/SharedGhostSystem.cs b/Content.Shared/Ghost/SharedGhostSystem.cs index 7d92852f4f..9113b893e1 100644 --- a/Content.Shared/Ghost/SharedGhostSystem.cs +++ b/Content.Shared/Ghost/SharedGhostSystem.cs @@ -53,6 +53,14 @@ namespace Content.Shared.Ghost { component.CanReturnToBody = value; } + public virtual void SetVisible(Entity ghost, bool visible) + { + if (!Resolve(ghost.Owner, ref ghost.Comp)) + return; + + ghost.Comp.Visible = visible; + Dirty(ghost); + } } /// diff --git a/Content.Shared/Revenant/Components/CorporealComponent.cs b/Content.Shared/Revenant/Components/CorporealComponent.cs index 289e20606a..4f5ad65b4e 100644 --- a/Content.Shared/Revenant/Components/CorporealComponent.cs +++ b/Content.Shared/Revenant/Components/CorporealComponent.cs @@ -12,4 +12,7 @@ public sealed partial class CorporealComponent : Component /// [ViewVariables(VVAccess.ReadWrite)] public float MovementSpeedDebuff = 0.4f; // WD EDIT + + [DataField] + public bool MadeVisible; } diff --git a/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs b/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs index e86fdb8e80..1f6eee9e4e 100644 --- a/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs +++ b/Content.Shared/Revenant/EntitySystems/SharedCorporealSystem.cs @@ -1,6 +1,7 @@ using Content.Shared.Physics; using Robust.Shared.Physics; using System.Linq; +using Content.Shared.Ghost; using Content.Shared.Movement.Systems; using Content.Shared.Revenant.Components; using Robust.Shared.Physics.Systems; @@ -17,6 +18,7 @@ public abstract class SharedCorporealSystem : EntitySystem [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly MovementSpeedModifierSystem _movement = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!; + [Dependency] private readonly SharedGhostSystem _ghost = default!; public override void Initialize() { @@ -44,6 +46,12 @@ public abstract class SharedCorporealSystem : EntitySystem _physics.SetCollisionLayer(uid, fixture.Key, fixture.Value, (int) CollisionGroup.SmallMobLayer, fixtures); } _movement.RefreshMovementSpeedModifiers(uid); + + if (!TryComp(uid, out GhostComponent? ghost) || ghost.Visible) + return; + + component.MadeVisible = true; + _ghost.SetVisible((uid, ghost), true); } public virtual void OnShutdown(EntityUid uid, CorporealComponent component, ComponentShutdown args) @@ -59,5 +67,8 @@ public abstract class SharedCorporealSystem : EntitySystem } component.MovementSpeedDebuff = 1; //just so we can avoid annoying code elsewhere _movement.RefreshMovementSpeedModifiers(uid); + + if (component.MadeVisible && TryComp(uid, out GhostComponent? ghost)) + _ghost.SetVisible((uid, ghost), false); } }