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;
[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!;
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);
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;
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);
}
}
private void OnSmokableShutdownEvent(Entity<SmokableComponent> entity, ref ComponentShutdown args)
{
- _active.Remove(entity);
+ RemComp<BurningComponent>(entity);
}
private void OnSmokeableEquipEvent(Entity<SmokableComponent> entity, ref GotEquippedEvent args)
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;
}
using Content.Shared.FixedPoint;
using Content.Shared.Smoking;
+using Robust.Shared.Audio;
using Robust.Shared.GameStates;
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");
}
}