| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using Content.Shared.Roles;
- using Robust.Shared.Network;
- using Robust.Shared.Prototypes;
- using Robust.Shared.Replays;
- using Robust.Shared.Serialization;
- using Robust.Shared.Serialization.Markdown.Mapping;
- using Robust.Shared.Serialization.Markdown.Value;
- using Robust.Shared.Timing;
- using Robust.Shared.Audio;
- using Robust.Shared.Player;
- using Content.Shared.NPC.Prototypes;
- namespace Content.Shared.GameTicking
- {
- public abstract class SharedGameTicker : EntitySystem
- {
- [Dependency] private readonly IReplayRecordingManager _replay = default!;
- [Dependency] private readonly IGameTiming _gameTiming = default!;
- [Dependency] private readonly ISharedPlayerManager _playerManager = default!;
- // See ideally these would be pulled from the job definition or something.
- // But this is easier, and at least it isn't hardcoded.
- //TODO: Move these, they really belong in StationJobsSystem or a cvar.
- [ValidatePrototypeId<JobPrototype>]
- public const string FallbackOverflowJob = "Nomad";
- public const string FallbackOverflowJobName = "job-name-nomad";
- // TODO network.
- // Probably most useful for replays, round end info, and probably things like lobby menus.
- [ViewVariables]
- public int RoundId { get; protected set; }
- [ViewVariables] public TimeSpan RoundStartTimeSpan { get; protected set; }
- public override void Initialize()
- {
- base.Initialize();
- _replay.RecordingStarted += OnRecordingStart;
- }
- public override void Shutdown()
- {
- _replay.RecordingStarted -= OnRecordingStart;
- }
- private void OnRecordingStart(MappingDataNode metadata, List<object> events)
- {
- if (RoundId != 0)
- {
- metadata["roundId"] = new ValueDataNode(RoundId.ToString());
- }
- }
- public TimeSpan RoundDuration()
- {
- return _gameTiming.CurTime.Subtract(RoundStartTimeSpan);
- }
- }
- [Serializable, NetSerializable]
- public sealed class TickerJoinLobbyEvent : EntityEventArgs
- {
- }
- [Serializable, NetSerializable]
- public sealed class TickerJoinGameEvent : EntityEventArgs
- {
- }
- [Serializable, NetSerializable]
- public sealed class TickerLateJoinStatusEvent : EntityEventArgs
- {
- // TODO: Make this a replicated CVar, honestly.
- public bool Disallowed { get; }
- public TickerLateJoinStatusEvent(bool disallowed)
- {
- Disallowed = disallowed;
- }
- }
- [Serializable, NetSerializable]
- public sealed class TickerConnectionStatusEvent : EntityEventArgs
- {
- public TimeSpan RoundStartTimeSpan { get; }
- public TickerConnectionStatusEvent(TimeSpan roundStartTimeSpan)
- {
- RoundStartTimeSpan = roundStartTimeSpan;
- }
- }
- [Serializable, NetSerializable]
- public sealed class TickerLobbyStatusEvent : EntityEventArgs
- {
- public bool IsRoundStarted { get; }
- public string? LobbyBackground { get; }
- public bool YouAreReady { get; }
- // UTC.
- public TimeSpan StartTime { get; }
- public TimeSpan RoundStartTimeSpan { get; }
- public bool Paused { get; }
- public TickerLobbyStatusEvent(bool isRoundStarted, string? lobbyBackground, bool youAreReady, TimeSpan startTime, TimeSpan preloadTime, TimeSpan roundStartTimeSpan, bool paused)
- {
- IsRoundStarted = isRoundStarted;
- LobbyBackground = lobbyBackground;
- YouAreReady = youAreReady;
- StartTime = startTime;
- RoundStartTimeSpan = roundStartTimeSpan;
- Paused = paused;
- }
- }
- [Serializable, NetSerializable]
- public sealed class TickerLobbyInfoEvent : EntityEventArgs
- {
- public string TextBlob { get; }
- public TickerLobbyInfoEvent(string textBlob)
- {
- TextBlob = textBlob;
- }
- }
- [Serializable, NetSerializable]
- public sealed class GetPlayerFactionCounts : EntityEventArgs
- {
- public Dictionary<ProtoId<NpcFactionPrototype>, int> FactionCounts { get; } = new();
- public GetPlayerFactionCounts(Dictionary<ProtoId<NpcFactionPrototype>, int> factionCounts)
- {
- FactionCounts = factionCounts;
- }
- }
- [Serializable, NetSerializable]
- public sealed class TickerLobbyCountdownEvent : EntityEventArgs
- {
- /// <summary>
- /// The game time that the game will start at.
- /// </summary>
- public TimeSpan StartTime { get; }
- /// <summary>
- /// Whether or not the countdown is paused
- /// </summary>
- public bool Paused { get; }
- public TickerLobbyCountdownEvent(TimeSpan startTime, bool paused)
- {
- StartTime = startTime;
- Paused = paused;
- }
- }
- [Serializable, NetSerializable]
- public sealed class TickerJobsAvailableEvent(
- Dictionary<NetEntity, string> stationNames,
- Dictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> jobsAvailableByStation)
- : EntityEventArgs
- {
- /// <summary>
- /// The Status of the Player in the lobby (ready, observer, ...)
- /// </summary>
- public Dictionary<NetEntity, Dictionary<ProtoId<JobPrototype>, int?>> JobsAvailableByStation { get; } = jobsAvailableByStation;
- public Dictionary<NetEntity, string> StationNames { get; } = stationNames;
- }
- [Serializable, NetSerializable, DataDefinition]
- public sealed partial class RoundEndMessageEvent : EntityEventArgs
- {
- [Serializable, NetSerializable, DataDefinition]
- public partial struct RoundEndPlayerInfo
- {
- [DataField]
- public string PlayerOOCName;
- [DataField]
- public string? PlayerICName;
- [DataField, NonSerialized]
- public NetUserId? PlayerGuid;
- public string Role;
- [DataField, NonSerialized]
- public string[] JobPrototypes;
- [DataField, NonSerialized]
- public string[] AntagPrototypes;
- public NetEntity? PlayerNetEntity;
- [DataField]
- public bool Antag;
- [DataField]
- public bool Observer;
- public bool Connected;
- }
- public string GamemodeTitle { get; }
- public string RoundEndText { get; }
- public TimeSpan RoundDuration { get; }
- public int RoundId { get; }
- public int PlayerCount { get; }
- public RoundEndPlayerInfo[] AllPlayersEndInfo { get; }
- /// <summary>
- /// Sound gets networked due to how entity lifecycle works between client / server and to avoid clipping.
- /// </summary>
- public ResolvedSoundSpecifier? RestartSound;
- public RoundEndMessageEvent(
- string gamemodeTitle,
- string roundEndText,
- TimeSpan roundDuration,
- int roundId,
- int playerCount,
- RoundEndPlayerInfo[] allPlayersEndInfo,
- ResolvedSoundSpecifier? restartSound)
- {
- GamemodeTitle = gamemodeTitle;
- RoundEndText = roundEndText;
- RoundDuration = roundDuration;
- RoundId = roundId;
- PlayerCount = playerCount;
- AllPlayersEndInfo = allPlayersEndInfo;
- RestartSound = restartSound;
- }
- }
- [Serializable, NetSerializable]
- public enum PlayerGameStatus : sbyte
- {
- NotReadyToPlay = 0,
- ReadyToPlay,
- JoinedGame,
- }
- }
|