diff --git a/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs b/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs index 7c8ea4f4e4..e502a08f1a 100644 --- a/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs +++ b/Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs @@ -1,5 +1,8 @@ using Content.Shared.GameObjects.Components.Markers; +using Content.Shared.Jobs; using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.ViewVariables; @@ -9,15 +12,24 @@ namespace Content.Server.GameObjects.Components.Markers [ComponentReference(typeof(SharedSpawnPointComponent))] public sealed class SpawnPointComponent : SharedSpawnPointComponent { +#pragma warning disable 649 + [Dependency] private IPrototypeManager _prototypeManager; +#pragma warning restore 649 + + [ViewVariables(VVAccess.ReadWrite)] private SpawnPointType _spawnType; - [ViewVariables] + [ViewVariables(VVAccess.ReadWrite)] + private string _jobId; public SpawnPointType SpawnType => _spawnType; + public JobPrototype Job => string.IsNullOrEmpty(_jobId) ? null + : _prototypeManager.Index(_jobId); public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); serializer.DataField(ref _spawnType, "spawn_type", SpawnPointType.Unset); + serializer.DataField(ref _jobId, "job_id", null); } } @@ -25,5 +37,6 @@ namespace Content.Server.GameObjects.Components.Markers { Unset = 0, LateJoin, + Job, } } diff --git a/Content.Server/GameTicking/GameTicker.cs b/Content.Server/GameTicking/GameTicker.cs index d2ea91741c..7da39da0ba 100644 --- a/Content.Server/GameTicking/GameTicker.cs +++ b/Content.Server/GameTicking/GameTicker.cs @@ -180,7 +180,7 @@ namespace Content.Server.GameTicking // Spawn everybody in! foreach (var (player, job) in assignedJobs) { - SpawnPlayer(player, job); + SpawnPlayer(player, job, false); } _sendStatusToAll(); @@ -258,9 +258,9 @@ namespace Content.Server.GameTicking UpdateInfoText(); } - private IEntity _spawnPlayerMob(Job job) + private IEntity _spawnPlayerMob(Job job, bool lateJoin = true) { - var entity = _entityManager.SpawnEntityAt(PlayerPrototypeName, _getLateJoinSpawnPoint()); + var entity = _entityManager.SpawnEntityAt(PlayerPrototypeName, lateJoin ? _getLateJoinSpawnPoint() : _getJobSpawnPoint(job.Prototype.ID)); if (entity.TryGetComponent(out InventoryComponent inventory)) { var gear = _prototypeManager.Index(job.StartingGear).Equipment; @@ -271,7 +271,6 @@ namespace Content.Server.GameTicking inventory.Equip(slot, equipmentEntity.GetComponent()); } } - return entity; } @@ -304,6 +303,22 @@ namespace Content.Server.GameTicking return location; } + private GridCoordinates _getJobSpawnPoint(string jobId) + { + var location = _spawnPoint; + + var possiblePoints = new List(); + foreach (var entity in _entityManager.GetEntities(new TypeEntityQuery(typeof(SpawnPointComponent)))) + { + var point = entity.GetComponent(); + if (point.SpawnType == SpawnPointType.Job && point.Job.ID == jobId) possiblePoints.Add(entity.Transform.GridPosition); + } + + if (possiblePoints.Count != 0) location = _robustRandom.Pick(possiblePoints); + + return location; + } + /// /// Cleanup that has to run to clear up anything from the previous round. /// Stuff like wiping the previous map clean. @@ -416,7 +431,7 @@ namespace Content.Server.GameTicking } } - private void SpawnPlayer(IPlayerSession session, string jobId = null) + private void SpawnPlayer(IPlayerSession session, string jobId = null, bool lateJoin = true) { var character = (HumanoidCharacterProfile) _prefsManager .GetPreferences(session.SessionId.Username) @@ -438,7 +453,7 @@ namespace Content.Server.GameTicking var job = new Job(data.Mind, jobPrototype); data.Mind.AddRole(job); - var mob = _spawnPlayerMob(job); + var mob = _spawnPlayerMob(job, lateJoin); data.Mind.TransferTo(mob); ApplyCharacterProfile(mob, character); diff --git a/Content.Server/Mobs/Roles/Job.cs b/Content.Server/Mobs/Roles/Job.cs index cabfeeecfc..53c7ca721c 100644 --- a/Content.Server/Mobs/Roles/Job.cs +++ b/Content.Server/Mobs/Roles/Job.cs @@ -8,15 +8,15 @@ namespace Content.Server.Mobs.Roles { public class Job : Role { - private readonly JobPrototype _jobPrototype; + public JobPrototype Prototype { get; } public override string Name { get; } - public String StartingGear => _jobPrototype.StartingGear; + public String StartingGear => Prototype.StartingGear; public Job(Mind mind, JobPrototype jobPrototype) : base(mind) { - _jobPrototype = jobPrototype; + Prototype = jobPrototype; Name = jobPrototype.Name; }