Фикс выдачи ролей антагов в прибытии

This commit is contained in:
Vigers Ray 2024-06-10 20:51:38 +03:00
parent 30de0468ff
commit 4a20ecfd08
5 changed files with 65 additions and 14 deletions

View file

@ -231,13 +231,15 @@ namespace Content.Server.GameTicking
var arrivals = true;
// Все появляются в прибытии в начале раунда. Зачем? А мне нравится эта бегающаа орящая толпа.
var spawnPointType = SpawnPointType.Arrivals;
if (jobPrototype.AlwaysUseSpawner)
{
lateJoin = false;
arrivals = false;
spawnPointType = SpawnPointType.Job;
}
var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character, arrivals: arrivals);
var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character, arrivals: arrivals, spawnPointType: spawnPointType);
DebugTools.AssertNotNull(mobMaybe);
var mob = mobMaybe!.Value;

View file

@ -4,7 +4,6 @@ using Content.Server.Administration;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Events;
using Content.Server.Parallax;
using Content.Server.Screens.Components;
using Content.Server.Shuttles.Components;
@ -19,9 +18,6 @@ using Content.Shared.DeviceNetwork;
using Content.Shared.Mobs.Components;
using Content.Shared.Movement.Components;
using Content.Shared.Parallax.Biomes;
using Content.Shared.Preferences;
using Content.Shared.Roles.Jobs;
using Content.Shared.Salvage;
using Content.Shared.Shuttles.Components;
using Content.Shared.Tiles;
using Robust.Server.GameObjects;
@ -304,16 +300,39 @@ public sealed class ArrivalsSystem : EntitySystem
}
}
public List<EntityCoordinates> GetArrivalsSpawnPoints()
{
TryGetArrivalsSource(out var arrivals);
var possiblePositions = new List<EntityCoordinates>();
if (TryComp(arrivals, out TransformComponent? arrivalsXform))
{
var mapId = arrivalsXform.MapID;
var points = EntityQueryEnumerator<SpawnPointComponent, TransformComponent>();
while (points.MoveNext(out var uid, out var spawnPoint, out var xform))
{
if (spawnPoint.SpawnType != SpawnPointType.LateJoin || xform.MapID != mapId)
continue;
possiblePositions.Add(xform.Coordinates);
}
}
return possiblePositions;
}
public void HandlePlayerSpawning(PlayerSpawningEvent ev)
{
if (ev.SpawnResult != null)
return;
// Only works on latejoin even if enabled.
if (!Enabled || !ev.Arrivals)
if (!Enabled || _ticker.RunLevel != GameRunLevel.InRound)
return;
if (!HasComp<StationArrivalsComponent>(ev.Station) && !ev.Arrivals)
if (!HasComp<StationArrivalsComponent>(ev.Station))
return;
TryGetArrivalsSource(out var arrivals);

View file

@ -27,4 +27,5 @@ public enum SpawnPointType
LateJoin,
Job,
Observer,
Arrivals
}

View file

@ -1,4 +1,5 @@
using Content.Server.GameTicking;
using Content.Server.Shuttles.Systems;
using Content.Server.Spawners.Components;
using Content.Server.Station.Systems;
using Robust.Shared.Map;
@ -12,6 +13,7 @@ public sealed class SpawnPointSystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly StationSpawningSystem _stationSpawning = default!;
[Dependency] private readonly ArrivalsSystem _arrivals = default!;
public override void Initialize()
{
@ -27,11 +29,29 @@ public sealed class SpawnPointSystem : EntitySystem
var points = EntityQueryEnumerator<SpawnPointComponent, TransformComponent>();
var possiblePositions = new List<EntityCoordinates>();
while ( points.MoveNext(out var uid, out var spawnPoint, out var xform))
while (points.MoveNext(out var uid, out var spawnPoint, out var xform))
{
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 == 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);
@ -45,6 +65,11 @@ public sealed class SpawnPointSystem : EntitySystem
}
}
if (args.DesiredSpawnPointType == SpawnPointType.Arrivals)
{
possiblePositions = _arrivals.GetArrivalsSpawnPoints();
}
if (possiblePositions.Count == 0)
{
// Ok we've still not returned, but we need to put them /somewhere/.

View file

@ -6,6 +6,7 @@ using Content.Server.IdentityManagement;
using Content.Server.Mind.Commands;
using Content.Server.PDA;
using Content.Server.Shuttles.Systems;
using Content.Server.Spawners.Components;
using Content.Server.Spawners.EntitySystems;
using Content.Server.Station.Components;
using Content.Shared.Access.Components;
@ -81,12 +82,12 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
/// <remarks>
/// This only spawns the character, and does none of the mind-related setup you'd need for it to be playable.
/// </remarks>
public EntityUid? SpawnPlayerCharacterOnStation(EntityUid? station, JobComponent? job, HumanoidCharacterProfile? profile, bool arrivals, StationSpawningComponent? stationSpawning = null)
public EntityUid? SpawnPlayerCharacterOnStation(EntityUid? station, JobComponent? job, HumanoidCharacterProfile? profile, bool arrivals, 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, arrivals);
var ev = new PlayerSpawningEvent(job, profile, station, spawnPointType);
if (station != null && profile != null)
{
@ -307,13 +308,16 @@ public sealed class PlayerSpawningEvent : EntityEventArgs
/// The target station, if any.
/// </summary>
public readonly EntityUid? Station;
public readonly bool Arrivals;
/// <summary>
/// Delta-V: Desired SpawnPointType, if any.
/// </summary>
public readonly SpawnPointType DesiredSpawnPointType;
public PlayerSpawningEvent(JobComponent? job, HumanoidCharacterProfile? humanoidCharacterProfile, EntityUid? station, bool arrivals)
public PlayerSpawningEvent(JobComponent? job, HumanoidCharacterProfile? humanoidCharacterProfile, EntityUid? station, SpawnPointType spawnPointType = SpawnPointType.Unset)
{
Job = job;
HumanoidCharacterProfile = humanoidCharacterProfile;
Station = station;
Arrivals = arrivals;
DesiredSpawnPointType = spawnPointType;
}
}