CatStation/Content.Shared/Ghost/Systems/SharedGhostSystem.cs
cashew 4bde1c1120
Port Chat Follow functionality from AfterLight (#45375)
* ports chat follow function from AL and removes PJB implementation
forgor to commit earlier so it's just one chunk

* fixes accidental MiscTab.xaml restructuring

* fix name color

* remove unused function

* cvar summary

* typo

* accidental doc removal

* fix test fail

* fix test fail

* like i said first pr :|

* inject in constructor

* adds chat links to Local, Whisper, LOOC and Dead Chat respects Admin ghost privacy

* i hate chat code

* remove cvar

* single events file

* adds CanGhostWarp back

* filter for admin ghosts

* move tag

* remove ChatLinkTag.cs

* fix speechbubble rendering

* i want to bash my brain in

* kill chatcode

* formatting

* testfail

* still not working

* atleast deadchat works now

* even prettier TextLinkTag.cs

* fix speechbubble rendering for looc

* docs

* renaming and better docs

* Revert "remove cvar"

This reverts commit 1acb168f

* final changes (hopefully)

* requested changes

* can't parse -

* change TextLinkTag again

* formatting and typo

Co-authored-by: Connor Huffine <chuffine@gmail.com>

* quickfix

* no logging for now actually

* i will work on this in the morning

* restructuring

* wip

* final restructuring and docs

* still not done btw

* review

* docfix

* actually we can filter for admin ghosts

* doc

* fix color

* fix fix color

* review

* all I care to clean up

* bold names

* doc

* admin warp

* fixed

* fsaasffsa

* GOD ONCE SAID: GOOD ENOUGH

* they call me the shuffler

* admin chat links

* forgor newline

* fix?

* actual fix

* dumb stuff

* chungus

---------

Co-authored-by: Connor Huffine <chuffine@gmail.com>
Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
2026-09-15 08:05:17 +00:00

256 lines
7.9 KiB
C#

using Content.Shared.Administration.Managers;
using Content.Shared.Chat;
using Content.Shared.Emoting;
using Content.Shared.Examine;
using Content.Shared.Follower;
using Content.Shared.Ghost.Components;
using Content.Shared.Hands;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
namespace Content.Shared.Ghost.Systems;
/// <summary>
/// System for the <see cref="GhostComponent"/>.
/// Prevents ghosts from interacting when <see cref="GhostComponent.CanGhostInteract"/> is false.
/// </summary>
public abstract partial class SharedGhostSystem : EntitySystem
{
[Dependency] protected IGameTiming GameTiming = default!;
[Dependency] private ISharedAdminManager _admin = default!;
[Dependency] private FollowerSystem _follower = default!;
[Dependency] protected SharedPopupSystem Popup = default!;
[Dependency] private TagSystem _tag = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GhostComponent, UseAttemptEvent>(OnAttempt);
SubscribeLocalEvent<GhostComponent, InteractionAttemptEvent>(OnAttemptInteract);
SubscribeLocalEvent<GhostComponent, EmoteAttemptEvent>(OnAttempt);
SubscribeLocalEvent<GhostComponent, DropAttemptEvent>(OnAttempt);
SubscribeLocalEvent<GhostComponent, PickupAttemptEvent>(OnAttempt);
SubscribeLocalEvent<GhostComponent, ExaminedEvent>(OnGhostExamine);
}
private void OnGhostExamine(EntityUid uid, GhostComponent component, ExaminedEvent args)
{
var timeSinceDeath = GameTiming.RealTime.Subtract(component.TimeOfDeath);
var deathTimeInfo = timeSinceDeath.Minutes > 0
? Loc.GetString("comp-ghost-examine-time-minutes", ("minutes", timeSinceDeath.Minutes))
: Loc.GetString("comp-ghost-examine-time-seconds", ("seconds", timeSinceDeath.Seconds));
args.PushMarkup(deathTimeInfo);
}
private void OnAttemptInteract(Entity<GhostComponent> ent, ref InteractionAttemptEvent args)
{
if (!ent.Comp.CanGhostInteract)
args.Cancelled = true;
}
private void OnAttempt(EntityUid uid, GhostComponent component, CancellableEntityEventArgs args)
{
if (!component.CanGhostInteract)
args.Cancel();
}
/// <summary>
/// Sets the ghost's time of death.
/// </summary>
public void SetTimeOfDeath(Entity<GhostComponent?> entity, TimeSpan value)
{
if (!Resolve(entity, ref entity.Comp))
return;
if (entity.Comp.TimeOfDeath == value)
return;
entity.Comp.TimeOfDeath = value;
Dirty(entity);
}
[Obsolete("Use the Entity<GhostComponent?> overload")]
public void SetTimeOfDeath(EntityUid uid, TimeSpan value, GhostComponent? component)
{
SetTimeOfDeath((uid, component), value);
}
/// <summary>
/// Sets whether or not the ghost player is allowed to return to their original body.
/// </summary>
public void SetCanReturnToBody(Entity<GhostComponent?> entity, bool value)
{
if (!Resolve(entity, ref entity.Comp))
return;
if (entity.Comp.CanReturnToBody == value)
return;
entity.Comp.CanReturnToBody = value;
Dirty(entity);
}
[Obsolete("Use the Entity<GhostComponent?> overload")]
public void SetCanReturnToBody(EntityUid uid, bool value, GhostComponent? component = null)
{
SetCanReturnToBody((uid, component), value);
}
[Obsolete("Use the Entity<GhostComponent?> overload")]
public void SetCanReturnToBody(GhostComponent component, bool value)
{
SetCanReturnToBody((component.Owner, component), value);
}
/// <summary>
/// Sets whether the ghost is allowed to interact with other entities.
/// </summary>
public void SetCanGhostInteract(Entity<GhostComponent?> entity, bool value)
{
if (!Resolve(entity, ref entity.Comp))
return;
if (entity.Comp.CanGhostInteract == value)
return;
entity.Comp.CanGhostInteract = value;
Dirty(entity);
}
[SubscribeLocalEvent]
private void OnGhostClickMessageSenderAttempt(Entity<GhostComponent> ent, ref ClickEntityLinkEvent args)
{
if (args.Handled)
return;
if (_admin.IsAdmin(ent) || !_tag.HasTag(args.Target, FollowerSystem.PreventGhostnadoWarpTag)) //tag is used on any ghost that shouldn't be teleported to
args.Handled = true;
if (!args.Pure)
_follower.StartFollowingEntity(ent, args.Target);
}
}
/// <summary>
/// A client to server request to get places a ghost can warp to.
/// Response is sent via <see cref="GhostWarpsResponseEvent"/>
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostWarpsRequestEvent : EntityEventArgs
{
}
/// <summary>
/// An individual place a ghost can warp to.
/// This is used as part of <see cref="GhostWarpsResponseEvent"/>
/// </summary>
[Serializable, NetSerializable]
public struct GhostWarp
{
public GhostWarp(NetEntity entity, string displayName, bool isWarpPoint)
{
Entity = entity;
DisplayName = displayName;
IsWarpPoint = isWarpPoint;
}
/// <summary>
/// The entity representing the warp point.
/// This is passed back to the server in <see cref="GhostWarpToTargetRequestEvent"/>
/// </summary>
public NetEntity Entity { get; }
/// <summary>
/// The display name to be surfaced in the ghost warps menu
/// </summary>
public string DisplayName { get; }
/// <summary>
/// Whether this warp represents a warp point or a player
/// </summary>
public bool IsWarpPoint { get; }
}
/// <summary>
/// A server to client response for a <see cref="GhostWarpsRequestEvent"/>.
/// Contains players, and locations a ghost can warp to
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostWarpsResponseEvent : EntityEventArgs
{
public GhostWarpsResponseEvent(List<GhostWarp> warps)
{
Warps = warps;
}
/// <summary>
/// A list of warp points.
/// </summary>
public List<GhostWarp> Warps { get; }
}
/// <summary>
/// A client to server request for their ghost to be warped to an entity
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostWarpToTargetRequestEvent : EntityEventArgs
{
public NetEntity Target { get; }
public GhostWarpToTargetRequestEvent(NetEntity target)
{
Target = target;
}
}
/// <summary>
/// A client to server request for their ghost to be warped to the most followed player.
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostnadoRequestEvent : EntityEventArgs;
/// <summary>
/// A client to server request for their ghost to be warped to a random player with at least one ghost follower.
/// </summary>
[Serializable, NetSerializable]
public sealed class WarpToRandomFollowedRequestEvent : EntityEventArgs;
/// <summary>
/// A client to server request for their ghost to be warped to a random player.
/// </summary>
[Serializable, NetSerializable]
public sealed class WarpToRandomRequestEvent : EntityEventArgs;
/// <summary>
/// A client to server request for their ghost to return to body
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostReturnToBodyRequest : EntityEventArgs
{
}
/// <summary>
/// A server to client update with the available ghost role count
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostUpdateGhostRoleCountEvent : EntityEventArgs
{
public int AvailableGhostRoles { get; }
public GhostUpdateGhostRoleCountEvent(int availableGhostRoleCount)
{
AvailableGhostRoles = availableGhostRoleCount;
}
}
/// <summary>
/// Raised on an entity when Its mind is attempting to ghost out.
/// </summary>
[ByRefEvent]
public record struct GhostAttemptEvent(EntityUid Mind, bool Cancelled = false);