More DoAfter Changes (#14609)

* DoAfters

* Compact Clone()

* Fix mice and cuffables

* Try generalize attempt events

* moves climbabledoafter event to shared, fixes issue with climbable target

* Fix merge (cuffing)

* Make all events netserializable

* handful of doafter events moved

* moves the rest of the events to their respective shared folders

* Changes all mentions of server doafter to shared

* stop stripping cancellation

* fix merge errors

* draw paused doafters

* handle unpausing

* missing netserializable ref

* removes break on stun reference

* removes cuffing state reference

* Fix tools

* Fix door prying.

* Fix construction

* Fix dumping

* Fix wielding assert

* fix rev

* Fix test

* more test fixes

---------

Co-authored-by: keronshb <keronshb@live.com>
This commit is contained in:
Leon Friedrich
2023-04-03 13:13:48 +12:00
committed by GitHub
parent 9e66fac805
commit 19277a2276
170 changed files with 3042 additions and 2954 deletions

View File

@@ -6,9 +6,6 @@ namespace Content.Server.Tools.Components;
[RegisterComponent]
public sealed class LatticeCuttingComponent : Component
{
[DataField("toolComponentNeeded")]
public bool ToolComponentNeeded = true;
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string QualityNeeded = "Cutting";

View File

@@ -15,8 +15,5 @@ namespace Content.Server.Tools.Components
[DataField("delay")]
public float Delay = 1f;
[DataField("cancelToken")]
public CancellationTokenSource? CancelToken;
}
}

View File

@@ -47,15 +47,9 @@ public sealed class WeldableComponent : SharedWeldableComponent
[ViewVariables(VVAccess.ReadWrite)]
public string? WeldedExamineMessage = "weldable-component-examine-is-welded";
/// <summary>
/// Whether something is currently using a welder on this so DoAfter isn't spammed.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
public bool BeingWelded;
/// <summary>
/// Is this entity currently welded shut?
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[DataField("isWelded")]
public bool IsWelded;
}

View File

@@ -1,10 +1,12 @@
using Content.Server.Administration.Logs;
using Content.Server.Tools.Components;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using Content.Shared.Tools.Systems;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
@@ -22,7 +24,6 @@ public sealed class WeldableSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<WeldableComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<WeldableComponent, WeldFinishedEvent>(OnWeldFinished);
SubscribeLocalEvent<WeldableComponent, WeldCancelledEvent>(OnWeldCanceled);
SubscribeLocalEvent<LayerChangeOnWeldComponent, WeldableChangedEvent>(OnWeldChanged);
SubscribeLocalEvent<WeldableComponent, ExaminedEvent>(OnExamine);
}
@@ -47,9 +48,7 @@ public sealed class WeldableSystem : EntitySystem
return false;
// Basic checks
if (!component.Weldable || component.BeingWelded)
return false;
if (!_toolSystem.HasQuality(tool, component.WeldingQuality))
if (!component.Weldable)
return false;
// Other component systems
@@ -69,8 +68,8 @@ public sealed class WeldableSystem : EntitySystem
if (!CanWeld(uid, tool, user, component))
return false;
var toolEvData = new ToolEventData(new WeldFinishedEvent(user, tool), cancelledEv: new WeldCancelledEvent(),targetEntity: uid);
component.BeingWelded = _toolSystem.UseTool(tool, user, uid, component.WeldingTime.Seconds, new[] { component.WeldingQuality }, toolEvData, fuel: component.FuelConsumption);
if (!_toolSystem.UseTool(tool, user, uid, component.WeldingTime.Seconds, component.WeldingQuality, new WeldFinishedEvent(), fuel: component.FuelConsumption))
return false;
// Log attempt
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(user):user} is {(component.IsWelded ? "un" : "")}welding {ToPrettyString(uid):target} at {Transform(uid).Coordinates:targetlocation}");
@@ -80,10 +79,11 @@ public sealed class WeldableSystem : EntitySystem
private void OnWeldFinished(EntityUid uid, WeldableComponent component, WeldFinishedEvent args)
{
component.BeingWelded = false;
if (args.Cancelled || args.Used == null)
return;
// Check if target is still valid
if (!CanWeld(uid, args.Tool, args.User, component))
if (!CanWeld(uid, args.Used.Value, args.User, component))
return;
component.IsWelded = !component.IsWelded;
@@ -95,11 +95,6 @@ public sealed class WeldableSystem : EntitySystem
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} {(!component.IsWelded ? "un" : "")}welded {ToPrettyString(uid):target}");
}
private void OnWeldCanceled(EntityUid uid, WeldableComponent component, WeldCancelledEvent args)
{
component.BeingWelded = false;
}
private void OnWeldChanged(EntityUid uid, LayerChangeOnWeldComponent component, WeldableChangedEvent args)
{
if (!TryComp<FixturesComponent>(uid, out var fixtures))
@@ -148,30 +143,6 @@ public sealed class WeldableSystem : EntitySystem
return;
component.WeldingTime = time;
}
/// <summary>
/// Raised after welding do_after has finished. It doesn't guarantee success,
/// use <see cref="WeldableChangedEvent"/> to get updated status.
/// </summary>
private sealed class WeldFinishedEvent : EntityEventArgs
{
public readonly EntityUid User;
public readonly EntityUid Tool;
public WeldFinishedEvent(EntityUid user, EntityUid tool)
{
User = user;
Tool = tool;
}
}
/// <summary>
/// Raised when entity welding has failed.
/// </summary>
private sealed class WeldCancelledEvent : EntityEventArgs
{
}
}
/// <summary>

