prevent magnet deconstruction when active (#19849)
* raise ToolUseAttemptEvent on target as well as tool * prevent using tools on magnet when active --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -25,6 +25,7 @@ using Content.Shared.CCVar;
|
|||||||
using Content.Shared.Construction.EntitySystems;
|
using Content.Shared.Construction.EntitySystems;
|
||||||
using Content.Shared.Random;
|
using Content.Shared.Random;
|
||||||
using Content.Shared.Random.Helpers;
|
using Content.Shared.Random.Helpers;
|
||||||
|
using Content.Shared.Tools.Components;
|
||||||
using Robust.Server.Maps;
|
using Robust.Server.Maps;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -68,6 +69,7 @@ namespace Content.Server.Salvage
|
|||||||
SubscribeLocalEvent<SalvageMagnetComponent, RefreshPartsEvent>(OnRefreshParts);
|
SubscribeLocalEvent<SalvageMagnetComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||||
SubscribeLocalEvent<SalvageMagnetComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
SubscribeLocalEvent<SalvageMagnetComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||||
SubscribeLocalEvent<SalvageMagnetComponent, ExaminedEvent>(OnExamined);
|
SubscribeLocalEvent<SalvageMagnetComponent, ExaminedEvent>(OnExamined);
|
||||||
|
SubscribeLocalEvent<SalvageMagnetComponent, ToolUseAttemptEvent>(OnToolUseAttempt);
|
||||||
SubscribeLocalEvent<SalvageMagnetComponent, ComponentShutdown>(OnMagnetRemoval);
|
SubscribeLocalEvent<SalvageMagnetComponent, ComponentShutdown>(OnMagnetRemoval);
|
||||||
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoval);
|
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoval);
|
||||||
|
|
||||||
@@ -232,6 +234,15 @@ namespace Content.Server.Salvage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnToolUseAttempt(EntityUid uid, SalvageMagnetComponent comp, ToolUseAttemptEvent args)
|
||||||
|
{
|
||||||
|
// prevent reconstruct exploit to "leak" wrecks or skip cooldowns
|
||||||
|
if (comp.MagnetState != MagnetState.Inactive)
|
||||||
|
{
|
||||||
|
args.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnInteractHand(EntityUid uid, SalvageMagnetComponent component, InteractHandEvent args)
|
private void OnInteractHand(EntityUid uid, SalvageMagnetComponent component, InteractHandEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace Content.Shared.Tools.Components
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempt event called *before* any do afters to see if the tool usage should succeed or not.
|
/// Attempt event called *before* any do afters to see if the tool usage should succeed or not.
|
||||||
|
/// Raised on both the tool and then target.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ToolUseAttemptEvent : CancellableEntityEventArgs
|
public sealed class ToolUseAttemptEvent : CancellableEntityEventArgs
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -180,16 +180,27 @@ public abstract partial class SharedToolSystem : EntitySystem
|
|||||||
if (!Resolve(tool, ref toolComponent))
|
if (!Resolve(tool, ref toolComponent))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// check if the tool can do what's required
|
||||||
|
if (!toolComponent.Qualities.ContainsAll(toolQualitiesNeeded))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// check if the user allows using the tool
|
||||||
var ev = new ToolUserAttemptUseEvent(target);
|
var ev = new ToolUserAttemptUseEvent(target);
|
||||||
RaiseLocalEvent(user, ref ev);
|
RaiseLocalEvent(user, ref ev);
|
||||||
if (ev.Cancelled)
|
if (ev.Cancelled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!toolComponent.Qualities.ContainsAll(toolQualitiesNeeded))
|
// check if the tool allows being used
|
||||||
|
var beforeAttempt = new ToolUseAttemptEvent(user);
|
||||||
|
RaiseLocalEvent(tool, beforeAttempt);
|
||||||
|
if (beforeAttempt.Cancelled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var beforeAttempt = new ToolUseAttemptEvent(user);
|
// check if the target allows using the tool
|
||||||
RaiseLocalEvent(tool, beforeAttempt, false);
|
if (target != null && target != tool)
|
||||||
|
{
|
||||||
|
RaiseLocalEvent(target.Value, beforeAttempt);
|
||||||
|
}
|
||||||
|
|
||||||
return !beforeAttempt.Cancelled;
|
return !beforeAttempt.Cancelled;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user