DoAfter & misc interaction fixes (#15144)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -463,12 +463,16 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
_toolSystem.HasQuality(args.Used, "Pulsing", tool)))
|
||||
{
|
||||
if (TryComp(args.User, out ActorComponent? actor))
|
||||
{
|
||||
_uiSystem.TryOpen(uid, WiresUiKey.Key, actor.PlayerSession);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
else if (_toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, "Screwing", new WirePanelDoAfterEvent(), toolComponent: tool))
|
||||
{
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
||||
$"{ToPrettyString(args.User):user} is screwing {ToPrettyString(uid):target}'s {(panel.Open ? "open" : "closed")} maintenance panel at {Transform(uid).Coordinates:targetlocation}");
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -245,14 +245,14 @@ public sealed class ToggleableClothingSystem : EntitySystem
|
||||
|
||||
var parent = Transform(target).ParentUid;
|
||||
if (component.Container.ContainedEntity == null)
|
||||
_inventorySystem.TryUnequip(parent, component.Slot);
|
||||
_inventorySystem.TryUnequip(user, parent, component.Slot);
|
||||
else if (_inventorySystem.TryGetSlotEntity(parent, component.Slot, out var existing))
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("toggleable-clothing-remove-first", ("entity", existing)),
|
||||
user, user);
|
||||
}
|
||||
else
|
||||
_inventorySystem.TryEquip(parent, component.ClothingUid.Value, component.Slot);
|
||||
_inventorySystem.TryEquip(user, parent, component.ClothingUid.Value, component.Slot);
|
||||
}
|
||||
|
||||
private void OnGetActions(EntityUid uid, ToggleableClothingComponent component, GetItemActionsEvent args)
|
||||
|
||||
@@ -92,8 +92,20 @@ public sealed class EncryptionKeySystem : EntitySystem
|
||||
if ( args.Handled || !TryComp<ContainerManagerComponent>(uid, out var storage))
|
||||
return;
|
||||
|
||||
args.Handled = true;
|
||||
if (HasComp<EncryptionKeyComponent>(args.Used))
|
||||
{
|
||||
args.Handled = true;
|
||||
TryInsertKey(uid, component, args);
|
||||
}
|
||||
else if (TryComp<ToolComponent>(args.Used, out var tool) && tool.Qualities.Contains(component.KeysExtractionMethod))
|
||||
{
|
||||
args.Handled = true;
|
||||
TryRemoveKey(uid, component, args, tool);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryInsertKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
|
||||
{
|
||||
if (!component.KeysUnlocked)
|
||||
{
|
||||
if (_net.IsClient && _timing.IsFirstTimePredicted)
|
||||
@@ -101,18 +113,6 @@ public sealed class EncryptionKeySystem : EntitySystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<EncryptionKeyComponent>(args.Used, out var key))
|
||||
{
|
||||
TryInsertKey(uid, component, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
TryRemoveKey(uid, component, args);
|
||||
}
|
||||
}
|
||||
|
||||
private void TryInsertKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
|
||||
{
|
||||
if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
|
||||
{
|
||||
if (_net.IsClient && _timing.IsFirstTimePredicted)
|
||||
@@ -137,10 +137,15 @@ public sealed class EncryptionKeySystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void TryRemoveKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
|
||||
private void TryRemoveKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args,
|
||||
ToolComponent? tool)
|
||||
{
|
||||
if (!TryComp<ToolComponent>(args.Used, out var tool) || !tool.Qualities.Contains(component.KeysExtractionMethod))
|
||||
if (!component.KeysUnlocked)
|
||||
{
|
||||
if (_net.IsClient && _timing.IsFirstTimePredicted)
|
||||
_popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user