artifact crusher (#22301)

This commit is contained in:
Nemanja
2023-12-11 18:15:47 -05:00
committed by GitHub
parent 0433d3b06a
commit 6e91346ff3
23 changed files with 501 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
using Content.Shared.Storage.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
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!;
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ArtifactCrusherComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ArtifactCrusherComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
}
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);
}
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);
}
}