Cloning Refactor and bugfixes (#35555)

* cloning refactor

* cleanup and fixes

* don't pick from 0

* give dwarves the correct species

* fix dna and bloodstream reagent data cloning

* don't copy helmets

* be less redundant
This commit is contained in:
slarticodefast
2025-03-02 16:50:12 +01:00
committed by GitHub
parent 02d3595faa
commit ceff2bea00
25 changed files with 796 additions and 420 deletions

View File

@@ -0,0 +1,13 @@
namespace Content.Shared.Cloning.Events;
/// <summary>
/// Raised before a mob is cloned. Cancel to prevent cloning.
/// </summary>
[ByRefEvent]
public record struct CloningAttemptEvent(CloningSettingsPrototype Settings, bool Cancelled = false);
/// <summary>
/// Raised after a new mob got spawned when cloning a humanoid.
/// </summary>
[ByRefEvent]
public record struct CloningEvent(CloningSettingsPrototype Settings, EntityUid CloneUid);

View File

@@ -10,8 +10,8 @@ namespace Content.Shared.Cloning;
[RegisterComponent]
public sealed partial class CloningPodComponent : Component
{
[ValidatePrototypeId<SinkPortPrototype>]
public const string PodPort = "CloningPodReceiver";
[DataField]
public ProtoId<SinkPortPrototype> PodPort = "CloningPodReceiver";
[ViewVariables]
public ContainerSlot BodyContainer = default!;
@@ -31,23 +31,25 @@ public sealed partial class CloningPodComponent : Component
/// <summary>
/// The material that is used to clone entities.
/// </summary>
[DataField("requiredMaterial"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public ProtoId<MaterialPrototype> RequiredMaterial = "Biomass";
/// <summary>
/// The current amount of time it takes to clone a body
/// The current amount of time it takes to clone a body.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float CloningTime = 30f;
/// <summary>
/// The mob to spawn on emag
/// The mob to spawn on emag.
/// </summary>
[DataField("mobSpawnId"), ViewVariables(VVAccess.ReadWrite)]
[DataField]
public EntProtoId MobSpawnId = "MobAbomination";
// TODO: Remove this from here when cloning and/or zombies are refactored
[DataField("screamSound")]
/// <summary>
/// The sound played when a mob is spawned from an emagged cloning pod.
/// </summary>
[DataField]
public SoundSpecifier ScreamSound = new SoundCollectionSpecifier("ZombieScreams")
{
Params = AudioParams.Default.WithVolume(4),
@@ -74,21 +76,3 @@ public enum CloningPodStatus : byte
Gore,
NoMind
}
/// <summary>
/// Raised after a new mob got spawned when cloning a humanoid
/// </summary>
[ByRefEvent]
public struct CloningEvent
{
public bool NameHandled = false;
public readonly EntityUid Source;
public readonly EntityUid Target;
public CloningEvent(EntityUid source, EntityUid target)
{
Source = source;
Target = target;
}
}

View File

@@ -0,0 +1,60 @@
using Content.Shared.Inventory;
using Content.Shared.Whitelist;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
namespace Content.Shared.Cloning;
/// <summary>
/// Settings for cloning a humanoid.
/// Used to decide which components should be copied.
/// </summary>
[Prototype]
public sealed partial class CloningSettingsPrototype : IPrototype, IInheritingPrototype
{
/// <inheritdoc/>
[IdDataField]
public string ID { get; private set; } = default!;
[ParentDataField(typeof(PrototypeIdArraySerializer<CloningSettingsPrototype>))]
public string[]? Parents { get; }
[AbstractDataField]
[NeverPushInheritance]
public bool Abstract { get; }
/// <summary>
/// Determines if cloning can be prevented by traits etc.
/// </summary>
[DataField]
public bool ForceCloning = true;
/// <summary>
/// Which inventory slots will receive a copy of the original's clothing.
/// Disabled when null.
/// </summary>
[DataField]
public SlotFlags? CopyEquipment = SlotFlags.WITHOUT_POCKET;
/// <summary>
/// Whitelist for the equipment allowed to be copied.
/// </summary>
[DataField]
public EntityWhitelist? Whitelist;
/// <summary>
/// Blacklist for the equipment allowed to be copied.
/// </summary>
[DataField]
public EntityWhitelist? Blacklist;
/// TODO: Make this not a string https://github.com/space-wizards/RobustToolbox/issues/5709
/// <summary>
/// Components to copy from the original to the clone.
/// This only makes a shallow copy of datafields!
/// If you need a deep copy or additional component initialization, then subscribe to CloningEvent instead!
/// </summary>
[DataField]
[AlwaysPushInheritance]
public HashSet<string> Components = new();
}

View File

@@ -9,5 +9,5 @@ namespace Content.Shared.Forensics.Components;
public sealed partial class DnaComponent : Component
{
[DataField("dna"), AutoNetworkedField]
public string DNA = String.Empty;
public string? DNA;
}

View File

@@ -53,7 +53,7 @@ public record struct TransferDnaEvent()
}
/// <summary>
/// An event to generate and act upon new DNA for an entity.
/// Raised on an entity when its DNA has been changed.
/// </summary>
[ByRefEvent]
public record struct GenerateDnaEvent()

View File

@@ -14,6 +14,12 @@ public sealed partial class UnrevivableComponent : Component
[DataField, AutoNetworkedField]
public bool Analyzable = true;
/// <summary>
/// Can this player be cloned using a cloning pod?
/// </summary>
[DataField, AutoNetworkedField]
public bool Cloneable = false;
/// <summary>
/// The loc string used to provide a reason for being unrevivable
/// </summary>