Makes players spawn on job spawn markers on roundstart (#543)
* Adds job type to spawn points, makes players spawn on job spawn markers on roundstart * Update Content.Server/GameObjects/Components/Markers/SpawnPointComponent.cs Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
committed by
Pieter-Jan Briers
parent
1996893a26
commit
09a27df6db
@@ -1,5 +1,8 @@
|
|||||||
using Content.Shared.GameObjects.Components.Markers;
|
using Content.Shared.GameObjects.Components.Markers;
|
||||||
|
using Content.Shared.Jobs;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
@@ -9,15 +12,24 @@ namespace Content.Server.GameObjects.Components.Markers
|
|||||||
[ComponentReference(typeof(SharedSpawnPointComponent))]
|
[ComponentReference(typeof(SharedSpawnPointComponent))]
|
||||||
public sealed class SpawnPointComponent : SharedSpawnPointComponent
|
public sealed class SpawnPointComponent : SharedSpawnPointComponent
|
||||||
{
|
{
|
||||||
|
#pragma warning disable 649
|
||||||
|
[Dependency] private IPrototypeManager _prototypeManager;
|
||||||
|
#pragma warning restore 649
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
private SpawnPointType _spawnType;
|
private SpawnPointType _spawnType;
|
||||||
[ViewVariables]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
private string _jobId;
|
||||||
public SpawnPointType SpawnType => _spawnType;
|
public SpawnPointType SpawnType => _spawnType;
|
||||||
|
public JobPrototype Job => string.IsNullOrEmpty(_jobId) ? null
|
||||||
|
: _prototypeManager.Index<JobPrototype>(_jobId);
|
||||||
|
|
||||||
public override void ExposeData(ObjectSerializer serializer)
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
base.ExposeData(serializer);
|
base.ExposeData(serializer);
|
||||||
|
|
||||||
serializer.DataField(ref _spawnType, "spawn_type", SpawnPointType.Unset);
|
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,
|
Unset = 0,
|
||||||
LateJoin,
|
LateJoin,
|
||||||
|
Job,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ namespace Content.Server.GameTicking
|
|||||||
// Spawn everybody in!
|
// Spawn everybody in!
|
||||||
foreach (var (player, job) in assignedJobs)
|
foreach (var (player, job) in assignedJobs)
|
||||||
{
|
{
|
||||||
SpawnPlayer(player, job);
|
SpawnPlayer(player, job, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendStatusToAll();
|
_sendStatusToAll();
|
||||||
@@ -258,9 +258,9 @@ namespace Content.Server.GameTicking
|
|||||||
UpdateInfoText();
|
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))
|
if (entity.TryGetComponent(out InventoryComponent inventory))
|
||||||
{
|
{
|
||||||
var gear = _prototypeManager.Index<StartingGearPrototype>(job.StartingGear).Equipment;
|
var gear = _prototypeManager.Index<StartingGearPrototype>(job.StartingGear).Equipment;
|
||||||
@@ -271,7 +271,6 @@ namespace Content.Server.GameTicking
|
|||||||
inventory.Equip(slot, equipmentEntity.GetComponent<ItemComponent>());
|
inventory.Equip(slot, equipmentEntity.GetComponent<ItemComponent>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,6 +303,22 @@ namespace Content.Server.GameTicking
|
|||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GridCoordinates _getJobSpawnPoint(string jobId)
|
||||||
|
{
|
||||||
|
var location = _spawnPoint;
|
||||||
|
|
||||||
|
var possiblePoints = new List<GridCoordinates>();
|
||||||
|
foreach (var entity in _entityManager.GetEntities(new TypeEntityQuery(typeof(SpawnPointComponent))))
|
||||||
|
{
|
||||||
|
var point = entity.GetComponent<SpawnPointComponent>();
|
||||||
|
if (point.SpawnType == SpawnPointType.Job && point.Job.ID == jobId) possiblePoints.Add(entity.Transform.GridPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (possiblePoints.Count != 0) location = _robustRandom.Pick(possiblePoints);
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cleanup that has to run to clear up anything from the previous round.
|
/// Cleanup that has to run to clear up anything from the previous round.
|
||||||
/// Stuff like wiping the previous map clean.
|
/// 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
|
var character = (HumanoidCharacterProfile) _prefsManager
|
||||||
.GetPreferences(session.SessionId.Username)
|
.GetPreferences(session.SessionId.Username)
|
||||||
@@ -438,7 +453,7 @@ namespace Content.Server.GameTicking
|
|||||||
var job = new Job(data.Mind, jobPrototype);
|
var job = new Job(data.Mind, jobPrototype);
|
||||||
data.Mind.AddRole(job);
|
data.Mind.AddRole(job);
|
||||||
|
|
||||||
var mob = _spawnPlayerMob(job);
|
var mob = _spawnPlayerMob(job, lateJoin);
|
||||||
data.Mind.TransferTo(mob);
|
data.Mind.TransferTo(mob);
|
||||||
ApplyCharacterProfile(mob, character);
|
ApplyCharacterProfile(mob, character);
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ namespace Content.Server.Mobs.Roles
|
|||||||
{
|
{
|
||||||
public class Job : Role
|
public class Job : Role
|
||||||
{
|
{
|
||||||
private readonly JobPrototype _jobPrototype;
|
public JobPrototype Prototype { get; }
|
||||||
|
|
||||||
public override string Name { get; }
|
public override string Name { get; }
|
||||||
|
|
||||||
public String StartingGear => _jobPrototype.StartingGear;
|
public String StartingGear => Prototype.StartingGear;
|
||||||
|
|
||||||
public Job(Mind mind, JobPrototype jobPrototype) : base(mind)
|
public Job(Mind mind, JobPrototype jobPrototype) : base(mind)
|
||||||
{
|
{
|
||||||
_jobPrototype = jobPrototype;
|
Prototype = jobPrototype;
|
||||||
Name = jobPrototype.Name;
|
Name = jobPrototype.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user