Files
crystall-punk-14/Content.Shared/GameTicking/SharedGameTicker.cs

225 lines
6.9 KiB
C#
Raw Permalink Normal View History

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;
namespace Content.Shared.GameTicking
{
public abstract class SharedGameTicker : EntitySystem
{
[Dependency] private readonly IReplayRecordingManager _replay = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
// See ideally these would be pulled from the job definition or something.
// But this is easier, and at least it isn't hardcoded.
StationSystem/jobs/partial spawning refactor (#7580) * Partial work on StationSystem refactor. * WIP station jobs API. * forgor to fire off grid events. * Partial implementation of StationSpawningSystem * whoops infinite loop. * Spawners should work now. * it compiles. * tfw * Vestigial code cleanup. * fix station deletion. * attempt to make tests go brr * add latejoin spawnpoints to test maps. * make sure the station still exists while destructing spawners. * forgot an exists check. * destruction order check. * hopefully fix final test. * fail-safe radstorm. * Deep-clean job code further. This is bugged!!!!! * Fix job bug. (init order moment) * whooo cleanup * New job selection algorithm that tries to distribute fairly across stations. * small nitpicks * Give the heads their weights to replace the head field. * make overflow assign take a station list. * moment * Fixes and test #1 of many. * please fix nullspace * AssignJobs should no longer even consider showing up on a trace. * add comment. * Introduce station configs, praying i didn't miss something. * in one small change stations are now fully serializable. * Further doc comments. * whoops. * Solve bug where assignjobs didn't account for roundstart. * Fix spawning, improve the API. Caught an oversight in stationsystem that should've broke everything but didn't, whoops. * Goodbye JobController. * minor fix.. * fix test fail, remove debug logs. * quick serialization fixes. * fixes.. * sus * partialing * Update Content.Server/Station/Systems/StationJobsSystem.Roundstart.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Use dirtying to avoid rebuilding the list 2,100 times. * add a bajillion more lines of docs (mostly in AssignJobs so i don't ever forget how it works) * Update Content.IntegrationTests/Tests/Station/StationJobsTest.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Add the Mysteriously Missing Captain Check. * Put maprender back the way it belongs. * I love addressing reviews. * Update Content.Server/Station/Systems/StationJobsSystem.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * doc cleanup. * Fix bureaucratic error, add job slot tests. * zero cost abstractions when * cri * saner error. * Fix spawning failing certain tests due to gameticker not handling falliability correctly. Can't fix this until I refactor the rest of spawning code. * submodule gaming * Packedenger. * Documentation consistency. Co-authored-by: Kara <lunarautomaton6@gmail.com>
2022-05-10 13:43:30 -05:00
//TODO: Move these, they really belong in StationJobsSystem or a cvar.
[ValidatePrototypeId<JobPrototype>]
2024-06-02 14:07:00 +03:00
public const string FallbackOverflowJob = "CP14Adventurer";
2024-06-02 12:22:22 +03:00
public const string FallbackOverflowJobName = "cp14-job-name-adventurer";
// TODO network.
// Probably most useful for replays, round end info, and probably things like lobby menus.
[ViewVariables]
public int RoundId { get; protected set; }
2023-12-26 16:24:53 -06:00
[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)
{
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; }
2022-03-13 19:33:19 -07:00
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;
2022-03-13 19:33:19 -07:00
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;
}
}
2019-10-18 14:28:39 +02:00
[Serializable, NetSerializable]
public sealed class TickerLobbyCountdownEvent : EntityEventArgs
{
/// <summary>
/// The game time that the game will start at.
/// </summary>
public TimeSpan StartTime { get; }
2019-10-18 14:28:39 +02:00
/// <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 string? RestartSound;
2022-05-13 10:13:07 +10:00
public RoundEndMessageEvent(
string gamemodeTitle,
string roundEndText,
TimeSpan roundDuration,
int roundId,
int playerCount,
RoundEndPlayerInfo[] allPlayersEndInfo,
string? restartSound)
{
GamemodeTitle = gamemodeTitle;
RoundEndText = roundEndText;
RoundDuration = roundDuration;
RoundId = roundId;
PlayerCount = playerCount;
AllPlayersEndInfo = allPlayersEndInfo;
RestartSound = restartSound;
}
}
[Serializable, NetSerializable]
2022-08-14 12:54:49 -07:00
public enum PlayerGameStatus : sbyte
{
2022-08-14 12:54:49 -07:00
NotReadyToPlay = 0,
ReadyToPlay,
JoinedGame,
}
}