Skip to content

Commit

Permalink
New DNA scrambling artifact effect
Browse files Browse the repository at this point in the history
New DNA scrambling artifact effect based off of DNA scrambler implant
  • Loading branch information
TheGrimbeeper committed Dec 25, 2024
1 parent dfa73db commit f3974aa
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;

/// <summary>
/// Scrambles DNA of some number of people within some range, possibly outside of their species
/// </summary>
[RegisterComponent]
public sealed partial class ScrambleDNAArtifactComponent : Component
{
/// <summary>
/// Distance from the artifact find people to scramble DNA
/// </summary>
[DataField("range"), ViewVariables(VVAccess.ReadWrite)]
public float Range = 6f;

/// <summary>
/// Number of people to DNA scramble
/// </summary>
[DataField("count"), ViewVariables(VVAccess.ReadWrite)]
public int Count = 1;

/// <summary>
/// Force scrambling to respect initial species
/// </summary>
[DataField("withinSpecies"), ViewVariables(VVAccess.ReadWrite)]
public bool WithinSpecies = true;

/// <summary>
/// if WithinSpecies is false, what species cannot be rolled
/// </summary>
[DataField("excludedSpecies"), ViewVariables(VVAccess.ReadWrite)]
public HashSet<string>? ExcludedSpecies = null;


}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ private void OnActivated(EntityUid uid, KnockdownArtifactComponent component, Ar
_stuns.TryParalyze(child, TimeSpan.FromSeconds(component.KnockdownTime), true, status);
}



}
else // knock over only people in range
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
using Content.Shared.Preferences;
using Content.Server.Humanoid;
using System.Linq;
using Robust.Shared.Random;
using Content.Shared.Humanoid;
using Content.Shared.Forensics;
using Content.Server.Forensics;



namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;

public sealed class ScrambleDNAArtifactSystem : EntitySystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearance = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly ForensicsSystem _forensicsSystem = default!;



/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ScrambleDNAArtifactComponent, ArtifactActivatedEvent>(OnActivated);
}

private void OnActivated(EntityUid uid, ScrambleDNAArtifactComponent component, ArtifactActivatedEvent args)
{
// Get all entities in range, and the person who activated the artifact even if they are not within range
var ents = _lookup.GetEntitiesInRange(uid, component.Range);
if (args.Activator != null)
ents.Add(args.Activator.Value);

//Extract the people who can be scrambled
var possibleVictims = new List<EntityUid>();
foreach (var ent in ents)
{
if (HasComp<HumanoidAppearanceComponent>(ent))
possibleVictims.Add(ent);
}

//Select random targets to scramble DNA
var numScrambled = 0;
while (numScrambled < component.Count){
var targetIndex = _random.Next(0, possibleVictims.Count);
var target = possibleVictims.ElementAt(targetIndex);
possibleVictims.Remove(target);

ScrambleTargetDNA(target, component);
numScrambled ++;
}
}

private void ScrambleTargetDNA(EntityUid target, ScrambleDNAArtifactComponent component)
{
if (TryComp<HumanoidAppearanceComponent>(target, out var humanoid))
{
var newProfile = (component.WithinSpecies ? HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species) : HumanoidCharacterProfile.Random(component.ExcludedSpecies));
_humanoidAppearance.LoadProfile(target, newProfile, humanoid);
_metaData.SetEntityName(target, newProfile.Name);
if (TryComp<DnaComponent>(target, out var dna))
{
dna.DNA = _forensicsSystem.GenerateDNA();

var ev = new GenerateDnaEvent { Owner = target, DNA = dna.DNA };
RaiseLocalEvent(target, ref ev);
}
if (TryComp<FingerprintComponent>(target, out var fingerprint))
{
fingerprint.Fingerprint = _forensicsSystem.GenerateFingerprint();
}
}
}

}
11 changes: 11 additions & 0 deletions Resources/Prototypes/XenoArch/Effects/normal_effects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,17 @@
duration: 10
count: 1

- type: artifactEffect
id: EffectScrambleSingleRare
targetDepth: 4
effectHint: artifact-effect-hint-polymorph
effectProb: 0.01
components:
- type: ScrambleDNAArtifact
range: 4
withinSpecies: true
count: 1

- type: artifactEffect
id: EffectSingulo
targetDepth: 10
Expand Down

0 comments on commit f3974aa

Please sign in to comment.