From dbd5f284e23721d4bd5ea2fa3f4d3df14d61dd78 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Sat, 30 Mar 2024 02:12:01 +0300 Subject: [PATCH] Some Late Join Fixing (#1154) * SpawnPoint * JobSpawns --- .../GameTicking/GameTicker.Spawning.cs | 10 +++++++++- .../ContainerSpawnPointSystem.cs | 6 +++++- .../EntitySystems/SpawnPointSystem.cs | 20 ++++++++++++++++++- .../Station/Systems/StationSpawningSystem.cs | 14 ++++++++++--- Content.Shared/Roles/JobPrototype.cs | 6 ++++++ .../Roles/Jobs/Cargo/mail_carrier.yml | 1 + .../Nyanotrasen/Roles/Jobs/Civilian/valet.yml | 1 + .../Roles/Jobs/Wildcards/prisoner.yml | 1 + .../Roles/Jobs/Civilian/janitor.yml | 1 + .../Roles/Jobs/Command/head_of_personnel.yml | 1 + .../Roles/Jobs/Security/head_of_security.yml | 1 + .../Prototypes/_NF/Roles/Jobs/Command/stc.yml | 1 + .../Roles/Jobs/Security/security_guard.yml | 1 + 13 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs index 01630000a6c..4fb0a868d08 100644 --- a/Content.Server/GameTicking/GameTicker.Spawning.cs +++ b/Content.Server/GameTicking/GameTicker.Spawning.cs @@ -209,7 +209,15 @@ private void SpawnPlayer(ICommonSession player, HumanoidCharacterProfile charact _playTimeTrackings.PlayerRolesChanged(player); - var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character); + // Delta-V: Add AlwaysUseSpawner. + var spawnPointType = SpawnPointType.Unset; + if (jobPrototype.AlwaysUseSpawner) + { + lateJoin = false; + spawnPointType = SpawnPointType.Job; + } + + var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character, spawnPointType: spawnPointType); DebugTools.AssertNotNull(mobMaybe); var mob = mobMaybe!.Value; diff --git a/Content.Server/Spawners/EntitySystems/ContainerSpawnPointSystem.cs b/Content.Server/Spawners/EntitySystems/ContainerSpawnPointSystem.cs index e213f29d07b..463e9dad125 100644 --- a/Content.Server/Spawners/EntitySystems/ContainerSpawnPointSystem.cs +++ b/Content.Server/Spawners/EntitySystems/ContainerSpawnPointSystem.cs @@ -1,4 +1,4 @@ -using Content.Server.GameTicking; +using Content.Server.GameTicking; using Content.Server.Spawners.Components; using Content.Server.Station.Systems; using Robust.Server.Containers; @@ -20,6 +20,10 @@ public void HandlePlayerSpawning(PlayerSpawningEvent args) if (args.SpawnResult != null) return; + // DeltaV - Ignore these two desired spawn types + if (args.DesiredSpawnPointType is SpawnPointType.Observer or SpawnPointType.LateJoin) + return; + var query = EntityQueryEnumerator(); var possibleContainers = new List>(); diff --git a/Content.Server/Spawners/EntitySystems/SpawnPointSystem.cs b/Content.Server/Spawners/EntitySystems/SpawnPointSystem.cs index b98e04844b9..65877d4e5de 100644 --- a/Content.Server/Spawners/EntitySystems/SpawnPointSystem.cs +++ b/Content.Server/Spawners/EntitySystems/SpawnPointSystem.cs @@ -1,4 +1,4 @@ -using Content.Server.GameTicking; +using Content.Server.GameTicking; using Content.Server.Spawners.Components; using Content.Server.Station.Systems; using Robust.Shared.Map; @@ -32,6 +32,24 @@ private void OnPlayerSpawning(PlayerSpawningEvent args) if (args.Station != null && _stationSystem.GetOwningStation(uid, xform) != args.Station) continue; + // Delta-V: Allow setting a desired SpawnPointType + if (args.DesiredSpawnPointType != SpawnPointType.Unset) + { + var isMatchingJob = spawnPoint.SpawnType == SpawnPointType.Job && + (args.Job == null || spawnPoint.Job?.ID == args.Job.Prototype); + + switch (args.DesiredSpawnPointType) + { + case SpawnPointType.Job when isMatchingJob: + case SpawnPointType.LateJoin when spawnPoint.SpawnType == SpawnPointType.LateJoin: + case SpawnPointType.Observer when spawnPoint.SpawnType == SpawnPointType.Observer: + possiblePositions.Add(xform.Coordinates); + break; + default: + continue; + } + } + if (_gameTicker.RunLevel == GameRunLevel.InRound && spawnPoint.SpawnType == SpawnPointType.LateJoin) { possiblePositions.Add(xform.Coordinates); diff --git a/Content.Server/Station/Systems/StationSpawningSystem.cs b/Content.Server/Station/Systems/StationSpawningSystem.cs index d0ebae9a0e6..5970dbbb58d 100644 --- a/Content.Server/Station/Systems/StationSpawningSystem.cs +++ b/Content.Server/Station/Systems/StationSpawningSystem.cs @@ -26,6 +26,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Random; using Robust.Shared.Utility; +using Content.Server.Spawners.Components; // DeltaV namespace Content.Server.Station.Systems; @@ -72,17 +73,19 @@ public override void Initialize() /// The job to assign, if any. /// The character profile to use, if any. /// Resolve pattern, the station spawning component for the station. + /// Delta-V: Set desired spawn point type. /// The resulting player character, if any. /// Thrown when the given station is not a station. /// /// This only spawns the character, and does none of the mind-related setup you'd need for it to be playable. /// - public EntityUid? SpawnPlayerCharacterOnStation(EntityUid? station, JobComponent? job, HumanoidCharacterProfile? profile, StationSpawningComponent? stationSpawning = null) + public EntityUid? SpawnPlayerCharacterOnStation(EntityUid? station, JobComponent? job, HumanoidCharacterProfile? profile, StationSpawningComponent? stationSpawning = null, SpawnPointType spawnPointType = SpawnPointType.Unset) { if (station != null && !Resolve(station.Value, ref stationSpawning)) throw new ArgumentException("Tried to use a non-station entity as a station!", nameof(station)); - var ev = new PlayerSpawningEvent(job, profile, station); + // Delta-V: Set desired spawn point type. + var ev = new PlayerSpawningEvent(job, profile, station, spawnPointType); if (station != null && profile != null) { @@ -276,11 +279,16 @@ public sealed class PlayerSpawningEvent : EntityEventArgs /// The target station, if any. /// public readonly EntityUid? Station; + /// + /// Delta-V: Desired SpawnPointType, if any. + /// + public readonly SpawnPointType DesiredSpawnPointType; - public PlayerSpawningEvent(JobComponent? job, HumanoidCharacterProfile? humanoidCharacterProfile, EntityUid? station) + public PlayerSpawningEvent(JobComponent? job, HumanoidCharacterProfile? humanoidCharacterProfile, EntityUid? station, SpawnPointType spawnPointType = SpawnPointType.Unset) { Job = job; HumanoidCharacterProfile = humanoidCharacterProfile; Station = station; + DesiredSpawnPointType = spawnPointType; } } diff --git a/Content.Shared/Roles/JobPrototype.cs b/Content.Shared/Roles/JobPrototype.cs index eb2e8535fa5..c4d87d40f41 100644 --- a/Content.Shared/Roles/JobPrototype.cs +++ b/Content.Shared/Roles/JobPrototype.cs @@ -67,6 +67,12 @@ public sealed partial class JobPrototype : IPrototype [DataField("canBeAntag")] public bool CanBeAntag { get; private set; } = true; + /// + /// Nyano/DV: For e.g. prisoners, they'll never use their latejoin spawner. + /// + [DataField("alwaysUseSpawner")] + public bool AlwaysUseSpawner { get; } = false; + /// /// Whether this job is a head. /// The job system will try to pick heads before other jobs on the same priority level. diff --git a/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Cargo/mail_carrier.yml b/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Cargo/mail_carrier.yml index 3a1ed796c83..09d250d2512 100644 --- a/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Cargo/mail_carrier.yml +++ b/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Cargo/mail_carrier.yml @@ -3,6 +3,7 @@ name: job-name-mail-carrier description: job-name-mail-carrier startingGear: MailCarrierGear + alwaysUseSpawner: true playTimeTracker: JobMailCarrier requirements: - !type:OverallPlaytimeRequirement diff --git a/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Civilian/valet.yml b/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Civilian/valet.yml index 26f2135e61a..6e3a90eae68 100644 --- a/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Civilian/valet.yml +++ b/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Civilian/valet.yml @@ -7,6 +7,7 @@ - !type:OverallPlaytimeRequirement time: 10800 startingGear: ValetGear + alwaysUseSpawner: true icon: "JobIconServiceWorker" supervisors: job-supervisors-everyone access: diff --git a/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Wildcards/prisoner.yml b/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Wildcards/prisoner.yml index bf6bccd67ba..f809dcdf369 100644 --- a/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Wildcards/prisoner.yml +++ b/Resources/Prototypes/Nyanotrasen/Roles/Jobs/Wildcards/prisoner.yml @@ -6,6 +6,7 @@ requirements: - !type:WhitelistRequirement startingGear: PrisonerGear +# alwaysUseSpawner: true canBeAntag: false whitelistRequired: true icon: "JobIconPrisoner" diff --git a/Resources/Prototypes/Roles/Jobs/Civilian/janitor.yml b/Resources/Prototypes/Roles/Jobs/Civilian/janitor.yml index 837ab94ba40..49a948d23fd 100644 --- a/Resources/Prototypes/Roles/Jobs/Civilian/janitor.yml +++ b/Resources/Prototypes/Roles/Jobs/Civilian/janitor.yml @@ -7,6 +7,7 @@ - !type:OverallPlaytimeRequirement time: 10800 startingGear: JanitorGear + alwaysUseSpawner: true icon: "JobIconJanitor" supervisors: job-supervisors-hop access: diff --git a/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml b/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml index 435021a3398..82b86ae3c92 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml @@ -9,6 +9,7 @@ - !type:WhitelistRequirement weight: 20 startingGear: HoPGear + alwaysUseSpawner: true icon: "JobIconHeadOfPersonnel" requireAdminNotify: true supervisors: job-supervisors-centcom # Frontier diff --git a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml index 1d7935c811f..56ec18ce0c8 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml @@ -21,6 +21,7 @@ # time: 108000 # 30 hrs weight: 10 startingGear: HoSGear + alwaysUseSpawner: true icon: "JobIconHeadOfSecurity" requireAdminNotify: true supervisors: job-supervisors-hop # Frontier diff --git a/Resources/Prototypes/_NF/Roles/Jobs/Command/stc.yml b/Resources/Prototypes/_NF/Roles/Jobs/Command/stc.yml index f385ab13bf5..6d4cca52fcc 100644 --- a/Resources/Prototypes/_NF/Roles/Jobs/Command/stc.yml +++ b/Resources/Prototypes/_NF/Roles/Jobs/Command/stc.yml @@ -4,6 +4,7 @@ description: job-description-stc playTimeTracker: JobStc startingGear: StcGear + alwaysUseSpawner: true requirements: - !type:OverallPlaytimeRequirement time: 72000 # 20 hrs diff --git a/Resources/Prototypes/_NF/Roles/Jobs/Security/security_guard.yml b/Resources/Prototypes/_NF/Roles/Jobs/Security/security_guard.yml index 4c34a506c87..2db4ea183b2 100644 --- a/Resources/Prototypes/_NF/Roles/Jobs/Security/security_guard.yml +++ b/Resources/Prototypes/_NF/Roles/Jobs/Security/security_guard.yml @@ -7,6 +7,7 @@ - !type:OverallPlaytimeRequirement time: 36000 # Frontier - 10 hrs startingGear: SecurityGuardGear + alwaysUseSpawner: true icon: "JobIconSecurityGuard" supervisors: job-supervisors-hop # not hos canBeAntag: false