From f6234c7920de977f771de3197e395a8eba58e7ac Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:55:11 -0400 Subject: [PATCH] view ghosts on round end (#11680) * view ghosts on round end * now make it good * it toggles now i hope --- .../Commands/ShowGhostsCommand.cs | 38 ++++++++++++++ Content.Server/Ghost/GhostSystem.cs | 49 ++++++++++++++++--- .../Revenant/EntitySystems/CorporealSystem.cs | 6 ++- .../Revenant/EntitySystems/RevenantSystem.cs | 29 +++++++++++ 4 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 Content.Server/Administration/Commands/ShowGhostsCommand.cs diff --git a/Content.Server/Administration/Commands/ShowGhostsCommand.cs b/Content.Server/Administration/Commands/ShowGhostsCommand.cs new file mode 100644 index 0000000000..2f8bf79e69 --- /dev/null +++ b/Content.Server/Administration/Commands/ShowGhostsCommand.cs @@ -0,0 +1,38 @@ +using Content.Server.Ghost; +using Content.Server.Revenant.EntitySystems; +using Content.Shared.Administration; +using Robust.Shared.Console; + +namespace Content.Server.Administration.Commands +{ + [AdminCommand(AdminFlags.Admin)] + public sealed class ShowGhostsCommand : IConsoleCommand + { + [Dependency] private readonly IEntityManager _entities = default!; + + public string Command => "showghosts"; + public string Description => "makes all of the currently present ghosts visible. Cannot be reversed."; + public string Help => "showghosts "; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 1) + { + shell.WriteError(Loc.GetString("shell-wrong-arguments-number")); + return; + } + + if (!bool.TryParse(args[0], out var visible)) + { + shell.WriteError(Loc.GetString("shell-invalid-bool")); + return; + } + + var ghostSys = _entities.EntitySysManager.GetEntitySystem(); + var revSys = _entities.EntitySysManager.GetEntitySystem(); + + ghostSys.MakeVisible(visible); + revSys.MakeVisible(visible); + } + } +} diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index cea7bb30c1..d353364645 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -3,6 +3,7 @@ using Content.Server.GameTicking; using Content.Server.Ghost.Components; using Content.Server.Mind; using Content.Server.Mind.Components; +using Content.Server.MobState; using Content.Server.Players; using Content.Server.Storage.Components; using Content.Server.Visible; @@ -32,6 +33,7 @@ namespace Content.Server.Ghost [Dependency] private readonly VisibilitySystem _visibilitySystem = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly FollowerSystem _followerSystem = default!; + [Dependency] private readonly MobStateSystem _mobState = default!; public override void Initialize() { @@ -53,6 +55,8 @@ namespace Content.Server.Ghost SubscribeLocalEvent(OnActionPerform); SubscribeLocalEvent(OnEntityStorageInsertAttempt); + + SubscribeLocalEvent(_ => MakeVisible(true)); } private void OnActionPerform(EntityUid uid, GhostComponent component, BooActionEvent args) { @@ -79,9 +83,14 @@ namespace Content.Server.Ghost private void OnRelayMoveInput(EntityUid uid, GhostOnMoveComponent component, ref MoveInputEvent args) { // Let's not ghost if our mind is visiting... - if (EntityManager.HasComponent(uid)) return; - if (!EntityManager.TryGetComponent(uid, out var mind) || !mind.HasMind || mind.Mind!.IsVisitingEntity) return; - if (component.MustBeDead && TryComp(uid, out var state) && !state.IsDead()) return; + if (EntityManager.HasComponent(uid)) + return; + + if (!EntityManager.TryGetComponent(uid, out var mind) || !mind.HasMind || mind.Mind!.IsVisitingEntity) + return; + + if (component.MustBeDead && (_mobState.IsAlive(uid) || _mobState.IsCritical(uid))) + return; _ticker.OnGhostAttempt(mind.Mind!, component.CanReturn); } @@ -91,9 +100,12 @@ namespace Content.Server.Ghost // Allow this entity to be seen by other ghosts. var visibility = EntityManager.EnsureComponent(component.Owner); - _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Ghost, false); - _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false); - _visibilitySystem.RefreshVisibility(visibility); + if (_ticker.RunLevel != GameRunLevel.PostRound) + { + _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Ghost, false); + _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false); + _visibilitySystem.RefreshVisibility(visibility); + } if (EntityManager.TryGetComponent(component.Owner, out EyeComponent? eye)) { @@ -237,17 +249,38 @@ namespace Content.Server.Ghost string playerInfo = $"{EntityManager.GetComponent(attached).EntityName} ({mind?.Mind?.CurrentJob?.Name ?? "Unknown"})"; - if (TryComp(attached, out var state) && !state.IsDead()) + if (_mobState.IsAlive(attached) || _mobState.IsCritical(attached)) yield return new GhostWarp(attached, playerInfo, false); } } } - public void OnEntityStorageInsertAttempt(EntityUid uid, GhostComponent comp, InsertIntoEntityStorageAttemptEvent args) + private void OnEntityStorageInsertAttempt(EntityUid uid, GhostComponent comp, InsertIntoEntityStorageAttemptEvent args) { args.Cancel(); } + /// + /// When the round ends, make all players able to see ghosts. + /// + public void MakeVisible(bool visible) + { + foreach (var (_, vis) in EntityQuery()) + { + if (visible) + { + _visibilitySystem.AddLayer(vis, (int) VisibilityFlags.Normal, false); + _visibilitySystem.RemoveLayer(vis, (int) VisibilityFlags.Ghost, false); + } + else + { + _visibilitySystem.AddLayer(vis, (int) VisibilityFlags.Ghost, false); + _visibilitySystem.RemoveLayer(vis, (int) VisibilityFlags.Normal, false); + } + _visibilitySystem.RefreshVisibility(vis); + } + } + public bool DoGhostBooEvent(EntityUid target) { var ghostBoo = new GhostBooEvent(); diff --git a/Content.Server/Revenant/EntitySystems/CorporealSystem.cs b/Content.Server/Revenant/EntitySystems/CorporealSystem.cs index 13ec6eb036..bad5eb6100 100644 --- a/Content.Server/Revenant/EntitySystems/CorporealSystem.cs +++ b/Content.Server/Revenant/EntitySystems/CorporealSystem.cs @@ -1,4 +1,5 @@ -using Content.Server.Visible; +using Content.Server.GameTicking; +using Content.Server.Visible; using Content.Shared.Revenant.Components; using Content.Shared.Revenant.EntitySystems; using Robust.Server.GameObjects; @@ -8,6 +9,7 @@ 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) { @@ -25,7 +27,7 @@ public sealed class CorporealSystem : SharedCorporealSystem { base.OnShutdown(uid, component, args); - if (TryComp(uid, out var visibility)) + if (TryComp(uid, out var visibility) && _ticker.RunLevel != GameRunLevel.PostRound) { _visibilitySystem.AddLayer(visibility, (int) VisibilityFlags.Ghost, false); _visibilitySystem.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false); diff --git a/Content.Server/Revenant/EntitySystems/RevenantSystem.cs b/Content.Server/Revenant/EntitySystems/RevenantSystem.cs index b3b99a46b3..8ce4135a76 100644 --- a/Content.Server/Revenant/EntitySystems/RevenantSystem.cs +++ b/Content.Server/Revenant/EntitySystems/RevenantSystem.cs @@ -4,6 +4,7 @@ using Content.Shared.Alert; using Content.Shared.Damage; using Content.Shared.Interaction; using Content.Server.DoAfter; +using Content.Server.GameTicking; using Content.Shared.Stunnable; using Content.Shared.Revenant; using Robust.Server.GameObjects; @@ -42,6 +43,8 @@ public sealed partial class RevenantSystem : EntitySystem [Dependency] private readonly SharedStunSystem _stun = default!; [Dependency] private readonly TagSystem _tag = default!; [Dependency] private readonly StoreSystem _store = default!; + [Dependency] private readonly VisibilitySystem _visibility = default!; + [Dependency] private readonly GameTicker _ticker = default!; public override void Initialize() { @@ -54,6 +57,7 @@ public sealed partial class RevenantSystem : EntitySystem SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnStatusAdded); SubscribeLocalEvent(OnStatusEnded); + SubscribeLocalEvent(_ => MakeVisible(true)); InitializeAbilities(); } @@ -68,6 +72,13 @@ 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(visibility, (int) VisibilityFlags.Ghost, false); + _visibility.RemoveLayer(visibility, (int) VisibilityFlags.Normal, false); + _visibility.RefreshVisibility(visibility); + } + //ghost vision if (TryComp(component.Owner, out EyeComponent? eye)) eye.VisibilityMask |= (uint) (VisibilityFlags.Ghost); @@ -164,6 +175,24 @@ public sealed partial class RevenantSystem : EntitySystem _store.ToggleUi(uid, store); } + public void MakeVisible(bool visible) + { + foreach (var (_, vis) in EntityQuery()) + { + if (visible) + { + _visibility.AddLayer(vis, (int) VisibilityFlags.Normal, false); + _visibility.RemoveLayer(vis, (int) VisibilityFlags.Ghost, false); + } + else + { + _visibility.AddLayer(vis, (int) VisibilityFlags.Ghost, false); + _visibility.RemoveLayer(vis, (int) VisibilityFlags.Normal, false); + } + _visibility.RefreshVisibility(vis); + } + } + public override void Update(float frameTime) { base.Update(frameTime);