From 3bb444f21bda4b81a964a37f132f78fa07d6d329 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Thu, 3 Oct 2024 18:40:18 +0100
Subject: [PATCH 1/4] add SpawnTableOnUse
---
.../Components/SpawnTableOnUseComponent.cs | 24 +++++++++++
.../EntitySystems/SpawnTableOnUseSystem.cs | 41 +++++++++++++++++++
2 files changed, 65 insertions(+)
create mode 100644 Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
create mode 100644 Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
diff --git a/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs b/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
new file mode 100644
index 000000000000..3455c54ff487
--- /dev/null
+++ b/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
@@ -0,0 +1,24 @@
+using Content.Server.Storage.EntitySystems;
+using Content.Shared.EntityTable.EntitySelectors;
+using Robust.Shared.Audio;
+
+namespace Content.Server.Storage.Components;
+
+///
+/// Spawns items from an entity table when used in hand.
+///
+[RegisterComponent, Access(typeof(SpawnTableOnUseSystem))]
+public sealed partial class SpawnTableOnUseComponent : Component
+{
+ ///
+ /// The entity table to select entities from.
+ ///
+ [DataField(required: true)]
+ public EntityTableSelector Table = default!;
+
+ ///
+ /// A sound to play when the items are spawned. For example, gift boxes being unwrapped.
+ ///
+ [DataField]
+ public SoundSpecifier? Sound;
+}
diff --git a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
new file mode 100644
index 000000000000..67381b82683f
--- /dev/null
+++ b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
@@ -0,0 +1,41 @@
+using Content.Server.Administration.Logs;
+using Content.Server.Storage.Components;
+using Content.Shared.EntityTable;
+using Content.Shared.Hands.EntitySystems;
+using Content.Shared.Interaction.Events;
+using Robust.Shared.Audio.Systems;
+
+namespace Content.Server.Storage.EntitySystems;
+
+public sealed class SpawnTableOnUseSystem : EntitySystem
+{
+ [Dependency] private readonly EntityTableSystem _entityTable = default!;
+ [Dependency] private readonly SharedAudioSystem _audio = default!;
+ [Dependency] private readonly SharedHandsSystem _hands = default!;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ SubscribeLocalEvent(OnUseInHand);
+ }
+
+ private void OnUseInHand(Entity ent, ref UseInHandEvent args)
+ {
+ if (args.Handled)
+ return;
+
+ args.Handled = true;
+
+ var coords = Transform(ent).Coordinates;
+ var spawns = _entityTable.GetSpawns(ent.Comp.Table);
+ foreach (var id in spawns)
+ {
+ var spawned = Spawn(id, coords);
+ _hands.TryPickupAnyHand(args.User, spawned);
+ }
+
+ _audio.PlayPvs(ent.Comp.Sound, coords);
+ Del(ent);
+ }
+}
From fec862d68a7d2b4956b024e0e7c63a738611aa67 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Fri, 11 Oct 2024 19:18:33 +0100
Subject: [PATCH 2/4] make BaseEmitSound more flexible and remove sound from
spawntable
---
.../Components/SpawnTableOnUseComponent.cs | 7 -------
.../EntitySystems/SpawnTableOnUseSystem.cs | 3 ---
.../Sound/Components/BaseEmitSoundComponent.cs | 7 +++++++
Content.Shared/Sound/SharedEmitSoundSystem.cs | 18 +++++++++++++-----
4 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs b/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
index 3455c54ff487..a7cbac725439 100644
--- a/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
+++ b/Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
@@ -1,6 +1,5 @@
using Content.Server.Storage.EntitySystems;
using Content.Shared.EntityTable.EntitySelectors;
-using Robust.Shared.Audio;
namespace Content.Server.Storage.Components;
@@ -15,10 +14,4 @@ public sealed partial class SpawnTableOnUseComponent : Component
///
[DataField(required: true)]
public EntityTableSelector Table = default!;
-
- ///
- /// A sound to play when the items are spawned. For example, gift boxes being unwrapped.
- ///
- [DataField]
- public SoundSpecifier? Sound;
}
diff --git a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
index 67381b82683f..4bfdd55cf05b 100644
--- a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
+++ b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
@@ -3,14 +3,12 @@
using Content.Shared.EntityTable;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction.Events;
-using Robust.Shared.Audio.Systems;
namespace Content.Server.Storage.EntitySystems;
public sealed class SpawnTableOnUseSystem : EntitySystem
{
[Dependency] private readonly EntityTableSystem _entityTable = default!;
- [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
public override void Initialize()
@@ -35,7 +33,6 @@ private void OnUseInHand(Entity ent, ref UseInHandEven
_hands.TryPickupAnyHand(args.User, spawned);
}
- _audio.PlayPvs(ent.Comp.Sound, coords);
Del(ent);
}
}
diff --git a/Content.Shared/Sound/Components/BaseEmitSoundComponent.cs b/Content.Shared/Sound/Components/BaseEmitSoundComponent.cs
index 4e6ebb23d216..870d20457ef7 100644
--- a/Content.Shared/Sound/Components/BaseEmitSoundComponent.cs
+++ b/Content.Shared/Sound/Components/BaseEmitSoundComponent.cs
@@ -14,4 +14,11 @@ public abstract partial class BaseEmitSoundComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField(required: true)]
public SoundSpecifier? Sound;
+
+ ///
+ /// Play the sound at the position instead of parented to the source entity.
+ /// Useful if the entity is deleted after.
+ ///
+ [DataField]
+ public bool Positional;
}
diff --git a/Content.Shared/Sound/SharedEmitSoundSystem.cs b/Content.Shared/Sound/SharedEmitSoundSystem.cs
index 8040910dc3c7..82e908783d1b 100644
--- a/Content.Shared/Sound/SharedEmitSoundSystem.cs
+++ b/Content.Shared/Sound/SharedEmitSoundSystem.cs
@@ -142,14 +142,22 @@ protected void TryEmitSound(EntityUid uid, BaseEmitSoundComponent component, Ent
if (component.Sound == null)
return;
- if (predict)
+ if (component.Positional)
{
- _audioSystem.PlayPredicted(component.Sound, uid, user);
+ var coords = Transform(uid).Coordinates;
+ if (predict)
+ _audioSystem.PlayPredicted(component.Sound, coords, user);
+ else if (_netMan.IsServer)
+ // don't predict sounds that client couldn't have played already
+ _audioSystem.PlayPvs(component.Sound, coords);
}
- else if (_netMan.IsServer)
+ else
{
- // don't predict sounds that client couldn't have played already
- _audioSystem.PlayPvs(component.Sound, uid);
+ if (predict)
+ _audioSystem.PlayPredicted(component.Sound, uid, user);
+ else if (_netMan.IsServer)
+ // don't predict sounds that client couldn't have played already
+ _audioSystem.PlayPvs(component.Sound, uid);
}
}
From a4f20f0d84eacbaea65257de9b515b8a81608bd2 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Wed, 27 Nov 2024 07:07:31 +0000
Subject: [PATCH 3/4] add log
---
Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
index 4bfdd55cf05b..d2162b12bb84 100644
--- a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
+++ b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
@@ -9,6 +9,7 @@ namespace Content.Server.Storage.EntitySystems;
public sealed class SpawnTableOnUseSystem : EntitySystem
{
[Dependency] private readonly EntityTableSystem _entityTable = default!;
+ [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
public override void Initialize()
@@ -30,6 +31,7 @@ private void OnUseInHand(Entity ent, ref UseInHandEven
foreach (var id in spawns)
{
var spawned = Spawn(id, coords);
+ _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User)} used {ToPrettyString(uid)} which spawned {ToPrettyString(spawned)}");
_hands.TryPickupAnyHand(args.User, spawned);
}
From b9a7a5fa564708e5a0915fa8b377f631e3b7c7a1 Mon Sep 17 00:00:00 2001
From: deltanedas <@deltanedas:kde.org>
Date: Thu, 12 Dec 2024 00:44:01 +0000
Subject: [PATCH 4/4] :trollface:
---
Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
index d2162b12bb84..96556ed7b256 100644
--- a/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
+++ b/Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
@@ -1,5 +1,6 @@
using Content.Server.Administration.Logs;
using Content.Server.Storage.Components;
+using Content.Shared.Database;
using Content.Shared.EntityTable;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction.Events;
@@ -31,7 +32,7 @@ private void OnUseInHand(Entity ent, ref UseInHandEven
foreach (var id in spawns)
{
var spawned = Spawn(id, coords);
- _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User)} used {ToPrettyString(uid)} which spawned {ToPrettyString(spawned)}");
+ _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User):user} used {ToPrettyString(ent):spawner} which spawned {ToPrettyString(spawned)}");
_hands.TryPickupAnyHand(args.User, spawned);
}