Skip to content

Commit

Permalink
Ghost Bar (#200)
Browse files Browse the repository at this point in the history
* WhoYouGonnaCall

* fix

* fix

* Update ghost-gui.ftl

* Update Content.Server/_CorvaxNext/Ghostbar/GhostBarSystem.cs

Co-authored-by: FN <[email protected]>

* like this

---------

Co-authored-by: FN <[email protected]>
  • Loading branch information
Vonsant and FireNameFN authored Dec 26, 2024
1 parent 9dc9373 commit 9d58879
Show file tree
Hide file tree
Showing 15 changed files with 16,285 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Content.Client/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,12 @@ public void ToggleGhostVisibility(bool? visibility = null)
{
GhostVisibility = visibility ?? !GhostVisibility;
}

// Corvax-Next-GhostBar-Start
public void GhostBarSpawn()
{
RaiseNetworkEvent(new GhostBarSpawnEvent());
}
// Corvax-Next-GhostBar-End
}
}
16 changes: 16 additions & 0 deletions Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public void LoadGui()
Gui.GhostRolesPressed += GhostRolesPressed;
Gui.TargetWindow.WarpClicked += OnWarpClicked;
Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;
Gui.GhostBarPressed += GhostBarPressed; // Corvax-Next-GhostBar
Gui.GhostBarWindow.SpawnButtonPressed += GhostBarSpawnPressed; // Corvax-Next-GhostBar

UpdateGui();
}
Expand All @@ -140,6 +142,8 @@ public void UnloadGui()
Gui.ReturnToBodyPressed -= ReturnToBody;
Gui.GhostRolesPressed -= GhostRolesPressed;
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
Gui.GhostBarPressed -= GhostBarPressed; // Corvax-Next-GhostBar
Gui.GhostBarWindow.SpawnButtonPressed -= GhostBarSpawnPressed; // Corvax-Next-GhostBar

Gui.Hide();
}
Expand All @@ -160,4 +164,16 @@ private void GhostRolesPressed()
{
_system?.OpenGhostRoles();
}

// Corvax-Next-GhostBar-Start
private void GhostBarPressed()
{
Gui?.GhostBarWindow.OpenCentered();
}

private void GhostBarSpawnPressed()
{
_system?.GhostBarSpawn();
}
// Corvax-Next-GhostBar-End
}
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'}" /> <!-- Corvax-Next-GhostBar -->
</BoxContainer>
</widgets:GhostGui>
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,41 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Content.Client._CorvaxNext.UserInterface.Systems.Ghost.Controls;

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

[GenerateTypedNameReferences]
public sealed partial class GhostGui : UIWidget
{
public GhostTargetWindow TargetWindow { get; }
public GhostBarRulesWindow GhostBarWindow { get; } // Corvax-Next-GhostBar

public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
public event Action? GhostBarPressed; // Corvax-Next-GhostBar

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

TargetWindow = new GhostTargetWindow();

GhostBarWindow = new GhostBarRulesWindow(); // Corvax-Next-GhostBar

MouseFilter = MouseFilterMode.Ignore;

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

public void Hide()
{
TargetWindow.Close();
GhostBarWindow.Close(); // Corvax-Next-GhostBar
Visible = false;
}

Expand Down Expand Up @@ -61,6 +68,7 @@ protected override void Dispose(bool disposing)
if (disposing)
{
TargetWindow.Dispose();
GhostBarWindow.Dispose(); // Corvax-Next-GhostBar
}
}
}
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="600 400"
SetSize="600 400">
<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.Controls;
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._CorvaxNext.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
@@ -0,0 +1,7 @@
namespace Content.Server._CorvaxNext.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._CorvaxNext.Ghostbar.Components;

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

namespace Content.Server._CorvaxNext.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!;

private const string MapPath = "Maps/Nonstations/ghostbar.yml";

private static readonly List<ProtoId<JobPrototype>> _jobComponents = ["Passenger", "Bartender", "Chef"];

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

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(GhostBarSpawnEvent msg, EntitySessionEventArgs args)
{
var player = args.SenderSession;

if (!_mindSystem.TryGetMind(player, out var mindId, out var mind))
{
Log.Warning($"Failed to find mind for player {player.Name}.");
return;
}

if (!_entityManager.HasComponent<GhostComponent>(player.AttachedEntity))
{
Log.Warning($"User {player.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 data = player.ContentData();

if (data == null)
{
Log.Warning($"ContentData was null when trying to spawn {player.Name} in 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);
_entityManager.EnsureComponent<MindShieldComponent>(mobUid);
_entityManager.EnsureComponent<AntagImmuneComponent>(mobUid);
_entityManager.EnsureComponent<IsDeadICComponent>(mobUid);

if (mind.Objectives.Count == 0)
_mindSystem.WipeMind(player);
mindId = _mindSystem.CreateMind(data.UserId, profile.Name).Owner;
_mindSystem.TransferTo(mindId, mobUid, true);
}

private void OnPlayerGhosted(EntityUid uid, GhostBarPlayerComponent component, MindRemovedMessage args)
{
_entityManager.DeleteEntity(uid);
}
}
7 changes: 7 additions & 0 deletions Content.Shared/Ghost/SharedGhostSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public sealed class GhostWarpsRequestEvent : EntityEventArgs
{
}

// Corvax-Next-GhostBar-Start: A server to client request for them to spawn at the ghost bar
[Serializable, NetSerializable]
public sealed class GhostBarSpawnEvent : EntityEventArgs
{
}
// Corvax-Next-GhostBar-End

/// <summary>
/// An individual place a ghost can warp to.
/// This is used as part of <see cref="GhostWarpsResponseEvent"/>
Expand Down
4 changes: 4 additions & 0 deletions Resources/Locale/en-US/_corvaxnext/guidebook/ghost-gui.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ghost-target-window-ghostbar = Ghost Bar
ghost-window-spawn-ghostbar-button = Spawn at Ghost Bar
ghost-window-spawn-ghostbar-button-timer = Spawn at 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.
4 changes: 4 additions & 0 deletions Resources/Locale/ru-RU/_corvaxnext/guidebook/ghost-gui.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ghost-target-window-ghostbar = Призрачный Бар
ghost-window-spawn-ghostbar-button = Возродиться в Баре
ghost-window-spawn-ghostbar-button-timer = Возродиться в Баре через ({$time}с)
ghost-bar-rules = Заходя в призрачный бар вы теряете возможность быть возвращены в тело. Находясь в баре придерживайтесь правил обычного призрака. Вы можете обсуждать любые текущие события раунда в открытом чате (без использования LOOC) и сохраняете воспоминания о своей прошлой жизни. ЗАПРЕЩЕНО нападать на других игроков, провоцировать конфликты и повреждать имущество бара. Если вы заметите нарушителей, сообщите администрации через Ahelp, и они будут немедленно отправлены в открытый космос. Покинув Призрачный Бар, вы полностью забудете все, что происходило здесь, а также события вашей прошлой жизни.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ent-GhostBarSpawner = спавнер призрачный бар
.desc = { ent-MarkerBase.desc }
Loading

0 comments on commit 9d58879

Please sign in to comment.