Turn some implants into triggers (#39364)
Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
This commit is contained in:
5
Content.Client/Forensics/Systems/ForensicsSystem.cs
Normal file
5
Content.Client/Forensics/Systems/ForensicsSystem.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using Content.Shared.Forensics.Systems;
|
||||||
|
|
||||||
|
namespace Content.Client.Forensics.Systems;
|
||||||
|
|
||||||
|
public sealed class ForensicsSystem : SharedForensicsSystem;
|
||||||
@@ -12,6 +12,7 @@ using Content.Shared.Chemistry.Components.SolutionManager;
|
|||||||
using Content.Shared.DoAfter;
|
using Content.Shared.DoAfter;
|
||||||
using Content.Shared.Forensics;
|
using Content.Shared.Forensics;
|
||||||
using Content.Shared.Forensics.Components;
|
using Content.Shared.Forensics.Components;
|
||||||
|
using Content.Shared.Forensics.Systems;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Interaction.Events;
|
using Content.Shared.Interaction.Events;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
@@ -23,7 +24,7 @@ using Content.Shared.Hands.Components;
|
|||||||
|
|
||||||
namespace Content.Server.Forensics
|
namespace Content.Server.Forensics
|
||||||
{
|
{
|
||||||
public sealed class ForensicsSystem : EntitySystem
|
public sealed class ForensicsSystem : SharedForensicsSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||||
@@ -317,12 +318,7 @@ namespace Content.Server.Forensics
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region Public API
|
#region Public API
|
||||||
|
public override void RandomizeDNA(Entity<DnaComponent?> ent)
|
||||||
/// <summary>
|
|
||||||
/// Give the entity a new, random DNA string and call an event to notify other systems like the bloodstream that it has been changed.
|
|
||||||
/// Does nothing if it does not have the DnaComponent.
|
|
||||||
/// </summary>
|
|
||||||
public void RandomizeDNA(Entity<DnaComponent?> ent)
|
|
||||||
{
|
{
|
||||||
if (!Resolve(ent, ref ent.Comp, false))
|
if (!Resolve(ent, ref ent.Comp, false))
|
||||||
return;
|
return;
|
||||||
@@ -334,11 +330,7 @@ namespace Content.Server.Forensics
|
|||||||
RaiseLocalEvent(ent.Owner, ref ev);
|
RaiseLocalEvent(ent.Owner, ref ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public override void RandomizeFingerprint(Entity<FingerprintComponent?> ent)
|
||||||
/// Give the entity a new, random fingerprint string.
|
|
||||||
/// Does nothing if it does not have the FingerprintComponent.
|
|
||||||
/// </summary>
|
|
||||||
public void RandomizeFingerprint(Entity<FingerprintComponent?> ent)
|
|
||||||
{
|
{
|
||||||
if (!Resolve(ent, ref ent.Comp, false))
|
if (!Resolve(ent, ref ent.Comp, false))
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
using Content.Server.Implants;
|
|
||||||
using Robust.Shared.Audio;
|
|
||||||
|
|
||||||
namespace Content.Server.Implants.Components;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Randomly teleports entity when triggered.
|
|
||||||
/// </summary>
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed partial class ScramImplantComponent : Component
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Up to how far to teleport the user
|
|
||||||
/// </summary>
|
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public float TeleportRadius = 100f;
|
|
||||||
|
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public SoundSpecifier TeleportSound = new SoundPathSpecifier("/Audio/Effects/teleport_arrival.ogg");
|
|
||||||
}
|
|
||||||
@@ -1,66 +1,21 @@
|
|||||||
using Content.Server.Cuffs;
|
|
||||||
using Content.Server.Forensics;
|
|
||||||
using Content.Server.Humanoid;
|
|
||||||
using Content.Server.Implants.Components;
|
|
||||||
using Content.Server.Store.Components;
|
using Content.Server.Store.Components;
|
||||||
using Content.Server.Store.Systems;
|
using Content.Server.Store.Systems;
|
||||||
using Content.Shared.Cuffs.Components;
|
|
||||||
using Content.Shared.Forensics;
|
|
||||||
using Content.Shared.Forensics.Components;
|
|
||||||
using Content.Shared.Humanoid;
|
|
||||||
using Content.Shared.Implants;
|
using Content.Shared.Implants;
|
||||||
using Content.Shared.Implants.Components;
|
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Physics;
|
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.Preferences;
|
|
||||||
using Robust.Shared.Audio.Systems;
|
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.Physics;
|
|
||||||
using Robust.Shared.Physics.Components;
|
|
||||||
using Robust.Shared.Random;
|
|
||||||
using System.Numerics;
|
|
||||||
using Content.Shared.Movement.Pulling.Components;
|
|
||||||
using Content.Shared.Movement.Pulling.Systems;
|
|
||||||
using Content.Server.IdentityManagement;
|
|
||||||
using Content.Shared.DetailExaminable;
|
|
||||||
using Content.Shared.Store.Components;
|
using Content.Shared.Store.Components;
|
||||||
using Robust.Shared.Collections;
|
|
||||||
using Robust.Shared.Map.Components;
|
|
||||||
|
|
||||||
namespace Content.Server.Implants;
|
namespace Content.Server.Implants;
|
||||||
|
|
||||||
public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
|
public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly CuffableSystem _cuffable = default!;
|
|
||||||
[Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearance = default!;
|
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
|
||||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
|
||||||
[Dependency] private readonly StoreSystem _store = default!;
|
[Dependency] private readonly StoreSystem _store = default!;
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
||||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||||
[Dependency] private readonly SharedTransformSystem _xform = default!;
|
|
||||||
[Dependency] private readonly ForensicsSystem _forensicsSystem = default!;
|
|
||||||
[Dependency] private readonly PullingSystem _pullingSystem = default!;
|
|
||||||
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
|
|
||||||
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
|
||||||
[Dependency] private readonly IdentitySystem _identity = default!;
|
|
||||||
|
|
||||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
|
||||||
private HashSet<Entity<MapGridComponent>> _targetGrids = [];
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
|
||||||
|
|
||||||
SubscribeLocalEvent<SubdermalImplantComponent, UseFreedomImplantEvent>(OnFreedomImplant);
|
|
||||||
SubscribeLocalEvent<StoreComponent, ImplantRelayEvent<AfterInteractUsingEvent>>(OnStoreRelay);
|
SubscribeLocalEvent<StoreComponent, ImplantRelayEvent<AfterInteractUsingEvent>>(OnStoreRelay);
|
||||||
SubscribeLocalEvent<SubdermalImplantComponent, ActivateImplantEvent>(OnActivateImplantEvent);
|
|
||||||
SubscribeLocalEvent<SubdermalImplantComponent, UseScramImplantEvent>(OnScramImplant);
|
|
||||||
SubscribeLocalEvent<SubdermalImplantComponent, UseDnaScramblerImplantEvent>(OnDnaScramblerImplant);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStoreRelay(EntityUid uid, StoreComponent store, ImplantRelayEvent<AfterInteractUsingEvent> implantRelay)
|
private void OnStoreRelay(EntityUid uid, StoreComponent store, ImplantRelayEvent<AfterInteractUsingEvent> implantRelay)
|
||||||
@@ -85,148 +40,4 @@ public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
|
|||||||
var msg = Loc.GetString("store-currency-inserted-implant", ("used", args.Used));
|
var msg = Loc.GetString("store-currency-inserted-implant", ("used", args.Used));
|
||||||
_popup.PopupEntity(msg, args.User, args.User);
|
_popup.PopupEntity(msg, args.User, args.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
|
|
||||||
{
|
|
||||||
if (!TryComp<CuffableComponent>(component.ImplantedEntity, out var cuffs) || cuffs.Container.ContainedEntities.Count < 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_cuffable.Uncuff(component.ImplantedEntity.Value, cuffs.LastAddedCuffs, cuffs.LastAddedCuffs);
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnActivateImplantEvent(EntityUid uid, SubdermalImplantComponent component, ActivateImplantEvent args)
|
|
||||||
{
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnScramImplant(EntityUid uid, SubdermalImplantComponent component, UseScramImplantEvent args)
|
|
||||||
{
|
|
||||||
if (component.ImplantedEntity is not { } ent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!TryComp<ScramImplantComponent>(uid, out var implant))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// We need stop the user from being pulled so they don't just get "attached" with whoever is pulling them.
|
|
||||||
// This can for example happen when the user is cuffed and being pulled.
|
|
||||||
if (TryComp<PullableComponent>(ent, out var pull) && _pullingSystem.IsPulled(ent, pull))
|
|
||||||
_pullingSystem.TryStopPull(ent, pull);
|
|
||||||
|
|
||||||
// Check if the user is pulling anything, and drop it if so
|
|
||||||
if (TryComp<PullerComponent>(ent, out var puller) && TryComp<PullableComponent>(puller.Pulling, out var pullable))
|
|
||||||
_pullingSystem.TryStopPull(puller.Pulling.Value, pullable);
|
|
||||||
|
|
||||||
var xform = Transform(ent);
|
|
||||||
var targetCoords = SelectRandomTileInRange(xform, implant.TeleportRadius);
|
|
||||||
|
|
||||||
if (targetCoords != null)
|
|
||||||
{
|
|
||||||
_xform.SetCoordinates(ent, targetCoords.Value);
|
|
||||||
_audio.PlayPvs(implant.TeleportSound, ent);
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private EntityCoordinates? SelectRandomTileInRange(TransformComponent userXform, float radius)
|
|
||||||
{
|
|
||||||
var userCoords = _xform.ToMapCoordinates(userXform.Coordinates);
|
|
||||||
_targetGrids.Clear();
|
|
||||||
_lookupSystem.GetEntitiesInRange(userCoords, radius, _targetGrids);
|
|
||||||
Entity<MapGridComponent>? targetGrid = null;
|
|
||||||
|
|
||||||
if (_targetGrids.Count == 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// Give preference to the grid the entity is currently on.
|
|
||||||
// This does not guarantee that if the probability fails that the owner's grid won't be picked.
|
|
||||||
// In reality the probability is higher and depends on the number of grids.
|
|
||||||
if (userXform.GridUid != null && TryComp<MapGridComponent>(userXform.GridUid, out var gridComp))
|
|
||||||
{
|
|
||||||
var userGrid = new Entity<MapGridComponent>(userXform.GridUid.Value, gridComp);
|
|
||||||
if (_random.Prob(0.5f))
|
|
||||||
{
|
|
||||||
_targetGrids.Remove(userGrid);
|
|
||||||
targetGrid = userGrid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetGrid == null)
|
|
||||||
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);
|
|
||||||
|
|
||||||
EntityCoordinates? targetCoords = null;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
var valid = false;
|
|
||||||
|
|
||||||
var range = (float) Math.Sqrt(radius);
|
|
||||||
var box = Box2.CenteredAround(userCoords.Position, new Vector2(range, range));
|
|
||||||
var tilesInRange = _mapSystem.GetTilesEnumerator(targetGrid.Value.Owner, targetGrid.Value.Comp, box, false);
|
|
||||||
var tileList = new ValueList<Vector2i>();
|
|
||||||
|
|
||||||
while (tilesInRange.MoveNext(out var tile))
|
|
||||||
{
|
|
||||||
tileList.Add(tile.GridIndices);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (tileList.Count != 0)
|
|
||||||
{
|
|
||||||
var tile = tileList.RemoveSwap(_random.Next(tileList.Count));
|
|
||||||
valid = true;
|
|
||||||
foreach (var entity in _mapSystem.GetAnchoredEntities(targetGrid.Value.Owner, targetGrid.Value.Comp,
|
|
||||||
tile))
|
|
||||||
{
|
|
||||||
if (!_physicsQuery.TryGetComponent(entity, out var body))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (body.BodyType != BodyType.Static ||
|
|
||||||
!body.Hard ||
|
|
||||||
(body.CollisionLayer & (int) CollisionGroup.MobMask) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
valid = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid)
|
|
||||||
{
|
|
||||||
targetCoords = new EntityCoordinates(targetGrid.Value.Owner,
|
|
||||||
_mapSystem.TileCenterToVector(targetGrid.Value, tile));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid || _targetGrids.Count == 0) // if we don't do the check here then PickAndTake will blow up on an empty set.
|
|
||||||
break;
|
|
||||||
|
|
||||||
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);
|
|
||||||
} while (true);
|
|
||||||
|
|
||||||
return targetCoords;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDnaScramblerImplant(EntityUid uid, SubdermalImplantComponent component, UseDnaScramblerImplantEvent args)
|
|
||||||
{
|
|
||||||
if (component.ImplantedEntity is not { } ent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (TryComp<HumanoidAppearanceComponent>(ent, out var humanoid))
|
|
||||||
{
|
|
||||||
var newProfile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
|
|
||||||
_humanoidAppearance.LoadProfile(ent, newProfile, humanoid);
|
|
||||||
_metaData.SetEntityName(ent, newProfile.Name, raiseEvents: false); // raising events would update ID card, station record, etc.
|
|
||||||
|
|
||||||
// If the entity has the respecive components, then scramble the dna and fingerprint strings
|
|
||||||
_forensicsSystem.RandomizeDNA(ent);
|
|
||||||
_forensicsSystem.RandomizeFingerprint(ent);
|
|
||||||
|
|
||||||
RemComp<DetailExaminableComponent>(ent); // remove MRP+ custom description if one exists
|
|
||||||
_identity.QueueIdentityUpdate(ent); // manually queue identity update since we don't raise the event
|
|
||||||
_popup.PopupEntity(Loc.GetString("scramble-implant-activated-popup"), ent, ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
args.Handled = true;
|
|
||||||
QueueDel(uid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
Content.Shared/Forensics/Systems/SharedForensicsSystem.cs
Normal file
18
Content.Shared/Forensics/Systems/SharedForensicsSystem.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Content.Shared.Forensics.Components;
|
||||||
|
|
||||||
|
namespace Content.Shared.Forensics.Systems;
|
||||||
|
|
||||||
|
public abstract class SharedForensicsSystem : EntitySystem
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Give the entity a new, random DNA string and call an event to notify other systems like the bloodstream that it has been changed.
|
||||||
|
/// Does nothing if it does not have the DnaComponent.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void RandomizeDNA(Entity<DnaComponent?> ent) { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Give the entity a new, random fingerprint string.
|
||||||
|
/// Does nothing if it does not have the FingerprintComponent.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void RandomizeFingerprint(Entity<FingerprintComponent?> ent) { }
|
||||||
|
}
|
||||||
@@ -66,11 +66,6 @@ public sealed partial class OpenStorageImplantEvent : InstantActionEvent
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed partial class UseFreedomImplantEvent : InstantActionEvent
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used for triggering trigger events on the implant via action
|
/// Used for triggering trigger events on the implant via action
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -86,13 +81,3 @@ public sealed partial class OpenUplinkImplantEvent : InstantActionEvent
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed partial class UseScramImplantEvent : InstantActionEvent
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed partial class UseDnaScramblerImplantEvent : InstantActionEvent
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace micro bomb with macro bomb
|
// replace micro bomb with macro bomb
|
||||||
|
// TODO: this shouldn't be hardcoded here
|
||||||
if (_container.TryGetContainer(component.ImplantedEntity.Value, ImplanterComponent.ImplantSlotId, out var implantContainer) && _tag.HasTag(uid, MacroBombTag))
|
if (_container.TryGetContainer(component.ImplantedEntity.Value, ImplanterComponent.ImplantSlotId, out var implantContainer) && _tag.HasTag(uid, MacroBombTag))
|
||||||
{
|
{
|
||||||
foreach (var implant in implantContainer.ContainedEntities)
|
foreach (var implant in implantContainer.ContainedEntities)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Components.Effects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scrambles the entity's identity and DNA, turning them into a randomized humanoid of the same species.
|
||||||
|
/// If TargetUser is true the user will be scrambled instead.
|
||||||
|
/// Used for dna scrambler implants.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
public sealed partial class DnaScrambleOnTriggerComponent : BaseXOnTriggerComponent;
|
||||||
@@ -24,7 +24,7 @@ public sealed partial class RattleOnTriggerComponent : BaseXOnTriggerComponent
|
|||||||
[DataField]
|
[DataField]
|
||||||
public Dictionary<MobState, LocId> Messages = new()
|
public Dictionary<MobState, LocId> Messages = new()
|
||||||
{
|
{
|
||||||
{MobState.Critical, "deathrattle-implant-critical-message"},
|
{MobState.Critical, "rattle-on-trigger-critical-message"},
|
||||||
{MobState.Dead, "deathrattle-implant-dead-message"}
|
{MobState.Dead, "rattle-on-trigger-dead-message"}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Components.Effects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Randomly teleports the entity when triggered.
|
||||||
|
/// If TargetUser is true the user will be teleported instead.
|
||||||
|
/// Used for scram implants.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
public sealed partial class ScramOnTriggerComponent : BaseXOnTriggerComponent
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Up to how far to teleport the entity.
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public float TeleportRadius = 100f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// the sound to play when teleporting.
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public SoundSpecifier TeleportSound = new SoundPathSpecifier("/Audio/Effects/teleport_arrival.ogg");
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Components.Effects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a pair of handcuffs from the entity.
|
||||||
|
/// If TargetUser is true the user will be uncuffed instead.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
public sealed partial class UncuffOnTriggerComponent : BaseXOnTriggerComponent;
|
||||||
62
Content.Shared/Trigger/Systems/DnaScrambleOnTriggerSystem.cs
Normal file
62
Content.Shared/Trigger/Systems/DnaScrambleOnTriggerSystem.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Content.Shared.DetailExaminable;
|
||||||
|
using Content.Shared.Forensics.Systems;
|
||||||
|
using Content.Shared.Humanoid;
|
||||||
|
using Content.Shared.IdentityManagement;
|
||||||
|
using Content.Shared.Preferences;
|
||||||
|
using Content.Shared.Popups;
|
||||||
|
using Content.Shared.Trigger.Components.Effects;
|
||||||
|
using Robust.Shared.Network;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Systems;
|
||||||
|
|
||||||
|
public sealed class DnaScrambleOnTriggerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||||
|
[Dependency] private readonly SharedHumanoidAppearanceSystem _humanoidAppearance = default!;
|
||||||
|
[Dependency] private readonly SharedIdentitySystem _identity = default!;
|
||||||
|
[Dependency] private readonly SharedForensicsSystem _forensics = default!;
|
||||||
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||||
|
[Dependency] private readonly INetManager _net = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<DnaScrambleOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTrigger(Entity<DnaScrambleOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
|
{
|
||||||
|
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TryComp<HumanoidAppearanceComponent>(target, out var humanoid))
|
||||||
|
return;
|
||||||
|
|
||||||
|
args.Handled = true;
|
||||||
|
|
||||||
|
// Randomness will mispredict
|
||||||
|
// and LoadProfile causes a debug assert on the client at the moment.
|
||||||
|
if (_net.IsClient)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var newProfile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
|
||||||
|
_humanoidAppearance.LoadProfile(target.Value, newProfile, humanoid);
|
||||||
|
_metaData.SetEntityName(target.Value, newProfile.Name, raiseEvents: false); // raising events would update ID card, station record, etc.
|
||||||
|
|
||||||
|
// If the entity has the respective components, then scramble the dna and fingerprint strings.
|
||||||
|
_forensics.RandomizeDNA(target.Value);
|
||||||
|
_forensics.RandomizeFingerprint(target.Value);
|
||||||
|
|
||||||
|
RemComp<DetailExaminableComponent>(target.Value); // remove MRP+ custom description if one exists
|
||||||
|
_identity.QueueIdentityUpdate(target.Value); // manually queue identity update since we don't raise the event
|
||||||
|
|
||||||
|
// Can't use PopupClient or PopupPredicted because the trigger might be unpredicted.
|
||||||
|
_popup.PopupEntity(Loc.GetString("scramble-on-trigger-popup"), target.Value, target.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
151
Content.Shared/Trigger/Systems/ScramOnTriggerSystem.cs
Normal file
151
Content.Shared/Trigger/Systems/ScramOnTriggerSystem.cs
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
using System.Numerics;
|
||||||
|
using Content.Shared.Movement.Pulling.Components;
|
||||||
|
using Content.Shared.Movement.Pulling.Systems;
|
||||||
|
using Content.Shared.Physics;
|
||||||
|
using Content.Shared.Trigger.Components.Effects;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Map.Components;
|
||||||
|
using Robust.Shared.Network;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
|
using Robust.Shared.Physics.Components;
|
||||||
|
using Robust.Shared.Audio.Systems;
|
||||||
|
using Robust.Shared.Collections;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Systems;
|
||||||
|
|
||||||
|
public sealed class ScramOnTriggerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly PullingSystem _pulling = default!;
|
||||||
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
[Dependency] private readonly SharedMapSystem _map = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly INetManager _net = default!;
|
||||||
|
|
||||||
|
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||||
|
private HashSet<Entity<MapGridComponent>> _targetGrids = new();
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<ScramOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||||
|
|
||||||
|
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTrigger(Entity<ScramOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
|
{
|
||||||
|
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// We need stop the user from being pulled so they don't just get "attached" with whoever is pulling them.
|
||||||
|
// This can for example happen when the user is cuffed and being pulled.
|
||||||
|
if (TryComp<PullableComponent>(target, out var pull) && _pulling.IsPulled(target.Value, pull))
|
||||||
|
_pulling.TryStopPull(ent, pull);
|
||||||
|
|
||||||
|
// Check if the user is pulling anything, and drop it if so.
|
||||||
|
if (TryComp<PullerComponent>(target, out var puller) && TryComp<PullableComponent>(puller.Pulling, out var pullable))
|
||||||
|
_pulling.TryStopPull(puller.Pulling.Value, pullable);
|
||||||
|
|
||||||
|
_audio.PlayPredicted(ent.Comp.TeleportSound, ent, args.User);
|
||||||
|
|
||||||
|
// Can't predict picking random grids and the target location might be out of PVS range.
|
||||||
|
if (_net.IsClient)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var xform = Transform(target.Value);
|
||||||
|
var targetCoords = SelectRandomTileInRange(xform, ent.Comp.TeleportRadius);
|
||||||
|
|
||||||
|
if (targetCoords != null)
|
||||||
|
{
|
||||||
|
_transform.SetCoordinates(target.Value, targetCoords.Value);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityCoordinates? SelectRandomTileInRange(TransformComponent userXform, float radius)
|
||||||
|
{
|
||||||
|
var userCoords = _transform.ToMapCoordinates(userXform.Coordinates);
|
||||||
|
_targetGrids.Clear();
|
||||||
|
_lookup.GetEntitiesInRange(userCoords, radius, _targetGrids);
|
||||||
|
Entity<MapGridComponent>? targetGrid = null;
|
||||||
|
|
||||||
|
if (_targetGrids.Count == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Give preference to the grid the entity is currently on.
|
||||||
|
// This does not guarantee that if the probability fails that the owner's grid won't be picked.
|
||||||
|
// In reality the probability is higher and depends on the number of grids.
|
||||||
|
if (userXform.GridUid != null && TryComp<MapGridComponent>(userXform.GridUid, out var gridComp))
|
||||||
|
{
|
||||||
|
var userGrid = new Entity<MapGridComponent>(userXform.GridUid.Value, gridComp);
|
||||||
|
if (_random.Prob(0.5f))
|
||||||
|
{
|
||||||
|
_targetGrids.Remove(userGrid);
|
||||||
|
targetGrid = userGrid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetGrid == null)
|
||||||
|
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);
|
||||||
|
|
||||||
|
EntityCoordinates? targetCoords = null;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
var valid = false;
|
||||||
|
|
||||||
|
var range = (float)Math.Sqrt(radius);
|
||||||
|
var box = Box2.CenteredAround(userCoords.Position, new Vector2(range, range));
|
||||||
|
var tilesInRange = _map.GetTilesEnumerator(targetGrid.Value.Owner, targetGrid.Value.Comp, box, false);
|
||||||
|
var tileList = new ValueList<Vector2i>();
|
||||||
|
|
||||||
|
while (tilesInRange.MoveNext(out var tile))
|
||||||
|
{
|
||||||
|
tileList.Add(tile.GridIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (tileList.Count != 0)
|
||||||
|
{
|
||||||
|
var tile = tileList.RemoveSwap(_random.Next(tileList.Count));
|
||||||
|
valid = true;
|
||||||
|
foreach (var entity in _map.GetAnchoredEntities(targetGrid.Value.Owner, targetGrid.Value.Comp,
|
||||||
|
tile))
|
||||||
|
{
|
||||||
|
if (!_physicsQuery.TryGetComponent(entity, out var body))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (body.BodyType != BodyType.Static ||
|
||||||
|
!body.Hard ||
|
||||||
|
(body.CollisionLayer & (int)CollisionGroup.MobMask) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
valid = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
targetCoords = new EntityCoordinates(targetGrid.Value.Owner,
|
||||||
|
_map.TileCenterToVector(targetGrid.Value, tile));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid || _targetGrids.Count == 0) // if we don't do the check here then PickAndTake will blow up on an empty set.
|
||||||
|
break;
|
||||||
|
|
||||||
|
targetGrid = _random.GetRandom().PickAndTake(_targetGrids);
|
||||||
|
} while (true);
|
||||||
|
|
||||||
|
return targetCoords;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
Content.Shared/Trigger/Systems/UncuffOnTriggerSystem.cs
Normal file
34
Content.Shared/Trigger/Systems/UncuffOnTriggerSystem.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Content.Shared.Cuffs;
|
||||||
|
using Content.Shared.Cuffs.Components;
|
||||||
|
using Content.Shared.Trigger.Components.Effects;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Systems;
|
||||||
|
|
||||||
|
public sealed class UncuffOnTriggerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly SharedCuffableSystem _cuffable = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<UncuffOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTrigger(Entity<UncuffOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
|
{
|
||||||
|
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TryComp<CuffableComponent>(target.Value, out var cuffs) || cuffs.Container.ContainedEntities.Count < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_cuffable.Uncuff(target.Value, args.User, cuffs.LastAddedCuffs);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,12 +25,3 @@ implanter-label-draw = [color=red]{$implantName}[/color]
|
|||||||
Mode: [color=white]{$modeString}[/color]
|
Mode: [color=white]{$modeString}[/color]
|
||||||
|
|
||||||
implanter-contained-implant-text = [color=green]{$desc}[/color]
|
implanter-contained-implant-text = [color=green]{$desc}[/color]
|
||||||
|
|
||||||
## Implant Popups
|
|
||||||
|
|
||||||
scramble-implant-activated-popup = Your appearance shifts and changes!
|
|
||||||
|
|
||||||
## Implant Messages
|
|
||||||
|
|
||||||
deathrattle-implant-dead-message = {$user} has died {$position}.
|
|
||||||
deathrattle-implant-critical-message = {$user} life signs critical, immediate assistance required {$position}.
|
|
||||||
|
|||||||
2
Resources/Locale/en-US/triggers/rattle-on-trigger.ftl
Normal file
2
Resources/Locale/en-US/triggers/rattle-on-trigger.ftl
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
rattle-on-trigger-dead-message = {$user} has died {$position}.
|
||||||
|
rattle-on-trigger-critical-message = {$user} life signs critical, immediate assistance required {$position}.
|
||||||
1
Resources/Locale/en-US/triggers/scramble-on-trigger.ftl
Normal file
1
Resources/Locale/en-US/triggers/scramble-on-trigger.ftl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
scramble-on-trigger-popup = Your appearance shifts and changes!
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
state: gib
|
state: gib
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseAction
|
parent: BaseImplantAction
|
||||||
id: ActionActivateFreedomImplant
|
id: ActionActivateFreedomImplant
|
||||||
name: Break Free
|
name: Break Free
|
||||||
description: Activating your freedom implant will free you from any hand restraints
|
description: Activating your freedom implant will free you from any hand restraints
|
||||||
@@ -135,8 +135,6 @@
|
|||||||
icon:
|
icon:
|
||||||
sprite: Actions/Implants/implants.rsi
|
sprite: Actions/Implants/implants.rsi
|
||||||
state: freedom
|
state: freedom
|
||||||
- type: InstantAction
|
|
||||||
event: !type:UseFreedomImplantEvent
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseAction
|
parent: BaseAction
|
||||||
@@ -171,7 +169,7 @@
|
|||||||
state: icon
|
state: icon
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseAction
|
parent: BaseImplantAction
|
||||||
id: ActionActivateScramImplant
|
id: ActionActivateScramImplant
|
||||||
name: SCRAM!
|
name: SCRAM!
|
||||||
description: Randomly teleports you within a large distance.
|
description: Randomly teleports you within a large distance.
|
||||||
@@ -186,11 +184,9 @@
|
|||||||
icon:
|
icon:
|
||||||
sprite: Structures/Specific/anomaly.rsi
|
sprite: Structures/Specific/anomaly.rsi
|
||||||
state: anom4
|
state: anom4
|
||||||
- type: InstantAction
|
|
||||||
event: !type:UseScramImplantEvent
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseAction
|
parent: BaseImplantAction
|
||||||
id: ActionActivateDnaScramblerImplant
|
id: ActionActivateDnaScramblerImplant
|
||||||
name: Scramble DNA
|
name: Scramble DNA
|
||||||
description: Randomly changes your name and appearance.
|
description: Randomly changes your name and appearance.
|
||||||
@@ -205,8 +201,6 @@
|
|||||||
icon:
|
icon:
|
||||||
sprite: Clothing/OuterClothing/Hardsuits/lingspacesuit.rsi
|
sprite: Clothing/OuterClothing/Hardsuits/lingspacesuit.rsi
|
||||||
state: icon
|
state: icon
|
||||||
- type: InstantAction
|
|
||||||
event: !type:UseDnaScramblerImplantEvent
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseAction
|
parent: BaseAction
|
||||||
|
|||||||
@@ -140,6 +140,9 @@
|
|||||||
whitelist:
|
whitelist:
|
||||||
components:
|
components:
|
||||||
- Cuffable # useless if you cant be cuffed
|
- Cuffable # useless if you cant be cuffed
|
||||||
|
- type: TriggerOnActivateImplant
|
||||||
|
- type: UncuffOnTrigger
|
||||||
|
targetUser: true
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseSubdermalImplant
|
parent: BaseSubdermalImplant
|
||||||
@@ -198,7 +201,8 @@
|
|||||||
- type: SubdermalImplant
|
- type: SubdermalImplant
|
||||||
implantAction: ActionActivateScramImplant
|
implantAction: ActionActivateScramImplant
|
||||||
- type: TriggerOnActivateImplant
|
- type: TriggerOnActivateImplant
|
||||||
- type: ScramImplant
|
- type: ScramOnTrigger
|
||||||
|
targetUser: true
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseSubdermalImplant
|
parent: BaseSubdermalImplant
|
||||||
@@ -212,6 +216,10 @@
|
|||||||
whitelist:
|
whitelist:
|
||||||
components:
|
components:
|
||||||
- HumanoidAppearance # syndies cant turn hamlet into a human
|
- HumanoidAppearance # syndies cant turn hamlet into a human
|
||||||
|
- type: TriggerOnActivateImplant
|
||||||
|
- type: DnaScrambleOnTrigger
|
||||||
|
targetUser: true
|
||||||
|
- type: DeleteOnTrigger
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
categories: [ HideSpawnMenu, Spawner ]
|
categories: [ HideSpawnMenu, Spawner ]
|
||||||
|
|||||||
Reference in New Issue
Block a user