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:
deltanedas
2023-09-05 17:20:54 +01:00
committed by GitHub
parent ce54689e0c
commit a096e5be7e
3 changed files with 27 additions and 4 deletions

View File

@@ -180,16 +180,27 @@ public abstract partial class SharedToolSystem : EntitySystem
if (!Resolve(tool, ref toolComponent))
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);
RaiseLocalEvent(user, ref ev);
if (ev.Cancelled)
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;
var beforeAttempt = new ToolUseAttemptEvent(user);
RaiseLocalEvent(tool, beforeAttempt, false);
// check if the target allows using the tool
if (target != null && target != tool)
{
RaiseLocalEvent(target.Value, beforeAttempt);
}
return !beforeAttempt.Cancelled;
}