ciggie sounds (#32426)

* add sounds

* change _active to BurningComponent

* play sound when lighting and snuffing a cigar

* network it

* mono

* attribution

* doc

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2025-04-18 23:01:52 +01:00
committed by GitHub
parent dd35318a87
commit 14d9a35116
6 changed files with 43 additions and 22 deletions

View File

@@ -15,6 +15,7 @@ using Content.Shared.Nutrition.Components;
using Content.Shared.Smoking;
using Content.Shared.Temperature;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using System.Linq;
using Content.Shared.Atmos;
@@ -30,6 +31,7 @@ namespace Content.Server.Nutrition.EntitySystems
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly ClothingSystem _clothing = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedItemSystem _items = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
@@ -39,11 +41,6 @@ namespace Content.Server.Nutrition.EntitySystems
private float _timer;
/// <summary>
/// We keep a list of active smokables, because iterating all existing smokables would be dumb.
/// </summary>
private readonly HashSet<EntityUid> _active = new();
public override void Initialize()
{
SubscribeLocalEvent<SmokableComponent, IsHotEvent>(OnSmokableIsHotEvent);
@@ -65,7 +62,7 @@ namespace Content.Server.Nutrition.EntitySystems
public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null,
AppearanceComponent? appearance = null, ClothingComponent? clothing = null)
{
if (!Resolve(uid, ref smokable, ref appearance, ref clothing))
if (!Resolve(uid, ref smokable, ref appearance, ref clothing) || smokable.State == state)
return;
smokable.State = state;
@@ -83,17 +80,17 @@ namespace Content.Server.Nutrition.EntitySystems
if (state == SmokableState.Lit)
{
EnsureComp<BurningComponent>(uid);
_audio.PlayPvs(smokable.LightSound, uid);
var igniteEvent = new IgnitedEvent();
RaiseLocalEvent(uid, ref igniteEvent);
_active.Add(uid);
}
else
{
var igniteEvent = new ExtinguishedEvent();
RaiseLocalEvent(uid, ref igniteEvent);
_active.Remove(uid);
RemComp<BurningComponent>(uid);
_audio.PlayPvs(smokable.SnuffSound, uid);
var extinguishEvent = new ExtinguishedEvent();
RaiseLocalEvent(uid, ref extinguishEvent);
}
}
@@ -104,7 +101,7 @@ namespace Content.Server.Nutrition.EntitySystems
private void OnSmokableShutdownEvent(Entity<SmokableComponent> entity, ref ComponentShutdown args)
{
_active.Remove(entity);
RemComp<BurningComponent>(entity);
}
private void OnSmokeableEquipEvent(Entity<SmokableComponent> entity, ref GotEquippedEvent args)
@@ -122,18 +119,12 @@ namespace Content.Server.Nutrition.EntitySystems
if (_timer < UpdateTimer)
return;
// TODO Use an "active smoke" component instead, EntityQuery over that.
foreach (var uid in _active.ToArray())
var query = EntityQueryEnumerator<BurningComponent, SmokableComponent>();
while (query.MoveNext(out var uid, out _, out var smokable))
{
if (!TryComp(uid, out SmokableComponent? smokable))
{
_active.Remove(uid);
continue;
}
if (!_solutionContainerSystem.TryGetSolution(uid, smokable.Solution, out var soln, out var solution))
{
_active.Remove(uid);
SetSmokableState(uid, SmokableState.Unlit, smokable);
continue;
}

View File

@@ -1,5 +1,6 @@
using Content.Shared.FixedPoint;
using Content.Shared.Smoking;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
namespace Content.Shared.Nutrition.Components
@@ -32,5 +33,17 @@ namespace Content.Shared.Nutrition.Components
public string LitPrefix = "lit";
[DataField("unlitPrefix")]
public string UnlitPrefix = "unlit";
/// <summary>
/// Sound played when lighting this smokable.
/// </summary>
[DataField]
public SoundSpecifier? LightSound = new SoundPathSpecifier("/Audio/Effects/cig_light.ogg");
/// <summary>
/// Sound played when this smokable is extinguished or runs out.
/// </summary>
[DataField]
public SoundSpecifier? SnuffSound = new SoundPathSpecifier("/Audio/Effects/cig_snuff.ogg");
}
}

View File

@@ -0,0 +1,12 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Smoking;
/// <summary>
/// Marker component used to track active burning objects.
/// </summary>
/// <remarks>
/// Right now only smoking uses this, but flammable could use it as well in the future.
/// </remarks>
[RegisterComponent, NetworkedComponent]
public sealed partial class BurningComponent : Component;

View File

@@ -241,3 +241,8 @@
copyright: 'created by Vrymaa on Freesound and modified by Chaboricks'
license: "CC0-1.0"
source: https://freesound.org/people/Vrymaa/sounds/785128/
- files: ["cig_light.ogg", "cig_snuff.ogg"]
license: "CC-BY-SA-3.0"
copyright: "Created by mattroks101 for Bee Station. cig_snuff converted to mono"
source: "https://github.com/BeeStation/BeeStation-Hornet/pull/29"

Binary file not shown.

Binary file not shown.