DoAfter & misc interaction fixes (#15144)

This commit is contained in:
Leon Friedrich
2023-04-05 12:19:28 +12:00
committed by GitHub
parent f254af53bb
commit b9b8180131
4 changed files with 38 additions and 36 deletions

View File

@@ -7,6 +7,7 @@ using Content.Shared.Construction;
using Content.Shared.Construction.Steps;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Radio.EntitySystems;
using Content.Shared.Tools.Components;
using Robust.Shared.Containers;
using Robust.Shared.Map;
@@ -30,13 +31,20 @@ namespace Content.Server.Construction
private void InitializeInteractions()
{
SubscribeLocalEvent<ConstructionComponent, ConstructionInteractDoAfterEvent>(EnqueueEvent);
SubscribeLocalEvent<ConstructionComponent, ConstructionInteractDoAfterEvent>(OnDoAfterComplete);
// Event handling. Add your subscriptions here! Just make sure they're all handled by EnqueueEvent.
SubscribeLocalEvent<ConstructionComponent, InteractUsingEvent>(EnqueueEvent, new []{typeof(AnchorableSystem)});
SubscribeLocalEvent<ConstructionComponent, InteractUsingEvent>(EnqueueEvent, new []{typeof(AnchorableSystem), typeof(EncryptionKeySystem)});
SubscribeLocalEvent<ConstructionComponent, OnTemperatureChangeEvent>(EnqueueEvent);
}
private void OnDoAfterComplete(EntityUid uid, ConstructionComponent component, ConstructionInteractDoAfterEvent args)
{
component.DoAfter = null;
if (!args.Cancelled)
EnqueueEvent(uid, component, args);
}
/// <summary>
/// Takes in an entity with <see cref="ConstructionComponent"/> and an object event, and handles any
/// possible construction interactions, depending on the construction's state.
@@ -223,11 +231,8 @@ namespace Content.Server.Construction
// The DoAfter events can only perform special logic when we're not validating events.
if (ev is ConstructionInteractDoAfterEvent interactDoAfter)
{
if (!validation)
construction.DoAfter = null;
if (interactDoAfter.Cancelled)
return HandleResult.False;
// cancelled events should not reach this point.
DebugTools.Assert(!interactDoAfter.Cancelled);
ev = new InteractUsingEvent(
interactDoAfter.User,
@@ -256,12 +261,6 @@ namespace Content.Server.Construction
if (ev is not InteractUsingEvent interactUsing)
break;
if (construction.DoAfter != null && !validation)
{
_doAfterSystem.Cancel(construction.DoAfter);
return HandleResult.False;
}
// TODO: Sanity checks.
user = interactUsing.User;
@@ -343,12 +342,6 @@ namespace Content.Server.Construction
if (ev is not InteractUsingEvent interactUsing)
break;
if (construction.DoAfter != null && !validation)
{
_doAfterSystem.Cancel(construction.DoAfter);
return HandleResult.False;
}
// TODO: Sanity checks.
user = interactUsing.User;