перенос

This commit is contained in:
NR
2025-03-21 02:20:37 +05:00
parent 9115a72d46
commit 4e66cc69fa
9 changed files with 79 additions and 102 deletions

View File

@@ -18,7 +18,7 @@ namespace Content.Client.Ghost
public int AvailableGhostRoleCount { get; private set; } public int AvailableGhostRoleCount { get; private set; }
private bool _ghostVisibility = true; private bool _ghostVisibility;
private bool GhostVisibility private bool GhostVisibility
{ {
@@ -33,9 +33,9 @@ namespace Content.Client.Ghost
_ghostVisibility = value; _ghostVisibility = value;
var query = AllEntityQuery<GhostComponent, SpriteComponent>(); var query = AllEntityQuery<GhostComponent, SpriteComponent>();
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) private void OnStartup(EntityUid uid, GhostComponent component, ComponentStartup args)
{ {
if (TryComp(uid, out SpriteComponent? sprite)) UpdateVisibility((uid, component));
sprite.Visible = GhostVisibility || uid == _playerManager.LocalEntity; }
private void UpdateVisibility(Entity<GhostComponent?, SpriteComponent?> 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) 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) private void OnGhostState(EntityUid uid, GhostComponent component, ref AfterAutoHandleStateEvent args)
{ {
if (TryComp<SpriteComponent>(uid, out var sprite)) if (TryComp<SpriteComponent>(uid, out var sprite))
sprite.LayerSetColor(0, component.color); sprite.LayerSetColor(0, component.Color);
UpdateVisibility((uid, component, null));
if (uid != _playerManager.LocalEntity) if (uid != _playerManager.LocalEntity)
return; return;

View File

@@ -28,11 +28,7 @@ namespace Content.Server.Administration.Commands
return; return;
} }
var ghostSys = _entities.EntitySysManager.GetEntitySystem<GhostSystem>(); _entities.System<GhostSystem>().MakeVisible(visible);
var revSys = _entities.EntitySysManager.GetEntitySystem<RevenantSystem>();
ghostSys.MakeVisible(visible);
revSys.MakeVisible(visible);
} }
} }
} }

View File

@@ -208,6 +208,33 @@ namespace Content.Server.Ghost
Dirty(uid, component); Dirty(uid, component);
} }
public override void SetVisible(Entity<GhostComponent?> 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) private void OnActionPerform(EntityUid uid, GhostComponent component, BooActionEvent args)
{ {
if (args.Handled) if (args.Handled)
@@ -257,7 +284,7 @@ namespace Content.Server.Ghost
// Allow this entity to be seen by other ghosts. // Allow this entity to be seen by other ghosts.
var visibility = EnsureComp<VisibilityComponent>(uid); var visibility = EnsureComp<VisibilityComponent>(uid);
if (_ticker.RunLevel != GameRunLevel.PostRound) if (_ticker.RunLevel != GameRunLevel.PostRound && !component.Visible)
{ {
_visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Ghost, false); _visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Ghost, false);
_visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false); _visibilitySystem.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
@@ -277,7 +304,7 @@ namespace Content.Server.Ghost
return; return;
// Entity can't be seen by ghosts anymore. // 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.RemoveLayer(uid, visibility, (int) VisibilityFlags.Ghost, false);
_visibilitySystem.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, 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) private void OnMindRemovedMessage(EntityUid uid, GhostComponent component, MindRemovedMessage args)
{ {
DeleteEntity(uid); QueueDel(uid);
} }
private void OnMindUnvisitedMessage(EntityUid uid, GhostComponent component, MindUnvisitedMessage args) private void OnMindUnvisitedMessage(EntityUid uid, GhostComponent component, MindUnvisitedMessage args)
{ {
DeleteEntity(uid); QueueDel(uid);
} }
private void OnPlayerDetached(EntityUid uid, GhostComponent component, PlayerDetachedEvent args) private void OnPlayerDetached(EntityUid uid, GhostComponent component, PlayerDetachedEvent args)
{ {
DeleteEntity(uid);
}
private void DeleteEntity(EntityUid uid)
{
if (Deleted(uid) || Terminating(uid))
return;
QueueDel(uid); QueueDel(uid);
} }
@@ -543,25 +562,14 @@ namespace Content.Server.Ghost
/// </summary> /// </summary>
public void MakeVisible(bool visible) public void MakeVisible(bool visible)
{ {
var entityQuery = EntityQueryEnumerator<GhostComponent, VisibilityComponent>(); var entityQuery = EntityQueryEnumerator<GhostComponent>();
while (entityQuery.MoveNext(out var uid, out _, out var vis)) while (entityQuery.MoveNext(out var uid, out var ghost))
{ {
// WD // WD
if (EntityManager.TryGetComponent(vis.Owner, out InvisibilityComponent? invis) && invis.Invisible) if (EntityManager.TryGetComponent(uid, out InvisibilityComponent? invis) && invis.Invisible)
continue; continue;
if (visible) SetVisible((uid, ghost), 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);
} }
} }

