Skip to content

Commit

Permalink
RandomizedCandy: Play sound when candy is fabricated
Browse files Browse the repository at this point in the history
  • Loading branch information
pissdemon committed Apr 10, 2024
1 parent da69fd0 commit 4f185a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Robust.Shared.Audio;

namespace Content.Server.Abilities.Borgs;

[RegisterComponent]
Expand All @@ -8,4 +10,11 @@ public sealed partial class FabricateCandyComponent : Component

[DataField("gumballAction")]
public EntityUid? GumballAction;

/// <summary>
/// The sound played when fabricating candy.
/// </summary>
[DataField("fabricationSound")]
[ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier FabricationSound = new SoundPathSpecifier("/Audio/Machines/machine_vend.ogg");
}
18 changes: 14 additions & 4 deletions Content.Server/Nyanotrasen/Abilities/Borgs/FabricateCandySystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Robust.Server.Audio;
using Robust.Shared.Prototypes;
using Content.Shared.Actions;
using Content.Shared.Actions.Events;

Expand All @@ -6,6 +8,8 @@ namespace Content.Server.Abilities.Borgs;
public sealed partial class FabricateCandySystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -25,13 +29,19 @@ private void OnInit(EntityUid uid, FabricateCandyComponent component, ComponentI

private void OnLollipop(FabricateLollipopActionEvent args)
{
Spawn("FoodLollipop", Transform(args.Performer).Coordinates);
args.Handled = true;
OnCandy("FoodLollipop", args);
}

private void OnGumball(FabricateGumballActionEvent args)
{
Spawn("FoodGumball", Transform(args.Performer).Coordinates);
args.Handled = true;
OnCandy("FoodGumball", args);
}

private void OnCandy(EntProtoId proto, BaseActionEvent evt)
{
Spawn(proto, Transform(evt.Performer).Coordinates);
if (TryComp(evt.Performer, out FabricateCandyComponent? comp))
_audioSystem.PlayPvs(comp.FabricationSound, evt.Performer);
evt.Handled = true;
}
}

0 comments on commit 4f185a0

Please sign in to comment.