View File

@@ -2,6 +2,7 @@
using Content.Server.Maps;
using Content.Server.Tools.Components;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Tools.Components;
@@ -22,6 +23,9 @@ public sealed partial class ToolSystem
private void OnLatticeCutComplete(EntityUid uid, LatticeCuttingComponent component, LatticeCuttingCompleteEvent args)
{
if (args.Cancelled)
return;
var gridUid = args.Coordinates.GetGridUid(EntityManager);
if (gridUid == null)
return;
@@ -50,10 +54,6 @@ public sealed partial class ToolSystem
private bool TryCut(EntityUid toolEntity, EntityUid user, LatticeCuttingComponent component, EntityCoordinates clickLocation)
{
ToolComponent? tool = null;
if (component.ToolComponentNeeded && !TryComp<ToolComponent?>(toolEntity, out tool))
return false;
if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid))
return false;
@@ -71,24 +71,8 @@ public sealed partial class ToolSystem
|| tile.IsBlockedTurf(true))
return false;
var toolEvData = new ToolEventData(new LatticeCuttingCompleteEvent(clickLocation, user), targetEntity: toolEntity);
if (!UseTool(toolEntity, user, null, component.Delay, new[] {component.QualityNeeded}, toolEvData, toolComponent: tool))
return false;
return true;
}
private sealed class LatticeCuttingCompleteEvent : EntityEventArgs
{
public EntityCoordinates Coordinates;
public EntityUid User;
public LatticeCuttingCompleteEvent(EntityCoordinates coordinates, EntityUid user)
{
Coordinates = coordinates;
User = user;
}
var ev = new LatticeCuttingCompleteEvent(clickLocation);
return UseTool(toolEntity, user, toolEntity, component.Delay, component.QualityNeeded, ev);
}
}

View File

@@ -1,6 +1,7 @@
using System.Threading;
using Content.Server.Fluids.Components;
using Content.Server.Tools.Components;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Tools.Components;
@@ -18,8 +19,7 @@ public sealed partial class ToolSystem
private void InitializeTilePrying()
{
SubscribeLocalEvent<TilePryingComponent, AfterInteractEvent>(OnTilePryingAfterInteract);
SubscribeLocalEvent<TilePryingComponent, TilePryingCompleteEvent>(OnTilePryComplete);
SubscribeLocalEvent<TilePryingComponent, TilePryingCancelledEvent>(OnTilePryCancelled);
SubscribeLocalEvent<TilePryingComponent, TilePryingDoAfterEvent>(OnTilePryComplete);
}
private void OnTilePryingAfterInteract(EntityUid uid, TilePryingComponent component, AfterInteractEvent args)
@@ -30,9 +30,11 @@ public sealed partial class ToolSystem
args.Handled = true;
}
private void OnTilePryComplete(EntityUid uid, TilePryingComponent component, TilePryingCompleteEvent args)
private void OnTilePryComplete(EntityUid uid, TilePryingComponent component, TilePryingDoAfterEvent args)
{
component.CancelToken = null;
if (args.Cancelled)
return;
var gridUid = args.Coordinates.GetGridUid(EntityManager);
if (!_mapManager.TryGetGrid(gridUid, out var grid))
{
@@ -44,14 +46,9 @@ public sealed partial class ToolSystem
_tile.PryTile(tile);
}
private void OnTilePryCancelled(EntityUid uid, TilePryingComponent component, TilePryingCancelledEvent args)
{
component.CancelToken = null;
}
private bool TryPryTile(EntityUid toolEntity, EntityUid user, TilePryingComponent component, EntityCoordinates clickLocation)
{
if (!TryComp<ToolComponent?>(toolEntity, out var tool) && component.ToolComponentNeeded || component.CancelToken != null)
if (!TryComp<ToolComponent?>(toolEntity, out var tool) && component.ToolComponentNeeded)
return false;
if (!_mapManager.TryGetGrid(clickLocation.GetGridUid(EntityManager), out var mapGrid))
@@ -69,28 +66,8 @@ public sealed partial class ToolSystem
if (!tileDef.CanCrowbar)
return false;
component.CancelToken = new CancellationTokenSource();
var toolEvData = new ToolEventData(new TilePryingCompleteEvent(clickLocation), cancelledEv:new TilePryingCancelledEvent() ,targetEntity:toolEntity);
if (!UseTool(toolEntity, user, null, component.Delay, new[] { component.QualityNeeded }, toolEvData, toolComponent: tool, cancelToken: component.CancelToken))
return false;
return true;
}
private sealed class TilePryingCompleteEvent : EntityEventArgs
{
public readonly EntityCoordinates Coordinates;
public TilePryingCompleteEvent(EntityCoordinates coordinates)
{
Coordinates = coordinates;
}
}
private sealed class TilePryingCancelledEvent : EntityEventArgs
{
var ev = new TilePryingDoAfterEvent(clickLocation);
return UseTool(toolEntity, user, toolEntity, component.Delay, component.QualityNeeded, ev, toolComponent: tool);
}
}