View File

@@ -1,37 +1,7 @@
using Content.Server.GameTicking; using Content.Shared.Revenant.EntitySystems;
using Content.Shared.Eye;
using Content.Shared.Revenant.Components;
using Content.Shared.Revenant.EntitySystems;
using Robust.Server.GameObjects;
namespace Content.Server.Revenant.EntitySystems; namespace Content.Server.Revenant.EntitySystems;
public sealed class CorporealSystem : SharedCorporealSystem 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<VisibilityComponent>(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<VisibilityComponent>(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);
}
}
} }

View File

@@ -35,7 +35,6 @@ public sealed partial class RevenantSystem : EntitySystem
[Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly DamageableSystem _damage = default!; [Dependency] private readonly DamageableSystem _damage = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly MobStateSystem _mobState = default!; [Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly PhysicsSystem _physics = default!; [Dependency] private readonly PhysicsSystem _physics = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = 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 SharedStunSystem _stun = default!;
[Dependency] private readonly StoreSystem _store = default!; [Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly TagSystem _tag = default!; [Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly VisibilitySystem _visibility = default!;
[ValidatePrototypeId<EntityPrototype>] [ValidatePrototypeId<EntityPrototype>]
private const string RevenantShopId = "ActionRevenantShop"; private const string RevenantShopId = "ActionRevenantShop";
@@ -63,7 +61,6 @@ public sealed partial class RevenantSystem : EntitySystem
SubscribeLocalEvent<RevenantComponent, ExaminedEvent>(OnExamine); SubscribeLocalEvent<RevenantComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<RevenantComponent, StatusEffectAddedEvent>(OnStatusAdded); SubscribeLocalEvent<RevenantComponent, StatusEffectAddedEvent>(OnStatusAdded);
SubscribeLocalEvent<RevenantComponent, StatusEffectEndedEvent>(OnStatusEnded); SubscribeLocalEvent<RevenantComponent, StatusEffectEndedEvent>(OnStatusEnded);
SubscribeLocalEvent<RoundEndTextAppendEvent>(_ => MakeVisible(true));
SubscribeLocalEvent<RevenantComponent, AttackedEvent>(OnAttacked); // WD EDIT SubscribeLocalEvent<RevenantComponent, AttackedEvent>(OnAttacked); // WD EDIT
@@ -90,18 +87,9 @@ public sealed partial class RevenantSystem : EntitySystem
_appearance.SetData(uid, RevenantVisuals.Harvesting, false); _appearance.SetData(uid, RevenantVisuals.Harvesting, false);
_appearance.SetData(uid, RevenantVisuals.Stunned, false); _appearance.SetData(uid, RevenantVisuals.Stunned, false);
if (_ticker.RunLevel == GameRunLevel.PostRound && TryComp<VisibilityComponent>(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 //ghost vision
if (TryComp(uid, out EyeComponent? eye)) if (TryComp(uid, out EyeComponent? eye))
{
_eye.SetVisibilityMask(uid, eye.VisibilityMask | (int) (VisibilityFlags.Ghost), eye); _eye.SetVisibilityMask(uid, eye.VisibilityMask | (int) (VisibilityFlags.Ghost), eye);
}
} }
private void OnMapInit(EntityUid uid, RevenantComponent component, MapInitEvent args) private void OnMapInit(EntityUid uid, RevenantComponent component, MapInitEvent args)
@@ -199,25 +187,6 @@ public sealed partial class RevenantSystem : EntitySystem
_store.ToggleUi(uid, uid, store); _store.ToggleUi(uid, uid, store);
} }
public void MakeVisible(bool visible)
{
var query = EntityQueryEnumerator<RevenantComponent, VisibilityComponent>();
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) public override void Update(float frameTime)
{ {
base.Update(frameTime); base.Update(frameTime);

View File

@@ -82,12 +82,15 @@ public sealed partial class GhostComponent : Component
} }
} }
[DataField, AutoNetworkedField]
public bool Visible;
/// <summary> /// <summary>
/// Ghost color /// Ghost color
/// </summary> /// </summary>
/// <remarks>Used to allow admins to change ghost colors. Should be removed if the capability to edit existing sprite colors is ever added back.</remarks> /// <remarks>Used to allow admins to change ghost colors. Should be removed if the capability to edit existing sprite colors is ever added back.</remarks>
[DataField("color"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] [DataField("color"), AutoNetworkedField]
public Color color = Color.White; public Color Color = Color.White;
[DataField("canReturnToBody"), AutoNetworkedField] [DataField("canReturnToBody"), AutoNetworkedField]
private bool _canReturnToBody; private bool _canReturnToBody;

View File

@@ -53,6 +53,14 @@ namespace Content.Shared.Ghost
{ {
component.CanReturnToBody = value; component.CanReturnToBody = value;
} }
public virtual void SetVisible(Entity<GhostComponent?> ghost, bool visible)
{
if (!Resolve(ghost.Owner, ref ghost.Comp))
return;
ghost.Comp.Visible = visible;
Dirty(ghost);
}
} }
/// <summary> /// <summary>

