Sync UseTool nullable broadcast events

This commit is contained in:
Vera Aguilera Puerto
2021-10-30 19:27:06 +02:00
parent f14c3c4aed
commit 3cd88b8cf2

View File

@@ -40,7 +40,10 @@ namespace Content.Server.Tools
private void OnDoAfterComplete(ToolDoAfterComplete ev) private void OnDoAfterComplete(ToolDoAfterComplete ev)
{ {
// Actually finish the tool use! Depending on whether that succeeds or not, either event will be broadcast. // Actually finish the tool use! Depending on whether that succeeds or not, either event will be broadcast.
RaiseLocalEvent(ToolFinishUse(ev.Uid, ev.UserUid, ev.Fuel) ? ev.CompletedEvent : ev.CancelledEvent); if(ToolFinishUse(ev.Uid, ev.UserUid, ev.Fuel))
RaiseLocalEvent(ev.CompletedEvent);
else if(ev.CancelledEvent != null)
RaiseLocalEvent(ev.CancelledEvent);
} }
private void OnDoAfterCancelled(ToolDoAfterCancelled ev) private void OnDoAfterCancelled(ToolDoAfterCancelled ev)
@@ -83,7 +86,8 @@ namespace Content.Server.Tools
/// to see whether using the tool succeeded or not. If the <see cref="doAfterDelay"/> is zero, /// to see whether using the tool succeeded or not. If the <see cref="doAfterDelay"/> is zero,
/// this simply returns whether using the tool succeeded or not.</returns> /// this simply returns whether using the tool succeeded or not.</returns>
public bool UseTool(EntityUid tool, EntityUid user, EntityUid? target, float fuel, public bool UseTool(EntityUid tool, EntityUid user, EntityUid? target, float fuel,
float doAfterDelay, IEnumerable<string> toolQualitiesNeeded, object doAfterCompleteEvent, object doAfterCancelledEvent, float doAfterDelay, IEnumerable<string> toolQualitiesNeeded,
object? doAfterCompleteEvent = null, object? doAfterCancelledEvent = null,
Func<bool>? doAfterCheck = null, ToolComponent? toolComponent = null) Func<bool>? doAfterCheck = null, ToolComponent? toolComponent = null)
{ {
// No logging here, after all that'd mean the caller would need to check if the component is there or not. // No logging here, after all that'd mean the caller would need to check if the component is there or not.
@@ -103,8 +107,8 @@ namespace Content.Server.Tools
BreakOnTargetMove = true, BreakOnTargetMove = true,
BreakOnUserMove = true, BreakOnUserMove = true,
NeedHand = true, NeedHand = true,
BroadcastFinishedEvent = new ToolDoAfterComplete(doAfterCompleteEvent, doAfterCancelledEvent, tool, user, fuel), BroadcastFinishedEvent = doAfterCompleteEvent != null ? new ToolDoAfterComplete(doAfterCompleteEvent, doAfterCancelledEvent, tool, user, fuel) : null,
BroadcastCancelledEvent = new ToolDoAfterCancelled(doAfterCancelledEvent), BroadcastCancelledEvent = doAfterCancelledEvent != null ? new ToolDoAfterCancelled(doAfterCancelledEvent) : null,
}; };
_doAfterSystem.DoAfter(doAfterArgs); _doAfterSystem.DoAfter(doAfterArgs);
@@ -231,12 +235,12 @@ namespace Content.Server.Tools
private class ToolDoAfterComplete : EntityEventArgs private class ToolDoAfterComplete : EntityEventArgs
{ {
public readonly object CompletedEvent; public readonly object CompletedEvent;
public readonly object CancelledEvent; public readonly object? CancelledEvent;
public readonly EntityUid Uid; public readonly EntityUid Uid;
public readonly EntityUid UserUid; public readonly EntityUid UserUid;
public readonly float Fuel; public readonly float Fuel;
public ToolDoAfterComplete(object completedEvent, object cancelledEvent, EntityUid uid, EntityUid userUid, float fuel) public ToolDoAfterComplete(object completedEvent, object? cancelledEvent, EntityUid uid, EntityUid userUid, float fuel)
{ {
CompletedEvent = completedEvent; CompletedEvent = completedEvent;
Uid = uid; Uid = uid;