Make UtensilSystem and SharpSystem not run AfterInteract if it has already been handled (#25826)

* Make UtensilSystem and SharpSystem not run AfterInteract if it has already been handled

* merge conflicts

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
DrSmugleaf
2024-04-13 20:39:22 -07:00
committed by GitHub
parent 96ad9002f1
commit c67948407e
2 changed files with 18 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
using Content.Server.Body.Systems; using Content.Server.Body.Systems;
using Content.Server.Kitchen.Components; using Content.Server.Kitchen.Components;
using Content.Server.Nutrition.EntitySystems;
using Content.Shared.Body.Components;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.Body.Components; using Content.Shared.Body.Components;
using Content.Shared.Database; using Content.Shared.Database;
@@ -11,9 +13,14 @@ using Content.Shared.Storage;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Content.Shared.Destructible; using Content.Shared.Destructible;
using Content.Shared.DoAfter; using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems; using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Popups;
using Content.Shared.Storage;
using Content.Shared.Verbs;
using Robust.Server.Containers; using Robust.Server.Containers;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -35,7 +42,7 @@ public sealed class SharpSystem : EntitySystem
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<SharpComponent, AfterInteractEvent>(OnAfterInteract, before: new[] { typeof(UtensilSystem) }); SubscribeLocalEvent<SharpComponent, AfterInteractEvent>(OnAfterInteract, before: [typeof(UtensilSystem)]);
SubscribeLocalEvent<SharpComponent, SharpDoAfterEvent>(OnDoAfter); SubscribeLocalEvent<SharpComponent, SharpDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<ButcherableComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs); SubscribeLocalEvent<ButcherableComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
@@ -43,16 +50,14 @@ public sealed class SharpSystem : EntitySystem
private void OnAfterInteract(EntityUid uid, SharpComponent component, AfterInteractEvent args) private void OnAfterInteract(EntityUid uid, SharpComponent component, AfterInteractEvent args)
{ {
if (args.Handled) if (args.Handled || args.Target is null || !args.CanReach)
return; return;
if (args.Target is null || !args.CanReach) if (TryStartButcherDoafter(uid, args.Target.Value, args.User))
return; args.Handled = true;
args.Handled = TryStartButcherDoAfter(uid, args.Target.Value, args.User);
} }
private bool TryStartButcherDoAfter(EntityUid knife, EntityUid target, EntityUid user) private bool TryStartButcherDoafter(EntityUid knife, EntityUid target, EntityUid user)
{ {
if (!TryComp<ButcherableComponent>(target, out var butcher)) if (!TryComp<ButcherableComponent>(target, out var butcher))
return false; return false;
@@ -66,11 +71,11 @@ public sealed class SharpSystem : EntitySystem
if (butcher.Type != ButcheringType.Knife && target != user) if (butcher.Type != ButcheringType.Knife && target != user)
{ {
_popupSystem.PopupEntity(Loc.GetString("butcherable-different-tool", ("target", target)), knife, user); _popupSystem.PopupEntity(Loc.GetString("butcherable-different-tool", ("target", target)), knife, user);
return true; return false;
} }
if (!sharp.Butchering.Add(target)) if (!sharp.Butchering.Add(target))
return true; return false;
var doAfter = var doAfter =
new DoAfterArgs(EntityManager, user, sharp.ButcherDelayModifier * butcher.ButcherDelay, new SharpDoAfterEvent(), knife, target: target, used: knife) new DoAfterArgs(EntityManager, user, sharp.ButcherDelayModifier * butcher.ButcherDelay, new SharpDoAfterEvent(), knife, target: target, used: knife)
@@ -165,7 +170,7 @@ public sealed class SharpSystem : EntitySystem
Act = () => Act = () =>
{ {
if (!disabled) if (!disabled)
TryStartButcherDoAfter(args.Using!.Value, args.Target, args.User); TryStartButcherDoafter(args.Using!.Value, args.Target, args.User);
}, },
Message = message, Message = message,
Disabled = disabled, Disabled = disabled,

View File

@@ -1,12 +1,11 @@
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Server.Nutrition.Components; using Content.Server.Nutrition.Components;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Nutrition.Components;
using Content.Shared.Nutrition.EntitySystems;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems; using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
namespace Content.Server.Nutrition.EntitySystems namespace Content.Server.Nutrition.EntitySystems
@@ -34,10 +33,7 @@ namespace Content.Server.Nutrition.EntitySystems
/// </summary> /// </summary>
private void OnAfterInteract(EntityUid uid, UtensilComponent component, AfterInteractEvent ev) private void OnAfterInteract(EntityUid uid, UtensilComponent component, AfterInteractEvent ev)
{ {
if (ev.Handled) if (ev.Handled || ev.Target == null || !ev.CanReach)
return;
if (ev.Target == null || !ev.CanReach)
return; return;
var result = TryUseUtensil(ev.User, ev.Target.Value, component); var result = TryUseUtensil(ev.User, ev.Target.Value, component);