View File

@@ -12,4 +12,7 @@ public sealed partial class CorporealComponent : Component
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public float MovementSpeedDebuff = 0.4f; // WD EDIT public float MovementSpeedDebuff = 0.4f; // WD EDIT
[DataField]
public bool MadeVisible;
} }

View File

@@ -1,6 +1,7 @@
using Content.Shared.Physics; using Content.Shared.Physics;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using System.Linq; using System.Linq;
using Content.Shared.Ghost;
using Content.Shared.Movement.Systems; using Content.Shared.Movement.Systems;
using Content.Shared.Revenant.Components; using Content.Shared.Revenant.Components;
using Robust.Shared.Physics.Systems; using Robust.Shared.Physics.Systems;
@@ -17,6 +18,7 @@ public abstract class SharedCorporealSystem : EntitySystem
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!; [Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedGhostSystem _ghost = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -44,6 +46,12 @@ public abstract class SharedCorporealSystem : EntitySystem
_physics.SetCollisionLayer(uid, fixture.Key, fixture.Value, (int) CollisionGroup.SmallMobLayer, fixtures); _physics.SetCollisionLayer(uid, fixture.Key, fixture.Value, (int) CollisionGroup.SmallMobLayer, fixtures);
} }
_movement.RefreshMovementSpeedModifiers(uid); _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) 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 component.MovementSpeedDebuff = 1; //just so we can avoid annoying code elsewhere
_movement.RefreshMovementSpeedModifiers(uid); _movement.RefreshMovementSpeedModifiers(uid);
if (component.MadeVisible && TryComp(uid, out GhostComponent? ghost))
_ghost.SetVisible((uid, ghost), false);
} }
} }