mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 02:41:18 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using Content.Server.Cloning.Components;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Mobs.Systems;
|
|
using Content.Shared.Objectives.Systems;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Cloning;
|
|
|
|
/// <summary>
|
|
/// This deals with spawning and setting up a clone of a random crew member.
|
|
/// </summary>
|
|
public sealed partial class RandomCloneSpawnerSystem : EntitySystem
|
|
{
|
|
[Dependency] private CloningSystem _cloning = default!;
|
|
[Dependency] private IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private SharedTransformSystem _transformSystem = default!;
|
|
[Dependency] private TargetSystem _target = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<RandomCloneSpawnerComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(Entity<RandomCloneSpawnerComponent> ent, ref MapInitEvent args)
|
|
{
|
|
QueueDel(ent.Owner);
|
|
|
|
if (!_prototypeManager.TryIndex(ent.Comp.Settings, out var settings))
|
|
{
|
|
Log.Error($"Used invalid cloning settings {ent.Comp.Settings} for RandomCloneSpawner");
|
|
return;
|
|
}
|
|
|
|
var allHumans = _target.GetAliveHumans();
|
|
|
|
if (allHumans.Count == 0)
|
|
return;
|
|
|
|
var bodyToClone = _random.Pick(allHumans).Comp.OwnedEntity;
|
|
|
|
if (bodyToClone != null)
|
|
_cloning.TryCloning(bodyToClone.Value, _transformSystem.GetMapCoordinates(ent.Owner), settings, out _);
|
|
}
|
|
}
|