Hand teleporter / portal tweaks (#13305)
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Content.Shared.Interaction.Events;
|
using System.Threading;
|
||||||
|
using Content.Server.DoAfter;
|
||||||
|
using Content.Shared.Interaction.Events;
|
||||||
using Content.Shared.Teleportation.Components;
|
using Content.Shared.Teleportation.Components;
|
||||||
using Content.Shared.Teleportation.Systems;
|
using Content.Shared.Teleportation.Systems;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
@@ -12,11 +14,26 @@ public sealed class HandTeleporterSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly LinkedEntitySystem _link = default!;
|
[Dependency] private readonly LinkedEntitySystem _link = default!;
|
||||||
[Dependency] private readonly AudioSystem _audio = default!;
|
[Dependency] private readonly AudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly DoAfterSystem _doafter = default!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<HandTeleporterComponent, UseInHandEvent>(OnUseInHand);
|
SubscribeLocalEvent<HandTeleporterComponent, UseInHandEvent>(OnUseInHand);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<HandTeleporterComponent, HandTeleporterSuccessEvent>(OnPortalSuccess);
|
||||||
|
SubscribeLocalEvent<HandTeleporterComponent, HandTeleporterCancelledEvent>(OnPortalCancelled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPortalSuccess(EntityUid uid, HandTeleporterComponent component, HandTeleporterSuccessEvent args)
|
||||||
|
{
|
||||||
|
component.CancelToken = null;
|
||||||
|
HandlePortalUpdating(uid, component, args.User);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPortalCancelled(EntityUid uid, HandTeleporterComponent component, HandTeleporterCancelledEvent args)
|
||||||
|
{
|
||||||
|
component.CancelToken = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUseInHand(EntityUid uid, HandTeleporterComponent component, UseInHandEvent args)
|
private void OnUseInHand(EntityUid uid, HandTeleporterComponent component, UseInHandEvent args)
|
||||||
@@ -27,19 +44,67 @@ public sealed class HandTeleporterSystem : EntitySystem
|
|||||||
if (Deleted(component.SecondPortal))
|
if (Deleted(component.SecondPortal))
|
||||||
component.SecondPortal = null;
|
component.SecondPortal = null;
|
||||||
|
|
||||||
|
if (component.CancelToken != null)
|
||||||
|
{
|
||||||
|
component.CancelToken.Cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.FirstPortal != null && component.SecondPortal != null)
|
||||||
|
{
|
||||||
|
// handle removing portals immediately as opposed to a doafter
|
||||||
|
HandlePortalUpdating(uid, component, args.User);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var xform = Transform(args.User);
|
||||||
|
if (xform.ParentUid != xform.GridUid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
component.CancelToken = new CancellationTokenSource();
|
||||||
|
var doafterArgs = new DoAfterEventArgs(args.User, component.PortalCreationDelay,
|
||||||
|
component.CancelToken.Token, used: uid)
|
||||||
|
{
|
||||||
|
BreakOnDamage = true,
|
||||||
|
BreakOnStun = true,
|
||||||
|
BreakOnUserMove = true,
|
||||||
|
MovementThreshold = 0.5f,
|
||||||
|
UsedCancelledEvent = new HandTeleporterCancelledEvent(),
|
||||||
|
UsedFinishedEvent = new HandTeleporterSuccessEvent(args.User)
|
||||||
|
};
|
||||||
|
|
||||||
|
_doafter.DoAfter(doafterArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates or removes a portal given the state of the hand teleporter.
|
||||||
|
/// </summary>
|
||||||
|
private void HandlePortalUpdating(EntityUid uid, HandTeleporterComponent component, EntityUid user)
|
||||||
|
{
|
||||||
|
if (Deleted(user))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var xform = Transform(user);
|
||||||
|
|
||||||
// Create the first portal.
|
// Create the first portal.
|
||||||
if (component.FirstPortal == null && component.SecondPortal == null)
|
if (component.FirstPortal == null && component.SecondPortal == null)
|
||||||
{
|
{
|
||||||
var timeout = EnsureComp<PortalTimeoutComponent>(args.User);
|
// don't portal
|
||||||
|
if (xform.ParentUid != xform.GridUid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var timeout = EnsureComp<PortalTimeoutComponent>(user);
|
||||||
timeout.EnteredPortal = null;
|
timeout.EnteredPortal = null;
|
||||||
component.FirstPortal = Spawn(component.FirstPortalPrototype, Transform(args.User).Coordinates);
|
component.FirstPortal = Spawn(component.FirstPortalPrototype, Transform(user).Coordinates);
|
||||||
_audio.PlayPvs(component.NewPortalSound, uid);
|
_audio.PlayPvs(component.NewPortalSound, uid);
|
||||||
}
|
}
|
||||||
else if (component.SecondPortal == null)
|
else if (component.SecondPortal == null)
|
||||||
{
|
{
|
||||||
var timeout = EnsureComp<PortalTimeoutComponent>(args.User);
|
var timeout = EnsureComp<PortalTimeoutComponent>(user);
|
||||||
timeout.EnteredPortal = null;
|
timeout.EnteredPortal = null;
|
||||||
component.SecondPortal = Spawn(component.SecondPortalPrototype, Transform(args.User).Coordinates);
|
component.SecondPortal = Spawn(component.SecondPortalPrototype, Transform(user).Coordinates);
|
||||||
_link.TryLink(component.FirstPortal!.Value, component.SecondPortal.Value, true);
|
_link.TryLink(component.FirstPortal!.Value, component.SecondPortal.Value, true);
|
||||||
_audio.PlayPvs(component.NewPortalSound, uid);
|
_audio.PlayPvs(component.NewPortalSound, uid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Audio;
|
using System.Threading;
|
||||||
|
using Content.Shared.Audio;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -33,4 +34,22 @@ public sealed class HandTeleporterComponent : Component
|
|||||||
|
|
||||||
[DataField("clearPortalsSound")]
|
[DataField("clearPortalsSound")]
|
||||||
public SoundSpecifier ClearPortalsSound = new SoundPathSpecifier("/Audio/Machines/button.ogg");
|
public SoundSpecifier ClearPortalsSound = new SoundPathSpecifier("/Audio/Machines/button.ogg");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delay for creating the portals in seconds.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("portalCreationDelay")]
|
||||||
|
public float PortalCreationDelay = 2.5f;
|
||||||
|
|
||||||
|
public CancellationTokenSource? CancelToken = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised on doafter success for creating a portal.
|
||||||
|
/// </summary>
|
||||||
|
public record HandTeleporterSuccessEvent(EntityUid User);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised on doafter cancel for creating a portal.
|
||||||
|
/// </summary>
|
||||||
|
public record HandTeleporterCancelledEvent;
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ public sealed class PortalComponent : Component
|
|||||||
/// If no portals are linked, the subject will be teleported a random distance at maximum this far away.
|
/// If no portals are linked, the subject will be teleported a random distance at maximum this far away.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("maxRandomRadius")]
|
[DataField("maxRandomRadius")]
|
||||||
public float MaxRandomRadius = 10.0f;
|
public float MaxRandomRadius = 7.0f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user