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

Port Ghost Bar #904

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion Content.Client/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ public void OpenGhostRoles()
_console.RemoteExecuteCommand(null, "ghostroles");
}

public void ToggleGhostVisibility()
public void GhostBarSpawn()
{
RaiseNetworkEvent(new GhostBarSpawnRequestEvent());
}

public void ToggleGhostVisibility(bool? visibility = null)
{
GhostVisibility = !GhostVisibility;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ghost-target-window-ghostbar'}"
MinSize="500 300"
SetSize="500 300">
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<RichTextLabel Name="TopBanner" VerticalExpand="True"/>
<Button Name="SpawnButton"
Text="{Loc 'ghost-window-spawn-ghostbar-button'}"
Disabled="True"
TextAlign="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</BoxContainer>
</DefaultWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.UserInterface.Systems.Ghost.Controls;

[GenerateTypedNameReferences]
public sealed partial class GhostBarRulesWindow : DefaultWindow
{
[Dependency] private readonly IConfigurationManager _cfg = IoCManager.Resolve<IConfigurationManager>();
private float _timer;

public event Action? SpawnButtonPressed;
public GhostBarRulesWindow()
{
RobustXamlLoader.Load(this);
var ghostBarTime = _cfg.GetCVar(CCVars.GhostRoleTime);
_timer = ghostBarTime;

if (ghostBarTime > 0f)
{
SpawnButton.Text = Loc.GetString("ghost-window-spawn-ghostbar-button-timer", ("time", $"{_timer:0.0}"));
TopBanner.SetMessage(FormattedMessage.FromMarkupPermissive(Loc.GetString("ghost-bar-rules") + "\n" + Loc.GetString("ghost-roles-window-rules-footer", ("time", ghostBarTime))));
SpawnButton.Disabled = true;
}

SpawnButton.OnPressed += _ => SpawnButtonPressed?.Invoke();
}


protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!SpawnButton.Disabled)
return;

if (_timer > 0.0)
{
_timer -= args.DeltaSeconds;
SpawnButton.Text = Loc.GetString("ghost-window-spawn-ghostbar-button-timer", ("time", $"{_timer:0.0}"));
}
else
{
SpawnButton.Disabled = false;
SpawnButton.Text = Loc.GetString("ghost-window-spawn-ghostbar-button");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace Content.Client.UserInterface.Systems.Ghost;
public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSystem>
{
[Dependency] private readonly IEntityNetworkManager _net = default!;

[UISystemDependency] private readonly GhostSystem? _system = default;

private GhostGui? Gui => UIManager.GetActiveUIWidgetOrNull<GhostGui>();


public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -119,6 +119,8 @@ public void LoadGui()
Gui.RequestWarpsPressed += RequestWarps;
Gui.ReturnToBodyPressed += ReturnToBody;
Gui.GhostRolesPressed += GhostRolesPressed;
Gui.GhostBarPressed += GhostBarPressed;
Gui.GhostBarWindow.SpawnButtonPressed += GhostBarSpawnPressed;
Gui.TargetWindow.WarpClicked += OnWarpClicked;

UpdateGui();
Expand All @@ -132,6 +134,8 @@ public void UnloadGui()
Gui.RequestWarpsPressed -= RequestWarps;
Gui.ReturnToBodyPressed -= ReturnToBody;
Gui.GhostRolesPressed -= GhostRolesPressed;
Gui.GhostBarPressed -= GhostBarPressed;
Gui.GhostBarWindow.SpawnButtonPressed -= GhostBarSpawnPressed;
Gui.TargetWindow.WarpClicked -= OnWarpClicked;

Gui.Hide();
Expand All @@ -153,4 +157,14 @@ private void GhostRolesPressed()
{
_system?.OpenGhostRoles();
}

private void GhostBarPressed()
{
Gui?.GhostBarWindow.OpenCentered();
}

private void GhostBarSpawnPressed()
{
_system?.GhostBarSpawn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
<Button Name="GhostRolesButton" />
<Button Name="GhostBarButton" Text="{Loc 'ghost-target-window-ghostbar'}" />
</BoxContainer>
</widgets:GhostGui>
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,33 @@ namespace Content.Client.UserInterface.Systems.Ghost.Widgets;
public sealed partial class GhostGui : UIWidget
{
public GhostTargetWindow TargetWindow { get; }
public GhostBarRulesWindow GhostBarWindow { get; }

public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
public event Action? GhostBarPressed;

public GhostGui()
{
RobustXamlLoader.Load(this);

TargetWindow = new GhostTargetWindow();

GhostBarWindow = new GhostBarRulesWindow();

MouseFilter = MouseFilterMode.Ignore;

GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
GhostBarButton.OnPressed += _ => GhostBarPressed?.Invoke();
}

public void Hide()
{
TargetWindow.Close();
GhostBarWindow.Close();
Visible = false;
}

Expand Down Expand Up @@ -61,6 +67,7 @@ protected override void Dispose(bool disposing)
if (disposing)
{
TargetWindow.Dispose();
GhostBarWindow.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.Ghostbar.Components;

/// <summary>
/// Tracker for ghostbar players
/// </summary>
[RegisterComponent]
public sealed partial class GhostBarPlayerComponent : Component { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.Ghostbar.Components;

/// <summary>
/// Target for ghosts to spawn at
/// </summary>
[RegisterComponent]
public sealed partial class GhostBarSpawnComponent : Component { }
95 changes: 95 additions & 0 deletions Content.Server/Ghostbar/GhostBarSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using Robust.Server.GameObjects;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Events;
using Content.Server.Station.Systems;
using Robust.Shared.Map;
using Robust.Server.Maps;
using Robust.Shared.Random;
using Content.Shared.Ghost;
using Content.Server.Ghostbar.Components;
using Content.Server.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Roles.Jobs;

namespace Content.Server.Ghostbar;

public sealed class GhostBarSystem : EntitySystem
{
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly StationSpawningSystem _spawningSystem = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;


const string MapPath = "Maps/Ruins/ghostbar.yml";
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved

private static readonly List<JobComponent> JobComponents = new()
{
new JobComponent { Prototype = "Passenger" },
new JobComponent { Prototype = "Bartender" },
new JobComponent { Prototype = "Botanist" },
new JobComponent { Prototype = "Chef" },
new JobComponent { Prototype = "Janitor" }
Comment on lines +31 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to be validated.

};


public override void Initialize()
{
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
SubscribeNetworkEvent<GhostBarSpawnRequestEvent>(SpawnPlayer);
SubscribeLocalEvent<GhostBarPlayerComponent, MindRemovedMessage>(OnPlayerGhosted);
}

VMSolidus marked this conversation as resolved.
Show resolved Hide resolved

private void OnRoundStart(RoundStartingEvent ev)
{
_mapSystem.CreateMap(out var mapId);
var options = new MapLoadOptions { LoadMap = true };

if (_mapLoader.TryLoad(mapId, MapPath, out _, options))
_mapSystem.SetPaused(mapId, false);
}

public void SpawnPlayer(GhostBarSpawnRequestEvent msg, EntitySessionEventArgs args)
{
if (!_entityManager.HasComponent<GhostComponent>(args.SenderSession.AttachedEntity))
{
Log.Warning($"User {args.SenderSession.Name} tried to spawn at ghost bar without being a ghost.");
return;
}

var spawnPoints = new List<EntityCoordinates>();
var query = EntityQueryEnumerator<GhostBarSpawnComponent>();
while (query.MoveNext(out var ent, out _))
spawnPoints.Add(_entityManager.GetComponent<TransformComponent>(ent).Coordinates);

if (spawnPoints.Count == 0)
{
Log.Warning("No spawn points found for ghost bar.");
return;
}


var randomSpawnPoint = _random.Pick(spawnPoints);
var randomJob = _random.Pick(JobComponents);
var profile = _ticker.GetPlayerProfile(args.SenderSession);
var mobUid = _spawningSystem.SpawnPlayerMob(randomSpawnPoint, randomJob, profile, null);

_entityManager.EnsureComponent<GhostBarPlayerComponent>(mobUid);

var targetMind = _mindSystem.GetMind(args.SenderSession.UserId);


if (targetMind != null)
_mindSystem.TransferTo(targetMind.Value, mobUid, true);
}

private void OnPlayerGhosted(EntityUid uid, GhostBarPlayerComponent component, MindRemovedMessage args)
{
_entityManager.DeleteEntity(uid);
}
}

6 changes: 6 additions & 0 deletions Content.Shared/Ghost/SharedGhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public sealed class GhostWarpsRequestEvent : EntityEventArgs
{
}

/// <summary>
/// A server to client request for them to spawn at the ghost bar
/// </summary>
[Serializable, NetSerializable]
public sealed class GhostBarSpawnRequestEvent : EntityEventArgs { }

/// <summary>
/// An individual place a ghost can warp to.
/// This is used as part of <see cref="GhostWarpsResponseEvent"/>
Expand Down
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/Goobstation/guidebook/ghost-gui.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ghost-target-window-ghostbar = Ghost Bar
ghost-window-spawn-ghostbar-button = Spawn at the Ghost Bar
ghost-window-spawn-ghostbar-button-timer = Spawn at the Ghost Bar ({$time}s)
ghost-bar-rules = Treat this role, and station, as you would just being a regular Ghost. You may talk about all current round events without the need for LOOC, and you remember everything from your previous life. DO NOT attack others, start fights, or attempt to break the station. If you see anyone doing this, please AHelp and they will be promptly thrown into space. Also, if you decide to leave the bar, you DO NOT remember anything from being here, or your life before it.

Loading
Loading