mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Add ghost random warp (#44499)
* wip * wip * wip * wip * wawa * woof * slight cleanup Im gonna go to sleep now * cleanup * a * review
This commit is contained in:
parent
90295503da
commit
9b359db2d6
7 changed files with 156 additions and 17 deletions
|
|
@ -1,6 +1,21 @@
|
|||
<DefaultWindow xmlns="https://spacestation14.io" Title="{Loc 'ghost-target-window-title'}" MinSize="450 450" SetSize="450 450">
|
||||
<DefaultWindow xmlns="https://spacestation14.io" Title="{Loc 'ghost-target-window-title'}" MinSize="450 450"
|
||||
SetSize="450 500">
|
||||
<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" />
|
||||
<BoxContainer Orientation="Vertical" Margin="0 4 0 4">
|
||||
<RichTextLabel Text="{Loc 'ghost-target-window-warp-to-title'}" HorizontalAlignment="Center" />
|
||||
<PanelContainer StyleClasses="LowDivider" Margin="0 5" />
|
||||
<BoxContainer Orientation="Horizontal" Align="Center">
|
||||
<Button Name="GhostnadoButton" Text="{Loc 'ghost-target-window-warp-to-most-followed'}"
|
||||
ToolTip="{Loc 'ghost-target-window-warp-to-most-followed-tooltip'}"
|
||||
HorizontalAlignment="Center" StyleClasses="OpenRight" />
|
||||
<Button Name="WarpToRandomFollowedButton" Text="{Loc 'ghost-target-window-warp-to-random-followed'}"
|
||||
ToolTip="{Loc 'ghost-target-window-warp-to-random-followed-tooltip'}"
|
||||
HorizontalAlignment="Center" StyleClasses="OpenBoth" />
|
||||
<Button Name="WarpToRandomButton" Text="{Loc 'ghost-target-window-warp-to-random'}"
|
||||
ToolTip="{Loc 'ghost-target-window-warp-to-random-tooltip'}" HorizontalAlignment="Center"
|
||||
StyleClasses="OpenLeft" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
<LineEdit Name="SearchBar" PlaceHolder="Search" HorizontalExpand="True" Margin="0 4" />
|
||||
<ScrollContainer Name="GhostScroll" VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False">
|
||||
<BoxContainer Name="ButtonContainer" Orientation="Vertical" VerticalExpand="True" SeparationOverride="5">
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
|
|||
|
||||
public event Action<NetEntity>? WarpClicked;
|
||||
public event Action? OnGhostnadoClicked;
|
||||
public event Action? OnWarpToRandomFollowedClicked;
|
||||
public event Action? OnWarpToRandomClicked;
|
||||
|
||||
public GhostTargetWindow()
|
||||
{
|
||||
|
|
@ -23,6 +25,8 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
|
|||
SearchBar.OnTextChanged += OnSearchTextChanged;
|
||||
|
||||
GhostnadoButton.OnPressed += _ => OnGhostnadoClicked?.Invoke();
|
||||
WarpToRandomFollowedButton.OnPressed += _ => OnWarpToRandomFollowedClicked?.Invoke();
|
||||
WarpToRandomButton.OnPressed += _ => OnWarpToRandomClicked?.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateWarps(IEnumerable<GhostWarp> warps)
|
||||
|
|
|
|||
|
|
@ -117,6 +117,18 @@ public sealed partial class GhostUIController : UIController, IOnSystemChanged<G
|
|||
_net.SendSystemNetworkMessage(msg);
|
||||
}
|
||||
|
||||
private void OnWarpToRandomFollowedClicked()
|
||||
{
|
||||
var msg = new WarpToRandomFollowedRequestEvent();
|
||||
_net.SendSystemNetworkMessage(msg);
|
||||
}
|
||||
|
||||
private void OnWarpToRandomClicked()
|
||||
{
|
||||
var msg = new WarpToRandomRequestEvent();
|
||||
_net.SendSystemNetworkMessage(msg);
|
||||
}
|
||||
|
||||
public void LoadGui()
|
||||
{
|
||||
if (Gui == null)
|
||||
|
|
@ -127,6 +139,8 @@ public sealed partial class GhostUIController : UIController, IOnSystemChanged<G
|
|||
Gui.GhostRolesPressed += GhostRolesPressed;
|
||||
Gui.TargetWindow.WarpClicked += OnWarpClicked;
|
||||
Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;
|
||||
Gui.TargetWindow.OnWarpToRandomFollowedClicked += OnWarpToRandomFollowedClicked;
|
||||
Gui.TargetWindow.OnWarpToRandomClicked += OnWarpToRandomClicked;
|
||||
|
||||
UpdateGui();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ using Content.Shared.Database;
|
|||
using Content.Shared.Eye;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Follower;
|
||||
using Content.Shared.Follower.Components;
|
||||
using Content.Shared.Ghost;
|
||||
using Content.Shared.GhostTypes;
|
||||
using Content.Shared.Mind;
|
||||
|
|
@ -68,6 +69,7 @@ namespace Content.Server.Ghost
|
|||
[Dependency] private GhostSpriteStateSystem _ghostState = default!;
|
||||
|
||||
[Dependency] private EntityQuery<GhostComponent> _ghostQuery = default!;
|
||||
[Dependency] private EntityQuery<FollowerComponent> _followerQuery = default!;
|
||||
[Dependency] private EntityQuery<PhysicsComponent> _physicsQuery = default!;
|
||||
|
||||
private static readonly ProtoId<TagPrototype> AllowGhostShownByEventTag = "AllowGhostShownByEvent";
|
||||
|
|
@ -91,6 +93,8 @@ namespace Content.Server.Ghost
|
|||
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
||||
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
||||
SubscribeNetworkEvent<GhostnadoRequestEvent>(OnGhostnadoRequest);
|
||||
SubscribeNetworkEvent<WarpToRandomFollowedRequestEvent>(OnWarpToRandomFollowedRequest);
|
||||
SubscribeNetworkEvent<WarpToRandomRequestEvent>(OnWarpToRandomRequest);
|
||||
|
||||
SubscribeLocalEvent<GhostComponent, BooActionEvent>(OnActionPerform);
|
||||
SubscribeLocalEvent<GhostComponent, ToggleGhostHearingActionEvent>(OnGhostHearingAction);
|
||||
|
|
@ -322,6 +326,9 @@ namespace Content.Server.Ghost
|
|||
GhostWarpRequest(args.SenderSession, msg.Target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to warp to the player with the most ghost followers.
|
||||
/// </summary>
|
||||
private void OnGhostnadoRequest(GhostnadoRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!CanGhostWarp(args.SenderSession, out var uid))
|
||||
|
|
@ -337,6 +344,48 @@ namespace Content.Server.Ghost
|
|||
_followerSystem.StartFollowingEntity(uid, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to warp to a random player with at least one ghost follower.
|
||||
/// </summary>
|
||||
private void OnWarpToRandomFollowedRequest(WarpToRandomFollowedRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!CanGhostWarp(args.SenderSession, out var uid))
|
||||
{
|
||||
Log.Warning($"User {args.SenderSession.Name} tried to warp to a random player with at least one ghost follower without being a ghost.");
|
||||
return;
|
||||
}
|
||||
|
||||
var following = _followerQuery.CompOrNull(uid)?.Following;
|
||||
if (_followerSystem.GetRandomGhostFollowed(except:following) is not {} target)
|
||||
return;
|
||||
|
||||
_followerSystem.StartFollowingEntity(uid, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request to warp to a random player.
|
||||
/// </summary>
|
||||
private void OnWarpToRandomRequest(WarpToRandomRequestEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
if (!CanGhostWarp(args.SenderSession, out var uid))
|
||||
{
|
||||
Log.Warning($"User {args.SenderSession.Name} tried to warp to a random player without being a ghost.");
|
||||
return;
|
||||
}
|
||||
|
||||
var following = _followerQuery.CompOrNull(uid)?.Following;
|
||||
// select player warps cuz no one wants to warp to places.
|
||||
if (GetPlayerWarps(following).ToArray() is not {} warps)
|
||||
return;
|
||||
if (warps.Length == 0)
|
||||
return;
|
||||
var warp = _random.Pick(warps);
|
||||
|
||||
var realTarget = GetEntity(warp.Entity);
|
||||
_followerSystem.StartFollowingEntity(uid, realTarget);
|
||||
}
|
||||
|
||||
|
||||
private void WarpTo(EntityUid uid, EntityUid target)
|
||||
{
|
||||
_adminLog.Add(LogType.GhostWarp, $"{ToPrettyString(uid)} ghost warped to {ToPrettyString(target)}");
|
||||
|
|
@ -364,7 +413,7 @@ namespace Content.Server.Ghost
|
|||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GhostWarp> GetPlayerWarps(EntityUid except)
|
||||
private IEnumerable<GhostWarp> GetPlayerWarps(EntityUid? except = null)
|
||||
{
|
||||
foreach (var player in _player.Sessions)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ using Robust.Shared.Physics;
|
|||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Follower;
|
||||
|
|
@ -33,6 +34,7 @@ public sealed partial class FollowerSystem : EntitySystem
|
|||
[Dependency] private SharedPhysicsSystem _physicsSystem = default!;
|
||||
[Dependency] private INetManager _netMan = default!;
|
||||
[Dependency] private ISharedAdminManager _adminManager = default!;
|
||||
[Dependency] private IRobustRandom _random = default!;
|
||||
|
||||
private static readonly ProtoId<TagPrototype> ForceableFollowTag = "ForceableFollow";
|
||||
private static readonly ProtoId<TagPrototype> PreventGhostnadoWarpTag = "NotGhostnadoWarpable";
|
||||
|
|
@ -317,13 +319,53 @@ public sealed partial class FollowerSystem : EntitySystem
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity with the most non-admin ghosts following it.
|
||||
/// Gets the player with the most non-admin ghosts following it.
|
||||
/// If there are multiple players with the same top amount of followers, picks one at random.
|
||||
/// </summary>
|
||||
public EntityUid? GetMostGhostFollowed()
|
||||
public EntityUid? GetMostGhostFollowed(EntityUid? except = null)
|
||||
{
|
||||
EntityUid? picked = null;
|
||||
var pool = new List<EntityUid>();
|
||||
var most = 0;
|
||||
|
||||
var followedEnts = GetAllFollowed(except);
|
||||
foreach (var (followed, followers) in followedEnts)
|
||||
{
|
||||
if (followers == most)
|
||||
{
|
||||
pool.Add(followed);
|
||||
}
|
||||
else if (followers > most)
|
||||
{
|
||||
pool.Clear();
|
||||
pool.Add(followed);
|
||||
most = followers;
|
||||
}
|
||||
}
|
||||
|
||||
return pool.Any() ? _random.Pick(pool) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random player that is being followed by at least one non-admin ghost.
|
||||
/// </summary>
|
||||
public EntityUid? GetRandomGhostFollowed(EntityUid? except = null)
|
||||
{
|
||||
var followedEnts = GetAllFollowed(except)
|
||||
.Where(item => item.Value > 0 && item.Key != except)
|
||||
.ToArray();
|
||||
if (followedEnts.Length == 0)
|
||||
return null;
|
||||
|
||||
var picked = _random.Pick(followedEnts);
|
||||
return picked.Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all players that are being followed by non-admin ghosts with a follower count for each.
|
||||
/// <remarks>Admin ghosts are excluded from the list of entities so that players can't spy on them.</remarks>
|
||||
/// </summary>
|
||||
private Dictionary<EntityUid, int> GetAllFollowed(EntityUid? except = null)
|
||||
{
|
||||
// Keep a tally of how many ghosts are following each entity
|
||||
var followedEnts = new Dictionary<EntityUid, int>();
|
||||
|
||||
|
|
@ -331,12 +373,15 @@ public sealed partial class FollowerSystem : EntitySystem
|
|||
var query = EntityQueryEnumerator<FollowerComponent, GhostComponent, ActorComponent>();
|
||||
while (query.MoveNext(out _, out var follower, out _, out var actor))
|
||||
{
|
||||
var followed = follower.Following;
|
||||
|
||||
if (follower.Following == except)
|
||||
continue;
|
||||
|
||||
// Don't count admin followers so that players cannot notice if admins are in stealth mode and following someone.
|
||||
if (_adminManager.IsAdmin(actor.PlayerSession))
|
||||
continue;
|
||||
|
||||
var followed = follower.Following;
|
||||
|
||||
// If the followed entity cannot be ghostnado'd to, we don't count it.
|
||||
// Used for making admins not warpable to, but IsAdmin isn't used for cases where the admin wants to be followed, for example during events.
|
||||
if (_tagSystem.HasTag(followed, PreventGhostnadoWarpTag))
|
||||
|
|
@ -345,15 +390,9 @@ public sealed partial class FollowerSystem : EntitySystem
|
|||
// Add new entry or increment existing
|
||||
followedEnts.TryGetValue(followed, out var currentValue);
|
||||
followedEnts[followed] = currentValue + 1;
|
||||
|
||||
if (followedEnts[followed] > most)
|
||||
{
|
||||
picked = followed;
|
||||
most = followedEnts[followed];
|
||||
}
|
||||
}
|
||||
|
||||
return picked;
|
||||
return followedEnts;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -189,11 +189,23 @@ namespace Content.Shared.Ghost
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// A client to server request for their ghost to be warped to the most followed entity.
|
||||
/// 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>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,13 @@ 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-target-window-warp-to-title = [bold]Quick Warp[/bold]
|
||||
ghost-target-window-warp-to-most-followed = Most Followed
|
||||
ghost-target-window-warp-to-random-followed = Random Followed
|
||||
ghost-target-window-warp-to-random = Random
|
||||
ghost-target-window-warp-to-most-followed-tooltip = Warp to the most followed player
|
||||
ghost-target-window-warp-to-random-followed-tooltip = Warp to a random followed player
|
||||
ghost-target-window-warp-to-random-tooltip = Warp to a random player
|
||||
|
||||
ghost-roles-window-title = Ghost Roles
|
||||
ghost-roles-window-available-button = Available ({$rolesCount})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue