DoAfter Refactor (#13225)

Co-authored-by: DrSmugleaf <drsmugleaf@gmail.com>
This commit is contained in:
keronshb
2023-02-24 19:01:25 -05:00
committed by GitHub
parent 7a9baa79c2
commit 9ebb452a3c
129 changed files with 2624 additions and 4132 deletions

View File

@@ -21,7 +21,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using System.Threading;
using Content.Shared.DoAfter;
namespace Content.Server.Light.EntitySystems
{
@@ -40,6 +40,7 @@ namespace Content.Server.Light.EntitySystems
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
private static readonly TimeSpan ThunkDelay = TimeSpan.FromSeconds(2);
@@ -61,8 +62,7 @@ namespace Content.Server.Light.EntitySystems
SubscribeLocalEvent<PoweredLightComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<PoweredLightComponent, EjectBulbCompleteEvent>(OnEjectBulbComplete);
SubscribeLocalEvent<PoweredLightComponent, EjectBulbCancelledEvent>(OnEjectBulbCancelled);
SubscribeLocalEvent<PoweredLightComponent, DoAfterEvent>(OnDoAfter);
}
private void OnInit(EntityUid uid, PoweredLightComponent light, ComponentInit args)
@@ -95,9 +95,6 @@ namespace Content.Server.Light.EntitySystems
if (args.Handled)
return;
if (light.CancelToken != null)
return;
// check if light has bulb to eject
var bulbUid = GetBulb(uid, light);
if (bulbUid == null)
@@ -122,10 +119,9 @@ namespace Content.Server.Light.EntitySystems
var damage = _damageableSystem.TryChangeDamage(userUid, light.Damage, origin: userUid);
if (damage != null)
_adminLogger.Add(LogType.Damaged,
$"{ToPrettyString(args.User):user} burned their hand on {ToPrettyString(args.Target):target} and received {damage.Total:damage} damage");
_adminLogger.Add(LogType.Damaged, $"{ToPrettyString(args.User):user} burned their hand on {ToPrettyString(args.Target):target} and received {damage.Total:damage} damage");
SoundSystem.Play(light.BurnHandSound.GetSound(), Filter.Pvs(uid), uid);
_audio.Play(light.BurnHandSound, Filter.Pvs(uid), uid, true);
args.Handled = true;
return;
@@ -141,22 +137,11 @@ namespace Content.Server.Light.EntitySystems
}
// removing a working bulb, so require a delay
light.CancelToken = new CancellationTokenSource();
_doAfterSystem.DoAfter(new DoAfterEventArgs(userUid, light.EjectBulbDelay, light.CancelToken.Token, uid)
_doAfterSystem.DoAfter(new DoAfterEventArgs(userUid, light.EjectBulbDelay, target:uid)
{
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnStun = true,
TargetFinishedEvent = new EjectBulbCompleteEvent()
{
Component = light,
User = userUid,
Target = uid,
},
TargetCancelledEvent = new EjectBulbCancelledEvent()
{
Component = light,
}
BreakOnStun = true
});
args.Handled = true;
@@ -287,7 +272,7 @@ namespace Content.Server.Light.EntitySystems
if (time > light.LastThunk + ThunkDelay)
{
light.LastThunk = time;
SoundSystem.Play(light.TurnOnSound.GetSound(), Filter.Pvs(uid), uid, AudioParams.Default.WithVolume(-10f));
_audio.Play(light.TurnOnSound, Filter.Pvs(uid), uid, true, AudioParams.Default.WithVolume(-10f));
}
}
else
@@ -358,7 +343,7 @@ namespace Content.Server.Light.EntitySystems
light.IsBlinking = isNowBlinking;
if (!EntityManager.TryGetComponent(light.Owner, out AppearanceComponent? appearance))
if (!EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
return;
_appearance.SetData(uid, PoweredLightVisuals.Blinking, isNowBlinking, appearance);
@@ -427,27 +412,14 @@ namespace Content.Server.Light.EntitySystems
UpdateLight(uid, light);
}
private void OnEjectBulbComplete(EntityUid uid, PoweredLightComponent component, EjectBulbCompleteEvent args)
private void OnDoAfter(EntityUid uid, PoweredLightComponent component, DoAfterEvent args)
{
args.Component.CancelToken = null;
EjectBulb(args.Target, args.User, args.Component);
}
if (args.Handled || args.Cancelled || args.Args.Target == null)
return;
private static void OnEjectBulbCancelled(EntityUid uid, PoweredLightComponent component, EjectBulbCancelledEvent args)
{
args.Component.CancelToken = null;
}
EjectBulb(args.Args.Target.Value, args.Args.User, component);
private sealed class EjectBulbCompleteEvent : EntityEventArgs
{
public PoweredLightComponent Component { get; init; } = default!;
public EntityUid User { get; init; }
public EntityUid Target { get; init; }
}
private sealed class EjectBulbCancelledEvent : EntityEventArgs
{
public PoweredLightComponent Component { get; init; } = default!;
args.Handled = true;
}
}
}