CatStation/Content.Server/Cloning/RandomCloneSpawnerSystem.cs
Princess Cheeseballs c5f5a43dd7
Generic Target System (#43554)
* number 15

* evil

* borgar

* Generic Target System

* jafhfjasj

* borger

* whoops

* rename

* a

* whoop

* whoop

* thars your problem!

* asssssssssssssssssssssssssss

* fasfasfsa

* random

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-07-11 04:11:24 +00:00

44 lines
1.4 KiB
C#

using Content.Server.Cloning.Components;
using Content.Shared.Objectives.Systems;
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 IRobustRandom _random = default!;
[Dependency] private SharedTransformSystem _transformSystem = default!;
[Dependency] private AliveHumanoidTargetSystem _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 (!ProtoMan.TryIndex(ent.Comp.Settings, out var settings))
{
Log.Error($"Used invalid cloning settings {ent.Comp.Settings} for RandomCloneSpawner");
return;
}
var allHumans = _target.GetMinds();
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 _);
}
}