Reduce Triggers Boilerplate. (#41086)
* Push 1 * cleanup + master merge * launchontrigger * A crumb of cleanup --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
891f5a8f6b
commit
c01ec294d0
@@ -14,7 +14,7 @@ using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Trigger.Systems;
|
||||
|
||||
public sealed class ScramOnTriggerSystem : EntitySystem
|
||||
public sealed class ScramOnTriggerSystem : XOnTriggerSystem<ScramOnTriggerComponent>
|
||||
{
|
||||
[Dependency] private readonly PullingSystem _pulling = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
@@ -31,24 +31,14 @@ public sealed class ScramOnTriggerSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ScramOnTriggerComponent, TriggerEvent>(OnTrigger);
|
||||
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
}
|
||||
|
||||
private void OnTrigger(Entity<ScramOnTriggerComponent> ent, ref TriggerEvent args)
|
||||
protected override void OnTrigger(Entity<ScramOnTriggerComponent> ent, EntityUid target, 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))
|
||||
if (TryComp<PullableComponent>(target, out var pull) && _pulling.IsPulled(target, pull))
|
||||
_pulling.TryStopPull(ent, pull);
|
||||
|
||||
// Check if the user is pulling anything, and drop it if so.
|
||||
@@ -61,12 +51,12 @@ public sealed class ScramOnTriggerSystem : EntitySystem
|
||||
if (_net.IsClient)
|
||||
return;
|
||||
|
||||
var xform = Transform(target.Value);
|
||||
var xform = Transform(target);
|
||||
var targetCoords = SelectRandomTileInRange(xform, ent.Comp.TeleportRadius);
|
||||
|
||||
if (targetCoords != null)
|
||||
{
|
||||
_transform.SetCoordinates(target.Value, targetCoords.Value);
|
||||
_transform.SetCoordinates(target, targetCoords.Value);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user