view ghosts on round end (#11680)
* view ghosts on round end * now make it good * it toggles now i hope
This commit is contained in:
@@ -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<GhostComponent, BooActionEvent>(OnActionPerform);
|
||||
SubscribeLocalEvent<GhostComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
|
||||
|
||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(_ => 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<VisitingMindComponent>(uid)) return;
|
||||
if (!EntityManager.TryGetComponent<MindComponent>(uid, out var mind) || !mind.HasMind || mind.Mind!.IsVisitingEntity) return;
|
||||
if (component.MustBeDead && TryComp<MobStateComponent>(uid, out var state) && !state.IsDead()) return;
|
||||
if (EntityManager.HasComponent<VisitingMindComponent>(uid))
|
||||
return;
|
||||
|
||||
if (!EntityManager.TryGetComponent<MindComponent>(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<VisibilityComponent>(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<MetaDataComponent>(attached).EntityName} ({mind?.Mind?.CurrentJob?.Name ?? "Unknown"})";
|
||||
|
||||
if (TryComp<MobStateComponent>(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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the round ends, make all players able to see ghosts.
|
||||
/// </summary>
|
||||
public void MakeVisible(bool visible)
|
||||
{
|
||||
foreach (var (_, vis) in EntityQuery<GhostComponent, VisibilityComponent>())
|
||||
{
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user