Move minds, roles, jobs and objectives to shared (#19679)

This commit is contained in:
DrSmugleaf
2023-08-30 21:46:11 -07:00
committed by GitHub
parent b702963d5e
commit 3f3ba6ac62
139 changed files with 1209 additions and 1041 deletions

View File

@@ -2,11 +2,12 @@ using System.Linq;
using Content.Server.Afk;
using Content.Server.Afk.Events;
using Content.Server.GameTicking;
using Content.Server.Roles;
using Content.Server.Mind;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Players;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Roles;
using Robust.Server.GameObjects;
@@ -27,6 +28,7 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly PlayTimeTrackingManager _tracking = default!;
public override void Initialize()
@@ -103,18 +105,14 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
private void OnRoleRemove(RoleRemovedEvent ev)
{
if (ev.Mind.Session == null)
return;
_tracking.QueueRefreshTrackers(ev.Mind.Session);
if (_minds.TryGetSession(ev.Mind, out var session))
_tracking.QueueRefreshTrackers(session);
}
private void OnRoleAdd(RoleAddedEvent ev)
{
if (ev.Mind.Session == null)
return;
_tracking.QueueRefreshTrackers(ev.Mind.Session);
if (_minds.TryGetSession(ev.Mind, out var session))
_tracking.QueueRefreshTrackers(session);
}
private void OnRoundEnd(RoundRestartCleanupEvent ev)

View File

@@ -1,59 +1,11 @@
using Content.Server.GameTicking;
using Content.Server.Mind;
using Content.Shared.Players;
using Robust.Server.Player;
using Robust.Shared.Network;
using Robust.Shared.Players;
namespace Content.Server.Players
{
/// <summary>
/// Content side for all data that tracks a player session.
/// Use <see cref="PlayerDataExt.ContentData(IPlayerData)"/> to retrieve this from an <see cref="IPlayerData"/>.
/// </summary>
public sealed class PlayerData
{
/// <summary>
/// The session ID of the player owning this data.
/// </summary>
[ViewVariables]
public NetUserId UserId { get; }
/// <summary>
/// This is a backup copy of the player name stored on connection.
/// This is useful in the event the player disconnects.
/// </summary>
[ViewVariables]
public string Name { get; }
/// <summary>
/// The currently occupied mind of the player owning this data.
/// DO NOT DIRECTLY SET THIS UNLESS YOU KNOW WHAT YOU'RE DOING.
/// </summary>
[ViewVariables, Access(typeof(MindSystem), typeof(GameTicker))]
public EntityUid? Mind { get; set; }
/// <summary>
/// If true, the player is an admin and they explicitly de-adminned mid-game,
/// so they should not regain admin if they reconnect.
/// </summary>
public bool ExplicitlyDeadminned { get; set; }
public PlayerData(NetUserId userId, string name)
{
UserId = userId;
Name = name;
}
}
public static class PlayerDataExt
{
/// <summary>
/// Gets the correctly cast instance of content player data from an engine player data storage.
/// </summary>
public static PlayerData? ContentData(this IPlayerData data)
{
return (PlayerData?) data.ContentDataUncast;
}
/// <summary>
/// Gets the correctly cast instance of content player data from an engine player data storage.
/// </summary>
@@ -62,6 +14,11 @@ namespace Content.Server.Players
return session.Data.ContentData();
}
public static PlayerData? ContentData(this ICommonSession session)
{
return ((IPlayerSession) session).ContentData();
}
/// <summary>
/// Gets the mind that is associated with this player.
/// </summary>

View File

@@ -0,0 +1,12 @@
using Content.Shared.Players;
using Robust.Shared.Players;
namespace Content.Server.Players;
public sealed class PlayerSystem : SharedPlayerSystem
{
public override PlayerData? ContentData(ICommonSession? session)
{
return session?.ContentData();
}
}