diff --git a/Content.Shared/Anomaly/Effects/Components/BluespaceAnomalyComponent.cs b/Content.Server/Anomaly/Components/BluespaceAnomalyComponent.cs similarity index 86% rename from Content.Shared/Anomaly/Effects/Components/BluespaceAnomalyComponent.cs rename to Content.Server/Anomaly/Components/BluespaceAnomalyComponent.cs index 03b9c3fef0..d1e9e783b9 100644 --- a/Content.Shared/Anomaly/Effects/Components/BluespaceAnomalyComponent.cs +++ b/Content.Server/Anomaly/Components/BluespaceAnomalyComponent.cs @@ -1,9 +1,9 @@ -using Robust.Shared.Audio; -using Robust.Shared.GameStates; +using Content.Server.Anomaly.Effects; +using Robust.Shared.Audio; -namespace Content.Shared.Anomaly.Effects.Components; +namespace Content.Server.Anomaly.Components; -[RegisterComponent, NetworkedComponent, Access(typeof(BluespaceAnomalySystem))] +[RegisterComponent, Access(typeof(BluespaceAnomalySystem))] public sealed class BluespaceAnomalyComponent : Component { /// diff --git a/Content.Shared/Anomaly/Effects/BluespaceAnomalySystem.cs b/Content.Server/Anomaly/Effects/BluespaceAnomalySystem.cs similarity index 95% rename from Content.Shared/Anomaly/Effects/BluespaceAnomalySystem.cs rename to Content.Server/Anomaly/Effects/BluespaceAnomalySystem.cs index dd521aeca0..41e96fb4c8 100644 --- a/Content.Shared/Anomaly/Effects/BluespaceAnomalySystem.cs +++ b/Content.Server/Anomaly/Effects/BluespaceAnomalySystem.cs @@ -1,11 +1,11 @@ using System.Linq; +using Content.Server.Anomaly.Components; using Content.Shared.Anomaly.Components; -using Content.Shared.Anomaly.Effects.Components; using Content.Shared.Mobs.Components; using Content.Shared.Teleportation.Components; using Robust.Shared.Random; -namespace Content.Shared.Anomaly.Effects; +namespace Content.Server.Anomaly.Effects; public sealed class BluespaceAnomalySystem : EntitySystem { @@ -24,13 +24,12 @@ public sealed class BluespaceAnomalySystem : EntitySystem private void OnPulse(EntityUid uid, BluespaceAnomalyComponent component, ref AnomalyPulseEvent args) { - var xform = Transform(uid); + var xformQuery = GetEntityQuery(); + var xform = xformQuery.GetComponent(uid); var range = component.MaxShuffleRadius * args.Severity; var allEnts = _lookup.GetComponentsInRange(xform.Coordinates, range) .Select(x => x.Owner).ToList(); allEnts.Add(uid); - - var xformQuery = GetEntityQuery(); var coords = new List(); foreach (var ent in allEnts) { diff --git a/Content.Shared/Teleportation/Systems/SharedPortalSystem.cs b/Content.Shared/Teleportation/Systems/SharedPortalSystem.cs index f21c9b2efd..3bb0aac29b 100644 --- a/Content.Shared/Teleportation/Systems/SharedPortalSystem.cs +++ b/Content.Shared/Teleportation/Systems/SharedPortalSystem.cs @@ -1,4 +1,5 @@ using System.Linq; +using Content.Shared.Directions; using Content.Shared.Projectiles; using Content.Shared.Pulling; using Content.Shared.Pulling.Components; @@ -8,7 +9,6 @@ using Robust.Shared.Map; using Robust.Shared.Network; using Robust.Shared.Physics.Dynamics; using Robust.Shared.Physics.Events; -using Robust.Shared.Player; using Robust.Shared.Random; namespace Content.Shared.Teleportation.Systems; @@ -20,12 +20,16 @@ public abstract class SharedPortalSystem : EntitySystem { [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly INetManager _netMan = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedPullingSystem _pulling = default!; private const string PortalFixture = "portalFixture"; private const string ProjectileFixture = "projectile"; + private const int MaxRandomTeleportAttempts = 20; + /// public override void Initialize() { @@ -117,9 +121,7 @@ public abstract class SharedPortalSystem : EntitySystem return; // no linked entity--teleport randomly - var randVector = _random.NextVector2(component.MaxRandomRadius); - var newCoords = Transform(uid).Coordinates.Offset(randVector); - TeleportEntity(uid, subject, newCoords); + TeleportRandomly(uid, subject, component); } private void OnEndCollide(EntityUid uid, PortalComponent component, ref EndCollideEvent args) @@ -155,12 +157,33 @@ public abstract class SharedPortalSystem : EntitySystem LogTeleport(portal, subject, Transform(subject).Coordinates, target); - Transform(subject).Coordinates = target; + _transform.SetCoordinates(subject, target); _audio.PlayPredicted(departureSound, portal, subject); _audio.PlayPredicted(arrivalSound, subject, subject); } + private void TeleportRandomly(EntityUid portal, EntityUid subject, PortalComponent? component = null) + { + if (!Resolve(portal, ref component)) + return; + + var xform = Transform(portal); + var coords = xform.Coordinates; + var newCoords = coords.Offset(_random.NextVector2(component.MaxRandomRadius)); + for (var i = 0; i < MaxRandomTeleportAttempts; i++) + { + var randVector = _random.NextVector2(component.MaxRandomRadius); + newCoords = coords.Offset(randVector); + if (!_lookup.GetEntitiesIntersecting(newCoords.ToMap(EntityManager, _transform), LookupFlags.Static).Any()) + { + break; + } + } + + TeleportEntity(portal, subject, newCoords); + } + protected virtual void LogTeleport(EntityUid portal, EntityUid subject, EntityCoordinates source, EntityCoordinates target) {