106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
using Content.Shared.Examine;
|
|
using Content.Shared.Storage.Components;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Containers;
|
|
using Content.Shared.Emag.Systems;
|
|
using Content.Shared.Xenoarchaeology.Equipment.Components;
|
|
|
|
namespace Content.Shared.Xenoarchaeology.Equipment;
|
|
|
|
/// <summary>
|
|
/// This handles logic relating to <see cref="ArtifactCrusherComponent"/>
|
|
/// </summary>
|
|
public abstract class SharedArtifactCrusherSystem : EntitySystem
|
|
{
|
|
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
|
|
[Dependency] protected readonly SharedAudioSystem AudioSystem = default!;
|
|
[Dependency] protected readonly SharedContainerSystem ContainerSystem = default!;
|
|
[Dependency] private readonly EmagSystem _emag = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ArtifactCrusherComponent, ComponentInit>(OnInit);
|
|
SubscribeLocalEvent<ArtifactCrusherComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
|
|
SubscribeLocalEvent<ArtifactCrusherComponent, StorageOpenAttemptEvent>(OnStorageOpenAttempt);
|
|
SubscribeLocalEvent<ArtifactCrusherComponent, ExaminedEvent>(OnExamine);
|
|
SubscribeLocalEvent<ArtifactCrusherComponent, GotEmaggedEvent>(OnEmagged);
|
|
SubscribeLocalEvent<ArtifactCrusherComponent, GotUnEmaggedEvent>(OnUnemagged); // Frontier: demag
|
|
}
|
|
|
|
private void OnInit(Entity<ArtifactCrusherComponent> ent, ref ComponentInit args)
|
|
{
|
|
ent.Comp.OutputContainer = ContainerSystem.EnsureContainer<Container>(ent, ent.Comp.OutputContainerName);
|
|
}
|
|
|
|
private void OnStorageAfterOpen(Entity<ArtifactCrusherComponent> ent, ref StorageAfterOpenEvent args)
|
|
{
|
|
StopCrushing(ent);
|
|
ContainerSystem.EmptyContainer(ent.Comp.OutputContainer);
|
|
}
|
|
|
|
private void OnEmagged(Entity<ArtifactCrusherComponent> ent, ref GotEmaggedEvent args)
|
|
{
|
|
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
|
|
return;
|
|
|
|
if (_emag.CheckFlag(ent, EmagType.Interaction))
|
|
return;
|
|
|
|
if (ent.Comp.AutoLock)
|
|
return;
|
|
|
|
ent.Comp.AutoLock = true;
|
|
args.Handled = true;
|
|
}
|
|
|
|
// Frontier: demag
|
|
private void OnUnemagged(Entity<ArtifactCrusherComponent> ent, ref GotUnEmaggedEvent args)
|
|
{
|
|
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
|
|
return;
|
|
|
|
if (!_emag.CheckFlag(ent, EmagType.Interaction))
|
|
return;
|
|
|
|
if (!ent.Comp.AutoLock)
|
|
return;
|
|
|
|
ent.Comp.AutoLock = false;
|
|
args.Handled = true;
|
|
}
|
|
// End Frontier
|
|
|
|
private void OnStorageOpenAttempt(Entity<ArtifactCrusherComponent> ent, ref StorageOpenAttemptEvent args)
|
|
{
|
|
if (ent.Comp.AutoLock && ent.Comp.Crushing)
|
|
args.Cancelled = true;
|
|
}
|
|
|
|
private void OnExamine(Entity<ArtifactCrusherComponent> ent, ref ExaminedEvent args)
|
|
{
|
|
args.PushMarkup(ent.Comp.AutoLock ? Loc.GetString("artifact-crusher-examine-autolocks") : Loc.GetString("artifact-crusher-examine-no-autolocks"));
|
|
}
|
|
|
|
public void StopCrushing(Entity<ArtifactCrusherComponent> ent, bool early = true)
|
|
{
|
|
var (_, crusher) = ent;
|
|
|
|
if (!crusher.Crushing)
|
|
return;
|
|
|
|
crusher.Crushing = false;
|
|
Appearance.SetData(ent, ArtifactCrusherVisuals.Crushing, false);
|
|
|
|
if (early)
|
|
{
|
|
AudioSystem.Stop(crusher.CrushingSoundEntity?.Item1, crusher.CrushingSoundEntity?.Item2);
|
|
crusher.CrushingSoundEntity = null;
|
|
}
|
|
|
|
Dirty(ent, ent.Comp);
|
|
}
|
|
}
|