Files
crystall-punk-14/Content.Server/Materials/MaterialStorageSystem.cs

60 lines
2.3 KiB
C#
Raw Normal View History

using Content.Server.Administration.Logs;
using Content.Shared.Materials;
using Content.Shared.Popups;
2023-01-07 13:09:05 -05:00
using Content.Shared.Stacks;
using Content.Server.Power.Components;
2023-01-07 13:09:05 -05:00
using Content.Server.Construction.Components;
using Content.Server.Stack;
using Content.Shared.Database;
namespace Content.Server.Materials;
/// <summary>
/// This handles <see cref="SharedMaterialStorageSystem"/>
/// </summary>
public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
2023-01-07 13:09:05 -05:00
[Dependency] private readonly StackSystem _stackSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MaterialStorageComponent, MachineDeconstructedEvent>(OnDeconstructed);
}
private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args)
{
2023-01-08 11:36:32 +13:00
if (!component.DropOnDeconstruct)
return;
2023-01-07 13:09:05 -05:00
foreach (var (material, amount) in component.Storage)
{
_stackSystem.SpawnMultipleFromMaterial(amount, material, Transform(uid).Coordinates);
}
}
2022-10-09 14:16:10 -04:00
public override bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, MaterialStorageComponent? component = null)
{
2022-10-09 14:16:10 -04:00
if (!Resolve(receiver, ref component))
return false;
if (TryComp<ApcPowerReceiverComponent>(receiver, out var power) && !power.Powered)
return false;
2022-10-09 14:16:10 -04:00
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, component))
return false;
_audio.PlayPvs(component.InsertingSound, component.Owner);
2022-10-09 14:16:10 -04:00
_popup.PopupEntity(Loc.GetString("machine-insert-item", ("user", user), ("machine", component.Owner),
("item", toInsert)), component.Owner);
QueueDel(toInsert);
// Logging
TryComp<StackComponent>(toInsert, out var stack);
var count = stack?.Count ?? 1;
_adminLogger.Add(LogType.Action, LogImpact.Low,
$"{ToPrettyString(user):player} inserted {count} {ToPrettyString(toInsert):inserted} into {ToPrettyString(receiver):receiver}");
2022-10-09 14:16:10 -04:00
return true;
}
}