mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 02:41:18 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
96 lines
3.7 KiB
C#
96 lines
3.7 KiB
C#
using Content.Shared.GameTicking;
|
|
using Content.Shared.Preferences;
|
|
using Content.Shared.Spawners.Components;
|
|
using Content.Shared.Station.Systems;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Shared.Spawners.EntitySystems;
|
|
|
|
public sealed partial class ContainerSpawnPointSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedContainerSystem _container = default!;
|
|
[Dependency] private GameTicker _gameTicker = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private StationSystem _station = default!;
|
|
[Dependency] private StationSpawningSystem _stationSpawning = default!;
|
|
|
|
[SubscribeLocalEvent(before: new []{typeof(SpawnPointSystem)})]
|
|
public void HandlePlayerSpawning(PlayerSpawningEvent args)
|
|
{
|
|
if (args.SpawnResult != null)
|
|
return;
|
|
|
|
// If it's just a spawn pref check if it's for cryo (silly).
|
|
if (args.HumanoidCharacterProfile?.SpawnPriority != SpawnPriorityPreference.Cryosleep &&
|
|
(!ProtoMan.Resolve(args.Job, out var jobProto) || jobProto.JobEntity == null))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var query = EntityQueryEnumerator<ContainerSpawnPointComponent, ContainerManagerComponent, TransformComponent>();
|
|
var possibleContainers = new List<Entity<ContainerSpawnPointComponent, ContainerManagerComponent, TransformComponent>>();
|
|
|
|
while (query.MoveNext(out var uid, out var spawnPoint, out var container, out var xform))
|
|
{
|
|
if (args.Station != null && _station.GetOwningStation(uid, xform) != args.Station)
|
|
continue;
|
|
|
|
// If it's unset, then we allow it to be used for both roundstart and midround joins
|
|
if (spawnPoint.SpawnType == SpawnPointType.Unset)
|
|
{
|
|
// make sure we also check the job here for various reasons.
|
|
if (spawnPoint.Job == null || spawnPoint.Job == args.Job)
|
|
possibleContainers.Add((uid, spawnPoint, container, xform));
|
|
continue;
|
|
}
|
|
|
|
if (_gameTicker.RunLevel == GameRunLevel.InRound && spawnPoint.SpawnType == SpawnPointType.LateJoin)
|
|
{
|
|
possibleContainers.Add((uid, spawnPoint, container, xform));
|
|
}
|
|
|
|
if (_gameTicker.RunLevel != GameRunLevel.InRound &&
|
|
spawnPoint.SpawnType == SpawnPointType.Job &&
|
|
(args.Job == null || spawnPoint.Job == args.Job))
|
|
{
|
|
possibleContainers.Add((uid, spawnPoint, container, xform));
|
|
}
|
|
}
|
|
|
|
if (possibleContainers.Count == 0)
|
|
return;
|
|
// we just need some default coords so we can spawn the player entity.
|
|
var baseCoords = possibleContainers[0].Comp3.Coordinates;
|
|
|
|
args.SpawnResult = _stationSpawning.SpawnPlayerMob(
|
|
baseCoords,
|
|
args.Job,
|
|
args.HumanoidCharacterProfile,
|
|
args.Station);
|
|
|
|
_random.Shuffle(possibleContainers);
|
|
foreach (var (uid, spawnPoint, manager, xform) in possibleContainers)
|
|
{
|
|
if (!_container.TryGetContainer(uid, spawnPoint.ContainerId, out var container, manager))
|
|
continue;
|
|
|
|
if (!_container.Insert(args.SpawnResult.Value, container, containerXform: xform))
|
|
continue;
|
|
|
|
var ev = new ContainerSpawnEvent(args.SpawnResult.Value);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
return;
|
|
}
|
|
|
|
Del(args.SpawnResult);
|
|
args.SpawnResult = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Raised on a container when a player is spawned into it.
|
|
/// </summary>
|
|
[ByRefEvent]
|
|
public record struct ContainerSpawnEvent(EntityUid Player);
|