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

@@ -1,14 +1,13 @@
using Content.Server.Administration.Logs;
using Content.Server.DoAfter;
using Content.Server.Kitchen.Components;
using Content.Server.Nutrition.Components;
using Content.Server.Popups;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.DragDrop;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Nutrition.Components;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Content.Shared.Storage;
using Robust.Shared.Random;
@@ -18,7 +17,6 @@ using Content.Shared.Kitchen;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
namespace Content.Server.Kitchen.EntitySystems
{
@@ -30,6 +28,7 @@ namespace Content.Server.Kitchen.EntitySystems
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
@@ -40,8 +39,7 @@ namespace Content.Server.Kitchen.EntitySystems
SubscribeLocalEvent<KitchenSpikeComponent, DragDropTargetEvent>(OnDragDrop);
//DoAfter
SubscribeLocalEvent<KitchenSpikeComponent, SpikingFinishedEvent>(OnSpikingFinished);
SubscribeLocalEvent<KitchenSpikeComponent, SpikingFailEvent>(OnSpikingFail);
SubscribeLocalEvent<KitchenSpikeComponent, DoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<KitchenSpikeComponent, SuicideEvent>(OnSuicide);
@@ -56,35 +54,32 @@ namespace Content.Server.Kitchen.EntitySystems
private void OnSuicide(EntityUid uid, KitchenSpikeComponent component, SuicideEvent args)
{
if (args.Handled) return;
if (args.Handled)
return;
args.SetHandled(SuicideKind.Piercing);
var victim = args.Victim;
var othersMessage = Loc.GetString("comp-kitchen-spike-suicide-other", ("victim", victim));
victim.PopupMessageOtherClients(othersMessage);
_popupSystem.PopupEntity(othersMessage, victim);
var selfMessage = Loc.GetString("comp-kitchen-spike-suicide-self");
victim.PopupMessage(selfMessage);
_popupSystem.PopupEntity(selfMessage, victim, victim);
}
private void OnSpikingFail(EntityUid uid, KitchenSpikeComponent component, SpikingFailEvent args)
private void OnDoAfter(EntityUid uid, KitchenSpikeComponent component, DoAfterEvent args)
{
component.InUse = false;
if (args.Args.Target == null)
return;
if (EntityManager.TryGetComponent<ButcherableComponent>(args.VictimUid, out var butcherable))
butcherable.BeingButchered = false;
}
private void OnSpikingFinished(EntityUid uid, KitchenSpikeComponent component, SpikingFinishedEvent args)
{
component.InUse = false;
if (EntityManager.TryGetComponent<ButcherableComponent>(args.VictimUid, out var butcherable))
if (TryComp<ButcherableComponent>(args.Args.Target.Value, out var butcherable))
butcherable.BeingButchered = false;
if (Spikeable(uid, args.UserUid, args.VictimUid, component, butcherable))
{
Spike(uid, args.UserUid, args.VictimUid, component);
}
if (args.Handled || args.Cancelled)
return;
if (Spikeable(uid, args.Args.User, args.Args.Target.Value, component, butcherable))
Spike(uid, args.Args.User, args.Args.Target.Value, component);
args.Handled = true;
}
private void OnDragDrop(EntityUid uid, KitchenSpikeComponent component, ref DragDropTargetEvent args)
@@ -96,8 +91,8 @@ namespace Content.Server.Kitchen.EntitySystems
if (Spikeable(uid, args.User, args.Dragged, component))
TrySpike(uid, args.User, args.Dragged, component);
}
private void OnInteractHand(EntityUid uid, KitchenSpikeComponent component, InteractHandEvent args)
{
if (args.Handled)
@@ -142,7 +137,7 @@ namespace Content.Server.Kitchen.EntitySystems
// TODO: Need to be able to leave them on the spike to do DoT, see ss13.
EntityManager.QueueDeleteEntity(victimUid);
SoundSystem.Play(component.SpikeSound.GetSound(), Filter.Pvs(uid), uid);
_audio.Play(component.SpikeSound, Filter.Pvs(uid), uid, true);
}
private bool TryGetPiece(EntityUid uid, EntityUid user, EntityUid used,
@@ -164,9 +159,7 @@ namespace Content.Server.Kitchen.EntitySystems
Loc.GetString("comp-kitchen-spike-meat-name", ("name", Name(ent)), ("victim", component.Victim));
if (component.PrototypesToSpawn.Count != 0)
{
_popupSystem.PopupEntity(component.MeatSource1p, uid, user, PopupType.MediumCaution);
}
else
{
UpdateAppearance(uid, null, component);
@@ -243,42 +236,18 @@ namespace Content.Server.Kitchen.EntitySystems
butcherable.BeingButchered = true;
component.InUse = true;
var doAfterArgs = new DoAfterEventArgs(userUid, component.SpikeDelay + butcherable.ButcherDelay, default, uid)
var doAfterArgs = new DoAfterEventArgs(userUid, component.SpikeDelay + butcherable.ButcherDelay, target:victimUid, used:uid)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnStun = true,
NeedHand = true,
TargetFinishedEvent = new SpikingFinishedEvent(userUid, victimUid),
TargetCancelledEvent = new SpikingFailEvent(victimUid)
NeedHand = true
};
_doAfter.DoAfter(doAfterArgs);
return true;
}
private sealed class SpikingFinishedEvent : EntityEventArgs
{
public EntityUid VictimUid;
public EntityUid UserUid;
public SpikingFinishedEvent(EntityUid userUid, EntityUid victimUid)
{
UserUid = userUid;
VictimUid = victimUid;
}
}
private sealed class SpikingFailEvent : EntityEventArgs
{
public EntityUid VictimUid;
public SpikingFailEvent(EntityUid victimUid)
{
VictimUid = victimUid;
}
}
}
}