diff --git a/Content.Client/Ghost/GhostSystem.cs b/Content.Client/Ghost/GhostSystem.cs
index f6913d2578..f60b92f13e 100644
--- a/Content.Client/Ghost/GhostSystem.cs
+++ b/Content.Client/Ghost/GhostSystem.cs
@@ -182,5 +182,11 @@ namespace Content.Client.Ghost
{
GhostVisibility = !GhostVisibility;
}
+
+ public void ReturnToRound()
+ {
+ var msg = new GhostReturnToRoundRequest();
+ RaiseNetworkEvent(msg);
+ }
}
}
diff --git a/Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs b/Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
index 12d6c65953..e40757cf85 100644
--- a/Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
+++ b/Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
@@ -120,6 +120,8 @@ public sealed class GhostUIController : UIController, IOnSystemChanged
+
diff --git a/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs b/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs
index 0f64e8a275..9a6ae93a52 100644
--- a/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs
+++ b/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs
@@ -15,6 +15,9 @@ public sealed partial class GhostGui : UIWidget
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
+ public event Action? ReturnToRoundPressed;
+
+
public GhostGui()
{
RobustXamlLoader.Load(this);
@@ -26,6 +29,7 @@ public sealed partial class GhostGui : UIWidget
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
+ ReturnToRound.OnPressed += _ => ReturnToRoundPressed?.Invoke();
}
public void Hide()
diff --git a/Content.Server/GameTicking/GameTicker.GamePreset.cs b/Content.Server/GameTicking/GameTicker.GamePreset.cs
index 04f7be016a..a9d249a072 100644
--- a/Content.Server/GameTicking/GameTicker.GamePreset.cs
+++ b/Content.Server/GameTicking/GameTicker.GamePreset.cs
@@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameTicking.Presets;
using Content.Server.Maps;
+using Content.Server.Ghost;
using Content.Shared.CCVar;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
@@ -21,6 +22,7 @@ namespace Content.Server.GameTicking
public sealed partial class GameTicker
{
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
+ [Dependency] private readonly GhostSystem _ghostSystem = default!;
public const float PresetFailedCooldownIncrease = 30f;
@@ -303,6 +305,11 @@ namespace Content.Server.GameTicking
_mind.Visit(mindId, ghost, mind);
else
_mind.TransferTo(mindId, ghost, mind: mind);
+
+ var player = mind.Session;
+ var userId = player!.UserId;
+ if (!_ghostSystem._deathTime.TryGetValue(userId, out _))
+ _ghostSystem._deathTime[userId] = _gameTiming.CurTime;
return true;
}
diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs
index 3902845004..2a525859cb 100644
--- a/Content.Server/GameTicking/GameTicker.Spawning.cs
+++ b/Content.Server/GameTicking/GameTicker.Spawning.cs
@@ -9,6 +9,7 @@ using Content.Server.Speech.Components;
using Content.Server.Station.Components;
using Content.Shared.CCVar;
using Content.Shared.Database;
+using Content.Shared.GameTicking;
using Content.Shared.Players;
using Content.Shared.Preferences;
using Content.Shared.Roles;
@@ -377,6 +378,7 @@ namespace Content.Server.GameTicking
}
var name = GetPlayerProfile(player).Name;
+
var ghost = SpawnObserverMob();
_metaData.SetEntityName(ghost, name);
_ghost.SetCanReturnToBody(ghost, false);
diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs
index acdeca9af0..d8b1c26f76 100644
--- a/Content.Server/Ghost/GhostSystem.cs
+++ b/Content.Server/Ghost/GhostSystem.cs
@@ -1,14 +1,18 @@
using System.Linq;
using System.Numerics;
+using Content.Server.Administration.Logs;
+using Content.Server.Chat.Managers;
using Content.Server.GameTicking;
using Content.Server.Ghost.Components;
using Content.Server.Mind;
using Content.Server.Roles.Jobs;
using Content.Server.Warps;
using Content.Shared.Actions;
+using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Eye;
using Content.Shared.Follower;
+using Content.Shared.GameTicking;
using Content.Shared.Ghost;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
@@ -19,6 +23,9 @@ using Content.Shared.Movement.Systems;
using Content.Shared.Storage.Components;
using Robust.Server.GameObjects;
using Robust.Server.Player;
+using Content.Shared.White;
+using Robust.Shared.Configuration;
+using Robust.Shared.Network;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
@@ -42,6 +49,8 @@ namespace Content.Server.Ghost
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
+ [Dependency] private readonly IChatManager _chatManager = default!;
+ [Dependency] private readonly IAdminLogManager _adminLogger = default!;
public override void Initialize()
{
@@ -63,11 +72,76 @@ namespace Content.Server.Ghost
SubscribeNetworkEvent(OnGhostReturnToBodyRequest);
SubscribeNetworkEvent(OnGhostWarpToTargetRequest);
+ SubscribeNetworkEvent(OnGhostReturnToRoundRequest);
+
SubscribeLocalEvent(OnActionPerform);
SubscribeLocalEvent(OnGhostHearingAction);
SubscribeLocalEvent(OnEntityStorageInsertAttempt);
SubscribeLocalEvent(_ => MakeVisible(true));
+ SubscribeLocalEvent(ResetDeathTimes);
+ }
+
+ public readonly Dictionary _deathTime = new();
+
+ private void ResetDeathTimes(RoundRestartCleanupEvent ev)
+ {
+ _deathTime.Clear();
+ }
+
+ private void OnGhostReturnToRoundRequest(GhostReturnToRoundRequest msg, EntitySessionEventArgs args)
+ {
+ var cfg = IoCManager.Resolve();
+ var maxPlayers = cfg.GetCVar(WhiteCVars.GhostRespawnMaxPlayers);
+ if (_playerManager.PlayerCount >= maxPlayers)
+ {
+ var message = Loc.GetString("ghost-respawn-max-players", ("players", maxPlayers));
+ var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
+ _chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server, message,
+ wrappedMessage, default, false, args.SenderSession.ConnectedClient, Color.Red);
+ return;
+ }
+
+ var userId = args.SenderSession.UserId;
+ if (userId == null)
+ return;
+ if (!_deathTime.TryGetValue(userId, out var deathTime))
+ {
+ var message = Loc.GetString("ghost-respawn-bug");
+ var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
+ _chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server, message,
+ wrappedMessage, default, false, args.SenderSession.ConnectedClient, Color.Red);
+ _deathTime[userId] = _gameTiming.CurTime;
+ return;
+ }
+
+ var timeUntilRespawn = (double)cfg.GetCVar(WhiteCVars.GhostRespawnTime);
+ var timePast = (_gameTiming.CurTime - deathTime).TotalMinutes;
+ if (timePast >= timeUntilRespawn)
+ {
+ var ticker = Get();
+ var playerMgr = IoCManager.Resolve();
+ playerMgr.TryGetSessionById(userId, out var targetPlayer);
+
+ if (targetPlayer != null)
+ ticker.Respawn(targetPlayer);
+ _deathTime.Remove(userId);
+
+ _adminLogger.Add(LogType.Mind, LogImpact.Extreme, $"{args.SenderSession.ConnectedClient.UserName} вернулся в лобби посредством гост респавна.");
+
+ var message = Loc.GetString("ghost-respawn-window-rules-footer");
+ var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
+ _chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server, message,
+ wrappedMessage, default, false, args.SenderSession.ConnectedClient, Color.Red);
+
+ }
+ else
+ {
+ var message = Loc.GetString("ghost-respawn-time-left", ("time", (int)(timeUntilRespawn-timePast)));
+ var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
+ _chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server, message,
+ wrappedMessage, default, false, args.SenderSession.ConnectedClient, Color.Red);
+ }
}
private void OnGhostHearingAction(EntityUid uid, GhostComponent component, ToggleGhostHearingActionEvent args)
diff --git a/Content.Shared/Ghost/SharedGhostSystem.cs b/Content.Shared/Ghost/SharedGhostSystem.cs
index c1c2c3c71e..8102d38c08 100644
--- a/Content.Shared/Ghost/SharedGhostSystem.cs
+++ b/Content.Shared/Ghost/SharedGhostSystem.cs
@@ -146,4 +146,10 @@ namespace Content.Shared.Ghost
AvailableGhostRoles = availableGhostRoleCount;
}
}
+
+
+ [Serializable, NetSerializable]
+ public sealed class GhostReturnToRoundRequest : EntityEventArgs
+ {
+ }
}
diff --git a/Content.Shared/White/WhiteCVars.cs b/Content.Shared/White/WhiteCVars.cs
index d1bb94e197..4863551139 100644
--- a/Content.Shared/White/WhiteCVars.cs
+++ b/Content.Shared/White/WhiteCVars.cs
@@ -140,4 +140,14 @@ public sealed class WhiteCVars
public static readonly CVarDef MeatyOreDefaultBalance =
CVarDef.Create("white.meatyore_default_balance", 15, CVar.SERVER | CVar.ARCHIVE);
+
+ /*
+ * Ghost Respawn
+ */
+
+ public static readonly CVarDef GhostRespawnTime =
+ CVarDef.Create("ghost.respawn_time", 15f, CVar.SERVERONLY);
+
+ public static readonly CVarDef GhostRespawnMaxPlayers =
+ CVarDef.Create("ghost.respawn_max_players", 40, CVar.SERVERONLY);
}