View File

@@ -4,6 +4,7 @@ using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Tools.Components;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
@@ -15,6 +16,7 @@ using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
namespace Content.Server.Tools
{
@@ -38,8 +40,8 @@ namespace Content.Server.Tools
SubscribeLocalEvent<WelderComponent, SolutionChangedEvent>(OnWelderSolutionChange);
SubscribeLocalEvent<WelderComponent, ActivateInWorldEvent>(OnWelderActivate);
SubscribeLocalEvent<WelderComponent, AfterInteractEvent>(OnWelderAfterInteract);
SubscribeLocalEvent<WelderComponent, ToolUseAttemptEvent>(OnWelderToolUseAttempt);
SubscribeLocalEvent<WelderComponent, ToolUseFinishAttemptEvent>(OnWelderToolUseFinishAttempt);
SubscribeLocalEvent<WelderComponent, DoAfterAttemptEvent<ToolDoAfterEvent>>(OnWelderToolUseAttempt);
SubscribeLocalEvent<WelderComponent, ToolDoAfterEvent>(OnWelderDoAfter);
SubscribeLocalEvent<WelderComponent, ComponentShutdown>(OnWelderShutdown);
SubscribeLocalEvent<WelderComponent, ComponentGetState>(OnWelderGetState);
SubscribeLocalEvent<WelderComponent, MeleeHitEvent>(OnMeleeHit);
@@ -262,56 +264,36 @@ namespace Content.Server.Tools
args.Handled = true;
}
private void OnWelderToolUseAttempt(EntityUid uid, WelderComponent welder, ToolUseAttemptEvent args)
private void OnWelderToolUseAttempt(EntityUid uid, WelderComponent welder, DoAfterAttemptEvent<ToolDoAfterEvent> args)
{
if (args.Cancelled)
return;
DebugTools.Assert(args.Event.Fuel > 0);
var user = args.DoAfter.Args.User;
if (!welder.Lit)
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-welder-not-lit-message"), uid, args.User);
_popupSystem.PopupEntity(Loc.GetString("welder-component-welder-not-lit-message"), uid, user);
args.Cancel();
return;
}
var (fuel, _) = GetWelderFuelAndCapacity(uid, welder);
if (FixedPoint2.New(args.Fuel) > fuel)
if (FixedPoint2.New(args.Event.Fuel) > fuel)
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-cannot-weld-message"), uid, args.User);
_popupSystem.PopupEntity(Loc.GetString("welder-component-cannot-weld-message"), uid, user);
args.Cancel();
}
}
private void OnWelderToolUseFinishAttempt(EntityUid uid, WelderComponent welder, ToolUseFinishAttemptEvent args)
private void OnWelderDoAfter(EntityUid uid, WelderComponent welder, ToolDoAfterEvent args)
{
if (args.Cancelled)
return;
if (!welder.Lit)
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-welder-not-lit-message"), uid, args.User);
args.Cancel();
return;
}
var (fuel, _) = GetWelderFuelAndCapacity(uid, welder);
var neededFuel = FixedPoint2.New(args.Fuel);
if (neededFuel > fuel)
{
_popupSystem.PopupEntity(Loc.GetString("welder-component-cannot-weld-message"), uid, args.User);
args.Cancel();
}
if (!_solutionContainerSystem.TryGetSolution(uid, welder.FuelSolution, out var solution))
{
args.Cancel();
return;
}
solution.RemoveReagent(welder.FuelReagent, neededFuel);
solution.RemoveReagent(welder.FuelReagent, FixedPoint2.New(args.Fuel));
_entityManager.Dirty(welder);
}