Skip to content

Commit

Permalink
Fix position swapping with QSI and artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoGarbage404 committed Mar 23, 2024
1 parent 6a7c059 commit e163bb0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ private void OnActivate(Entity<PortalArtifactComponent> artifact, ref ArtifactAc
var secondPortal = Spawn(artifact.Comp.PortalProto, _transform.GetMapCoordinates(target));

//Manual position swapping, because the portal that opens doesn't trigger a collision, and doesn't teleport targets the first time.
_transform.SetCoordinates(artifact, Transform(secondPortal).Coordinates);
_transform.SetCoordinates(target, Transform(firstPortal).Coordinates);
_transform.SwapPositions(target, secondPortal);

_link.TryLink(firstPortal, secondPortal, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private void OnActivated(EntityUid uid, ShuffleArtifactComponent component, Arti
{
var mobState = GetEntityQuery<MobStateComponent>();

List<EntityCoordinates> allCoords = new();
List<Entity<TransformComponent>> toShuffle = new();

foreach (var ent in _lookup.GetEntitiesInRange(uid, component.Radius, LookupFlags.Dynamic | LookupFlags.Sundries))
Expand All @@ -33,13 +32,15 @@ private void OnActivated(EntityUid uid, ShuffleArtifactComponent component, Arti
var xform = Transform(ent);

toShuffle.Add((ent, xform));
allCoords.Add(xform.Coordinates);
}

foreach (var xform in toShuffle)
_random.Shuffle(toShuffle);

while (toShuffle.Count > 1)
{
var xformUid = xform.Owner;
_xform.SetCoordinates(xformUid, xform, _random.PickAndTake(allCoords));
var ent1 = _random.PickAndTake(toShuffle);
var ent2 = _random.PickAndTake(toShuffle);
_xform.SwapPositions((ent1, ent1), (ent2, ent2));
}
}
}
15 changes: 1 addition & 14 deletions Content.Shared/Teleportation/Systems/SwapTeleporterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,14 @@ public void DoTeleport(Entity<SwapTeleporterComponent, TransformComponent> ent)
}

var teleEnt = GetTeleportingEntity((uid, xform));
var teleEntXform = Transform(teleEnt);
var otherTeleEnt = GetTeleportingEntity((linkedEnt, Transform(linkedEnt)));
var otherTeleEntXform = Transform(otherTeleEnt);

_popup.PopupEntity(Loc.GetString("swap-teleporter-popup-teleport-other",
("entity", Identity.Entity(linkedEnt, EntityManager))),
otherTeleEnt,
otherTeleEnt,
PopupType.MediumCaution);
var pos = teleEntXform.Coordinates;
var otherPos = otherTeleEntXform.Coordinates;

if (_transform.ContainsEntity(teleEnt, (otherTeleEnt, otherTeleEntXform)) ||
_transform.ContainsEntity(otherTeleEnt, (teleEnt, teleEntXform)))
{
Log.Error($"Invalid teleport swap attempt between {ToPrettyString(teleEnt)} and {ToPrettyString(otherTeleEnt)}");
return;
}

_transform.SetCoordinates(teleEnt, otherPos);
_transform.SetCoordinates(otherTeleEnt, pos);
_transform.SwapPositions(teleEnt, otherTeleEnt);
}

/// <remarks>
Expand Down

0 comments on commit e163bb0

Please sign in to comment.