[add] New ghostrespawn system
This commit is contained in:
@@ -182,5 +182,11 @@ namespace Content.Client.Ghost
|
|||||||
{
|
{
|
||||||
GhostVisibility = !GhostVisibility;
|
GhostVisibility = !GhostVisibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReturnToRound()
|
||||||
|
{
|
||||||
|
var msg = new GhostReturnToRoundRequest();
|
||||||
|
RaiseNetworkEvent(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
|||||||
Gui.ReturnToBodyPressed += ReturnToBody;
|
Gui.ReturnToBodyPressed += ReturnToBody;
|
||||||
Gui.GhostRolesPressed += GhostRolesPressed;
|
Gui.GhostRolesPressed += GhostRolesPressed;
|
||||||
Gui.TargetWindow.WarpClicked += OnWarpClicked;
|
Gui.TargetWindow.WarpClicked += OnWarpClicked;
|
||||||
|
Gui.ReturnToRoundPressed += ReturnToRound;
|
||||||
|
|
||||||
|
|
||||||
UpdateGui();
|
UpdateGui();
|
||||||
}
|
}
|
||||||
@@ -133,6 +135,8 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
|||||||
Gui.ReturnToBodyPressed -= ReturnToBody;
|
Gui.ReturnToBodyPressed -= ReturnToBody;
|
||||||
Gui.GhostRolesPressed -= GhostRolesPressed;
|
Gui.GhostRolesPressed -= GhostRolesPressed;
|
||||||
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
|
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
|
||||||
|
Gui.ReturnToRoundPressed -= ReturnToRound;
|
||||||
|
|
||||||
|
|
||||||
Gui.Hide();
|
Gui.Hide();
|
||||||
}
|
}
|
||||||
@@ -142,6 +146,11 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
|||||||
_system?.ReturnToBody();
|
_system?.ReturnToBody();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ReturnToRound()
|
||||||
|
{
|
||||||
|
_system?.ReturnToRound();
|
||||||
|
}
|
||||||
|
|
||||||
private void RequestWarps()
|
private void RequestWarps()
|
||||||
{
|
{
|
||||||
_system?.RequestWarps();
|
_system?.RequestWarps();
|
||||||
|
|||||||
@@ -5,5 +5,6 @@
|
|||||||
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
|
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
|
||||||
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
|
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
|
||||||
<Button Name="GhostRolesButton" />
|
<Button Name="GhostRolesButton" />
|
||||||
|
<Button Name="ReturnToRound" Text="{Loc ghost-gui-return-to-round-button}" />
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
</widgets:GhostGui>
|
</widgets:GhostGui>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ public sealed partial class GhostGui : UIWidget
|
|||||||
public event Action? ReturnToBodyPressed;
|
public event Action? ReturnToBodyPressed;
|
||||||
public event Action? GhostRolesPressed;
|
public event Action? GhostRolesPressed;
|
||||||
|
|
||||||
|
public event Action? ReturnToRoundPressed;
|
||||||
|
|
||||||
|
|
||||||
public GhostGui()
|
public GhostGui()
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
@@ -26,6 +29,7 @@ public sealed partial class GhostGui : UIWidget
|
|||||||
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
|
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
|
||||||
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
|
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
|
||||||
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
|
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
|
||||||
|
ReturnToRound.OnPressed += _ => ReturnToRoundPressed?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Hide()
|
public void Hide()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.GameTicking.Presets;
|
using Content.Server.GameTicking.Presets;
|
||||||
using Content.Server.Maps;
|
using Content.Server.Maps;
|
||||||
|
using Content.Server.Ghost;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Damage.Prototypes;
|
using Content.Shared.Damage.Prototypes;
|
||||||
@@ -21,6 +22,7 @@ namespace Content.Server.GameTicking
|
|||||||
public sealed partial class GameTicker
|
public sealed partial class GameTicker
|
||||||
{
|
{
|
||||||
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
|
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
|
||||||
|
[Dependency] private readonly GhostSystem _ghostSystem = default!;
|
||||||
|
|
||||||
public const float PresetFailedCooldownIncrease = 30f;
|
public const float PresetFailedCooldownIncrease = 30f;
|
||||||
|
|
||||||
@@ -303,6 +305,11 @@ namespace Content.Server.GameTicking
|
|||||||
_mind.Visit(mindId, ghost, mind);
|
_mind.Visit(mindId, ghost, mind);
|
||||||
else
|
else
|
||||||
_mind.TransferTo(mindId, ghost, mind: mind);
|
_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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Content.Server.Speech.Components;
|
|||||||
using Content.Server.Station.Components;
|
using Content.Server.Station.Components;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Players;
|
using Content.Shared.Players;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
using Content.Shared.Roles;
|
using Content.Shared.Roles;
|
||||||
@@ -377,6 +378,7 @@ namespace Content.Server.GameTicking
|
|||||||
}
|
}
|
||||||
|
|
||||||
var name = GetPlayerProfile(player).Name;
|
var name = GetPlayerProfile(player).Name;
|
||||||
|
|
||||||
var ghost = SpawnObserverMob();
|
var ghost = SpawnObserverMob();
|
||||||
_metaData.SetEntityName(ghost, name);
|
_metaData.SetEntityName(ghost, name);
|
||||||
_ghost.SetCanReturnToBody(ghost, false);
|
_ghost.SetCanReturnToBody(ghost, false);
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using Content.Server.Administration.Logs;
|
||||||
|
using Content.Server.Chat.Managers;
|
||||||
using Content.Server.GameTicking;
|
using Content.Server.GameTicking;
|
||||||
using Content.Server.Ghost.Components;
|
using Content.Server.Ghost.Components;
|
||||||
using Content.Server.Mind;
|
using Content.Server.Mind;
|
||||||
using Content.Server.Roles.Jobs;
|
using Content.Server.Roles.Jobs;
|
||||||
using Content.Server.Warps;
|
using Content.Server.Warps;
|
||||||
using Content.Shared.Actions;
|
using Content.Shared.Actions;
|
||||||
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Eye;
|
using Content.Shared.Eye;
|
||||||
using Content.Shared.Follower;
|
using Content.Shared.Follower;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Ghost;
|
using Content.Shared.Ghost;
|
||||||
using Content.Shared.Mind;
|
using Content.Shared.Mind;
|
||||||
using Content.Shared.Mind.Components;
|
using Content.Shared.Mind.Components;
|
||||||
@@ -19,6 +23,9 @@ using Content.Shared.Movement.Systems;
|
|||||||
using Content.Shared.Storage.Components;
|
using Content.Shared.Storage.Components;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
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.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
@@ -42,6 +49,8 @@ namespace Content.Server.Ghost
|
|||||||
[Dependency] private readonly GameTicker _ticker = default!;
|
[Dependency] private readonly GameTicker _ticker = default!;
|
||||||
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
||||||
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
|
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
|
||||||
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -63,11 +72,76 @@ namespace Content.Server.Ghost
|
|||||||
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
SubscribeNetworkEvent<GhostReturnToBodyRequest>(OnGhostReturnToBodyRequest);
|
||||||
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
|
||||||
|
|
||||||
|
SubscribeNetworkEvent<GhostReturnToRoundRequest>(OnGhostReturnToRoundRequest);
|
||||||
|
|
||||||
SubscribeLocalEvent<GhostComponent, BooActionEvent>(OnActionPerform);
|
SubscribeLocalEvent<GhostComponent, BooActionEvent>(OnActionPerform);
|
||||||
SubscribeLocalEvent<GhostComponent, ToggleGhostHearingActionEvent>(OnGhostHearingAction);
|
SubscribeLocalEvent<GhostComponent, ToggleGhostHearingActionEvent>(OnGhostHearingAction);
|
||||||
SubscribeLocalEvent<GhostComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
|
SubscribeLocalEvent<GhostComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
|
||||||
|
|
||||||
SubscribeLocalEvent<RoundEndTextAppendEvent>(_ => MakeVisible(true));
|
SubscribeLocalEvent<RoundEndTextAppendEvent>(_ => MakeVisible(true));
|
||||||
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(ResetDeathTimes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly Dictionary<NetUserId, TimeSpan> _deathTime = new();
|
||||||
|
|
||||||
|
private void ResetDeathTimes(RoundRestartCleanupEvent ev)
|
||||||
|
{
|
||||||
|
_deathTime.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGhostReturnToRoundRequest(GhostReturnToRoundRequest msg, EntitySessionEventArgs args)
|
||||||
|
{
|
||||||
|
var cfg = IoCManager.Resolve<IConfigurationManager>();
|
||||||
|
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<GameTicker>();
|
||||||
|
var playerMgr = IoCManager.Resolve<IPlayerManager>();
|
||||||
|
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)
|
private void OnGhostHearingAction(EntityUid uid, GhostComponent component, ToggleGhostHearingActionEvent args)
|
||||||
|
|||||||
@@ -146,4 +146,10 @@ namespace Content.Shared.Ghost
|
|||||||
AvailableGhostRoles = availableGhostRoleCount;
|
AvailableGhostRoles = availableGhostRoleCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class GhostReturnToRoundRequest : EntityEventArgs
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,4 +140,14 @@ public sealed class WhiteCVars
|
|||||||
|
|
||||||
public static readonly CVarDef<int> MeatyOreDefaultBalance =
|
public static readonly CVarDef<int> MeatyOreDefaultBalance =
|
||||||
CVarDef.Create("white.meatyore_default_balance", 15, CVar.SERVER | CVar.ARCHIVE);
|
CVarDef.Create("white.meatyore_default_balance", 15, CVar.SERVER | CVar.ARCHIVE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ghost Respawn
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static readonly CVarDef<float> GhostRespawnTime =
|
||||||
|
CVarDef.Create("ghost.respawn_time", 15f, CVar.SERVERONLY);
|
||||||
|
|
||||||
|
public static readonly CVarDef<int> GhostRespawnMaxPlayers =
|
||||||
|
CVarDef.Create("ghost.respawn_max_players", 40, CVar.SERVERONLY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user