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,110 @@
using Content.Shared.Damage;
using Content.Shared.Stacks;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Components;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Xenoarchaeology.Equipment;
/// <summary>
/// This is an entity storage that, when activated, crushes the artifact inside of it and gives artifact fragments.
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedArtifactCrusherSystem))]
public sealed partial class ArtifactCrusherComponent : Component
{
/// <summary>
/// Whether or not the crusher is currently in the process of crushing something.
/// </summary>
[DataField, AutoNetworkedField]
public bool Crushing;
/// <summary>
/// When the current crushing will end.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public TimeSpan CrushEndTime;
/// <summary>
/// The next second. Used to apply damage over time.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public TimeSpan NextSecond;
/// <summary>
/// The total duration of the crushing.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public TimeSpan CrushDuration = TimeSpan.FromSeconds(10);
/// <summary>
/// A whitelist specifying what items, when crushed, will give fragments.
/// </summary>
[DataField]
public EntityWhitelist CrushingWhitelist = new();
/// <summary>
/// The minimum amount of fragments spawned.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public int MinFragments = 2;
/// <summary>
/// The maximum amount of fragments spawned, non-inclusive.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public int MaxFragments = 5;
/// <summary>
/// The material for the fragments.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public ProtoId<StackPrototype> FragmentStackProtoId = "ArtifactFragment";
/// <summary>
/// A container used to hold fragments and gibs from crushing.
/// </summary>
[ViewVariables]
public Container OutputContainer;
/// <summary>
/// The ID for <see cref="OutputContainer"/>
/// </summary>
[DataField]
public string OutputContainerName = "output_container";
/// <summary>
/// Damage dealt each second to entities inside while crushing.
/// </summary>
[DataField]
public DamageSpecifier CrushingDamage = new();
/// <summary>
/// Sound played at the end of a successful crush.
/// </summary>
[DataField, AutoNetworkedField]
public SoundSpecifier? CrushingCompleteSound = new SoundPathSpecifier("/Audio/Effects/metal_crunch.ogg");
/// <summary>
/// Sound played throughout the entire crushing. Cut off if ended early.
/// </summary>
[DataField, AutoNetworkedField]
public SoundSpecifier? CrushingSound = new SoundPathSpecifier("/Audio/Effects/hydraulic_press.ogg");
/// <summary>
/// Stores entity of <see cref="CrushingSound"/> to allow ending it early.
/// </summary>
[DataField]
public (EntityUid, AudioComponent)? CrushingSoundEntity;
}
[Serializable, NetSerializable]
public enum ArtifactCrusherVisuals : byte
{
Crushing
}

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);
}
}