-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add SpawnTableOnUse * make BaseEmitSound more flexible and remove sound from spawntable * add log * --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
- Loading branch information
1 parent
cd23805
commit 2635888
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Content.Server/Storage/Components/SpawnTableOnUseComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Content.Server.Storage.EntitySystems; | ||
using Content.Shared.EntityTable.EntitySelectors; | ||
|
||
namespace Content.Server.Storage.Components; | ||
|
||
/// <summary> | ||
/// Spawns items from an entity table when used in hand. | ||
/// </summary> | ||
[RegisterComponent, Access(typeof(SpawnTableOnUseSystem))] | ||
public sealed partial class SpawnTableOnUseComponent : Component | ||
{ | ||
/// <summary> | ||
/// The entity table to select entities from. | ||
/// </summary> | ||
[DataField(required: true)] | ||
public EntityTableSelector Table = default!; | ||
} |
41 changes: 41 additions & 0 deletions
41
Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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; | ||
|
||
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() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<SpawnTableOnUseComponent, UseInHandEvent>(OnUseInHand); | ||
} | ||
|
||
private void OnUseInHand(Entity<SpawnTableOnUseComponent> 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); | ||
_adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User):user} used {ToPrettyString(ent):spawner} which spawned {ToPrettyString(spawned)}"); | ||
_hands.TryPickupAnyHand(args.User, spawned); | ||
} | ||
|
||
Del(ent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters