Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ghostnado button to warp menu #27556

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<DefaultWindow xmlns="https://spacestation14.io" Title="{Loc 'ghost-target-window-title'}" MinSize="450 450" SetSize="450 450">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="0.4">
<Button Name="GhostnadoButton" Text="{Loc 'ghost-target-window-warp-to-most-followed'}" HorizontalAlignment="Center" Margin="0 4" />
<LineEdit Name="SearchBar" PlaceHolder="Search" HorizontalExpand="True" Margin="0 4" />
<ScrollContainer VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False">
<BoxContainer Name="ButtonContainer" Orientation="Vertical" VerticalExpand="True" SeparationOverride="5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ public sealed partial class GhostTargetWindow : DefaultWindow
private string _searchText = string.Empty;

public event Action<NetEntity>? WarpClicked;
public event Action? OnGhostnadoClicked;

public GhostTargetWindow()
{
RobustXamlLoader.Load(this);
SearchBar.OnTextChanged += OnSearchTextChanged;

GhostnadoButton.OnPressed += _ => OnGhostnadoClicked?.Invoke();
}

public void UpdateWarps(IEnumerable<GhostWarp> warps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ private void OnWarpClicked(NetEntity player)
_net.SendSystemNetworkMessage(msg);
}

private void OnGhostnadoClicked()
{
var msg = new GhostnadoRequestEvent();
_net.SendSystemNetworkMessage(msg);
}

public void LoadGui()
{
if (Gui == null)
Expand All @@ -120,6 +126,7 @@ public void LoadGui()
Gui.ReturnToBodyPressed += ReturnToBody;
Gui.GhostRolesPressed += GhostRolesPressed;
Gui.TargetWindow.WarpClicked += OnWarpClicked;
Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;

UpdateGui();
}
Expand Down
45 changes: 36 additions & 9 deletions Content.Server/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ public sealed class GhostSystem : SharedGhostSystem
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;

private EntityQuery<GhostComponent> _ghostQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;

public override void Initialize()
{
base.Initialize();

_ghostQuery = GetEntityQuery<GhostComponent>();
_physicsQuery = GetEntityQuery<PhysicsComponent>();

SubscribeLocalEvent<GhostComponent, ComponentStartup>(OnGhostStartup);
SubscribeLocalEvent<GhostComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<GhostComponent, ComponentShutdown>(OnGhostShutdown);
Expand All @@ -62,6 +68,7 @@ public override void Initialize()
SubscribeNetworkEvent<GhostWarpsRequestEvent>(OnGhostWarpsRequest);
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
SubscribeNetworkEvent<GhostnadoRequestEvent>(OnGhostnadoRequest);

SubscribeLocalEvent<GhostComponent, BooActionEvent>(OnActionPerform);
SubscribeLocalEvent<GhostComponent, ToggleGhostHearingActionEvent>(OnGhostHearingAction);
Expand Down Expand Up @@ -241,7 +248,7 @@ private void DeleteEntity(EntityUid uid)
private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not {Valid: true} attached
|| !TryComp(attached, out GhostComponent? ghost)
|| !_ghostQuery.TryComp(attached, out var ghost)
|| !ghost.CanReturnToBody
|| !TryComp(attached, out ActorComponent? actor))
{
Expand All @@ -257,7 +264,7 @@ private void OnGhostReturnToBodyRequest(GhostReturnToBodyRequest msg, EntitySess
private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not {Valid: true} entity
|| !HasComp<GhostComponent>(entity))
|| !_ghostQuery.HasComp(entity))
{
Log.Warning($"User {args.SenderSession.Name} sent a {nameof(GhostWarpsRequestEvent)} without being a ghost.");
return;
Expand All @@ -270,7 +277,7 @@ private void OnGhostWarpsRequest(GhostWarpsRequestEvent msg, EntitySessionEventA
private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not {Valid: true} attached
|| !TryComp(attached, out GhostComponent? _))
|| !_ghostQuery.HasComp(attached))
{
Log.Warning($"User {args.SenderSession.Name} tried to warp to {msg.Target} without being a ghost.");
return;
Expand All @@ -284,17 +291,37 @@ private void OnGhostWarpToTargetRequest(GhostWarpToTargetRequestEvent msg, Entit
return;
}

WarpTo(attached, target);
}

private void OnGhostnadoRequest(GhostnadoRequestEvent msg, EntitySessionEventArgs args)
{
if (args.SenderSession.AttachedEntity is not {} uid
|| !_ghostQuery.HasComp(uid))
{
Log.Warning($"User {args.SenderSession.Name} tried to ghostnado without being a ghost.");
return;
}

if (_followerSystem.GetMostFollowed() is not {} target)
return;

WarpTo(uid, target);
}

private void WarpTo(EntityUid uid, EntityUid target)
{
if ((TryComp(target, out WarpPointComponent? warp) && warp.Follow) || HasComp<MobStateComponent>(target))
{
_followerSystem.StartFollowingEntity(attached, target);
_followerSystem.StartFollowingEntity(uid, target);
return;
}

var xform = Transform(attached);
_transformSystem.SetCoordinates(attached, xform, Transform(target).Coordinates);
_transformSystem.AttachToGridOrMap(attached, xform);
if (TryComp(attached, out PhysicsComponent? physics))
_physics.SetLinearVelocity(attached, Vector2.Zero, body: physics);
var xform = Transform(uid);
_transformSystem.SetCoordinates(uid, xform, Transform(target).Coordinates);
_transformSystem.AttachToGridOrMap(uid, xform);
if (_physicsQuery.TryComp(uid, out var physics))
_physics.SetLinearVelocity(uid, Vector2.Zero, body: physics);
}

private IEnumerable<GhostWarp> GetLocationWarps()
Expand Down
21 changes: 21 additions & 0 deletions Content.Shared/Follower/FollowerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,27 @@ public void StopAllFollowers(EntityUid uid,
StopFollowingEntity(player, uid, followed);
}
}

/// <summary>
/// Get the most followed entity.
/// </summary>
public EntityUid? GetMostFollowed()
{
EntityUid? picked = null;
int most = 0;
var query = EntityQueryEnumerator<FollowedComponent>();
while (query.MoveNext(out var uid, out var comp))
{
var count = comp.Following.Count;
if (count > most)
{
picked = uid;
most = count;
}
}

return picked;
}
}

public abstract class FollowEvent : EntityEventArgs
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Ghost/SharedGhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public GhostWarpToTargetRequestEvent(NetEntity target)
}
}

/// <summary>
/// A client to server request for their ghost to be warped to the most followed entity.
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostnadoRequestEvent : EntityEventArgs;

/// <summary>
/// A client to server request for their ghost to return to body
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/ghost/ghost-gui.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ghost-gui-toggle-hearing-popup-off = You can now only hear radio and nearby mess

ghost-target-window-title = Ghost Warp
ghost-target-window-current-button = Warp: {$name}
ghost-target-window-warp-to-most-followed = Warp to Most Followed

ghost-roles-window-title = Ghost Roles
ghost-roles-window-request-role-button = Request
Expand Down
Loading