mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description This ports https://github.com/WWhiteDreamProject/wwdpublic/pull/56 The new Respawn System is one that allows players to return themselves to the lobby after a configurable delay, while also requiring that they respawn as a different character upon returning. # TODO - [x] Finish the usual cleanup # Changelog 🆑 - add: Ported a Respawn System. This system allows players to return themselves to the lobby, while also requiring that if they re-enter the round, that they must do so on a different character. --------- Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> # Conflicts: # Resources/Locale/ru-RU/ghost/ghost-gui.ftl
81 lines
3.1 KiB
C#
81 lines
3.1 KiB
C#
using Content.Server.Administration.Logs;
|
|
using Content.Server.Chat.Managers;
|
|
using Content.Server.GameTicking;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Ghost;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Server.Ghost;
|
|
|
|
public sealed class GhostReturnToRoundSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
[Dependency] private readonly GameTicker _ticker = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeNetworkEvent<GhostReturnToRoundRequest>(OnGhostReturnToRoundRequest);
|
|
}
|
|
|
|
private void OnGhostReturnToRoundRequest(GhostReturnToRoundRequest msg, EntitySessionEventArgs args)
|
|
{
|
|
var uid = args.SenderSession.AttachedEntity;
|
|
|
|
if (uid == null)
|
|
return;
|
|
|
|
var connectedClient = args.SenderSession.Channel;
|
|
var userId = args.SenderSession.UserId;
|
|
|
|
TryGhostReturnToRound(uid.Value, connectedClient, userId, out var message, out var wrappedMessage);
|
|
|
|
_chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server,
|
|
message,
|
|
wrappedMessage,
|
|
default,
|
|
false,
|
|
connectedClient,
|
|
Color.Red);
|
|
}
|
|
|
|
private void TryGhostReturnToRound(EntityUid uid, INetChannel connectedClient, NetUserId userId, out string message, out string wrappedMessage)
|
|
{
|
|
var maxPlayers = _cfg.GetCVar(CCVars.GhostRespawnMaxPlayers);
|
|
if (_playerManager.PlayerCount >= maxPlayers)
|
|
{
|
|
message = Loc.GetString("ghost-respawn-max-players", ("players", maxPlayers));
|
|
wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
|
|
return;
|
|
}
|
|
|
|
var deathTime = EnsureComp<GhostComponent>(uid).TimeOfDeath;
|
|
var timeUntilRespawn = _cfg.GetCVar(CCVars.GhostRespawnTime);
|
|
var timePast = (_gameTiming.CurTime - deathTime).TotalMinutes;
|
|
if (timePast >= timeUntilRespawn)
|
|
{
|
|
_playerManager.TryGetSessionById(userId, out var targetPlayer);
|
|
|
|
if (targetPlayer != null)
|
|
_ticker.Respawn(targetPlayer);
|
|
|
|
_adminLogger.Add(LogType.Mind, LogImpact.Medium, $"{Loc.GetString("ghost-respawn-log-return-to-lobby", ("userName", connectedClient.UserName))}");
|
|
|
|
message = Loc.GetString("ghost-respawn-window-rules-footer");
|
|
wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
|
|
|
|
return;
|
|
}
|
|
|
|
message = Loc.GetString("ghost-respawn-time-left", ("time", (int) (timeUntilRespawn - timePast)));
|
|
wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", message));
|
|
}
|
|
}
|