UseInHandEvent cleanup (#35231)

This commit is contained in:
slarticodefast
2025-02-18 13:27:30 +01:00
committed by GitHub
parent e09ef5aa6f
commit d171057680
9 changed files with 45 additions and 25 deletions

View File

@@ -76,14 +76,13 @@ public sealed class GasAnalyzerSystem : EntitySystem
/// </summary>
private void OnUseInHand(Entity<GasAnalyzerComponent> entity, ref UseInHandEvent args)
{
// Not checking for Handled because ActivatableUISystem already marks it as such.
if (!entity.Comp.Enabled)
{
ActivateAnalyzer(entity, args.User);
}
else
{
DisableAnalyzer(entity, args.User);
}
args.Handled = true;
}

View File

@@ -6,7 +6,6 @@ using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Whitelist;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
@@ -26,6 +25,7 @@ public sealed class RandomGiftSystem : EntitySystem
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
private readonly List<string> _possibleGiftsSafe = new();
private readonly List<string> _possibleGiftsUnsafe = new();
@@ -63,11 +63,16 @@ public sealed class RandomGiftSystem : EntitySystem
if (component.Wrapper is not null)
Spawn(component.Wrapper, coords);
args.Handled = true;
_audio.PlayPvs(component.Sound, args.User);
Del(uid);
// Don't delete the entity in the event bus, so we queue it for deletion.
// We need the free hand for the new item, so we send it to nullspace.
_transform.DetachEntity(uid, Transform(uid));
QueueDel(uid);
_hands.PickupOrDrop(args.User, handsEnt);
args.Handled = true;
}
private void OnGiftMapInit(EntityUid uid, RandomGiftComponent component, MapInitEvent args)

View File

@@ -27,6 +27,9 @@ public sealed class MousetrapSystem : EntitySystem
private void OnUseInHand(EntityUid uid, MousetrapComponent component, UseInHandEvent args)
{
if (args.Handled)
return;
component.IsActive = !component.IsActive;
_popupSystem.PopupEntity(component.IsActive
? Loc.GetString("mousetrap-on-activate")
@@ -35,6 +38,8 @@ public sealed class MousetrapSystem : EntitySystem
args.User);
UpdateVisuals(uid);
args.Handled = true;
}
private void OnStepTriggerAttempt(EntityUid uid, MousetrapComponent component, ref StepTriggerAttemptEvent args)

View File

@@ -37,6 +37,8 @@ public sealed class PAISystem : SharedPAISystem
private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args)
{
// Not checking for Handled because ToggleableGhostRoleSystem already marks it as such.
if (!TryComp<MindContainerComponent>(uid, out var mind) || !mind.HasMind)
component.LastUser = args.User;
}

View File

@@ -4,10 +4,8 @@ using Content.Server.Storage.Components;
using Content.Shared.Database;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction.Events;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Random;
using static Content.Shared.Storage.EntitySpawnCollection;
@@ -20,6 +18,7 @@ namespace Content.Server.Storage.EntitySystems
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly PricingSystem _pricing = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
@@ -80,26 +79,25 @@ namespace Content.Server.Storage.EntitySystems
_adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User)} used {ToPrettyString(uid)} which spawned {ToPrettyString(entityToPlaceInHands.Value)}");
}
// The entity is often deleted, so play the sound at its position rather than parenting
if (component.Sound != null)
{
// The entity is often deleted, so play the sound at its position rather than parenting
var coordinates = Transform(uid).Coordinates;
_audio.PlayPvs(component.Sound, coordinates);
}
_audio.PlayPvs(component.Sound, coords);
component.Uses--;
// Delete entity only if component was successfully used
if (component.Uses <= 0)
{
args.Handled = true;
EntityManager.DeleteEntity(uid);
// Don't delete the entity in the event bus, so we queue it for deletion.
// We need the free hand for the new item, so we send it to nullspace.
_transform.DetachEntity(uid, Transform(uid));
QueueDel(uid);
}
if (entityToPlaceInHands != null)
{
_hands.PickupOrDrop(args.User, entityToPlaceInHands.Value);
}
args.Handled = true;
}
}
}

View File

@@ -12,6 +12,7 @@ public sealed class SpawnTableOnUseSystem : EntitySystem
[Dependency] private readonly EntityTableSystem _entityTable = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
@@ -25,17 +26,21 @@ public sealed class SpawnTableOnUseSystem : EntitySystem
if (args.Handled)
return;
args.Handled = true;
var coords = Transform(ent).Coordinates;
var spawns = _entityTable.GetSpawns(ent.Comp.Table);
// Don't delete the entity in the event bus, so we queue it for deletion.
// We need the free hand for the new item, so we send it to nullspace.
_transform.DetachEntity(ent, Transform(ent));
QueueDel(ent);
foreach (var id in spawns)
{
var spawned = Spawn(id, coords);
_adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User):user} used {ToPrettyString(ent):spawner} which spawned {ToPrettyString(spawned)}");
_hands.TryPickupAnyHand(args.User, spawned);
_hands.PickupOrDrop(args.User, spawned);
}
Del(ent);
args.Handled = true;
}
}

View File

@@ -41,6 +41,9 @@ public sealed class HandTeleporterSystem : EntitySystem
private void OnUseInHand(EntityUid uid, HandTeleporterComponent component, UseInHandEvent args)
{
if (args.Handled)
return;
if (Deleted(component.FirstPortal))
component.FirstPortal = null;
@@ -67,6 +70,8 @@ public sealed class HandTeleporterSystem : EntitySystem
_doafter.TryStartDoAfter(doafterArgs);
}
args.Handled = true;
}

View File

@@ -38,6 +38,8 @@ public abstract partial class SharedGunSystem
private void OnMagazineUse(EntityUid uid, MagazineAmmoProviderComponent component, UseInHandEvent args)
{
// not checking for args.Handled or marking as such because we only relay the event to the magazine entity
var magEnt = GetMagazineEntity(uid);
if (magEnt == null)

View File

@@ -27,11 +27,10 @@ public sealed class WhistleSystem : EntitySystem
public void OnUseInHand(EntityUid uid, WhistleComponent component, UseInHandEvent args)
{
if (!_timing.IsFirstTimePredicted)
if (args.Handled || !_timing.IsFirstTimePredicted)
return;
TryMakeLoudWhistle(uid, args.User, component);
args.Handled = true;
args.Handled = TryMakeLoudWhistle(uid, args.User, component);
}
public bool TryMakeLoudWhistle(EntityUid uid, EntityUid owner, WhistleComponent? component = null)