forked from space-wizards/space-station-14
-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New DNA scrambling artifact effect based off of DNA scrambler implant
- Loading branch information
1 parent
dfa73db
commit f3974aa
Showing
4 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...pstation/Xenoarchaeology/XenoArtifacts/Effects/Components/ScrambleDNAArtifactComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...er/_Impstation/Xenoarchaeology/XenoArtifacts/Effects/Systems/ScrambleDNAArtifactSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters