2022-01-18 07:35:17 +01:00
|
|
|
using Content.Server.Atmos.EntitySystems;
|
2021-11-11 16:10:57 -07:00
|
|
|
using Content.Server.Body.Components;
|
2021-11-30 16:47:21 -07:00
|
|
|
using Content.Server.Body.Systems;
|
2023-12-29 04:47:43 -08:00
|
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
|
|
|
|
using Content.Server.Forensics;
|
2021-09-26 15:19:00 +02:00
|
|
|
using Content.Shared.Chemistry;
|
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2022-10-23 11:30:37 +13:00
|
|
|
using Content.Shared.Clothing.Components;
|
2022-07-27 03:53:47 -07:00
|
|
|
using Content.Shared.Clothing.EntitySystems;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2022-06-29 12:36:32 +01:00
|
|
|
using Content.Shared.Inventory;
|
2023-12-29 04:47:43 -08:00
|
|
|
using Content.Shared.Inventory.Events;
|
2022-07-29 13:02:09 +12:00
|
|
|
using Content.Shared.Item;
|
2023-12-29 04:47:43 -08:00
|
|
|
using Content.Shared.Nutrition.Components;
|
2021-09-22 11:05:33 +02:00
|
|
|
using Content.Shared.Smoking;
|
|
|
|
|
using Content.Shared.Temperature;
|
2022-07-04 16:51:34 +02:00
|
|
|
using Robust.Server.GameObjects;
|
2021-09-26 15:19:00 +02:00
|
|
|
using Robust.Shared.Containers;
|
2022-10-23 11:30:37 +13:00
|
|
|
using System.Linq;
|
2021-09-22 11:05:33 +02:00
|
|
|
|
|
|
|
|
namespace Content.Server.Nutrition.EntitySystems
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed partial class SmokingSystem : EntitySystem
|
2021-09-22 11:05:33 +02:00
|
|
|
{
|
2021-11-22 02:17:35 -07:00
|
|
|
[Dependency] private readonly ReactiveSystem _reactiveSystem = default!;
|
2021-09-26 15:19:00 +02:00
|
|
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
2021-11-30 16:47:21 -07:00
|
|
|
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
|
2022-01-18 07:35:17 +01:00
|
|
|
[Dependency] private readonly AtmosphereSystem _atmos = default!;
|
2022-07-04 16:51:34 +02:00
|
|
|
[Dependency] private readonly TransformSystem _transformSystem = default!;
|
2022-06-29 12:36:32 +01:00
|
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
2022-07-27 03:53:47 -07:00
|
|
|
[Dependency] private readonly ClothingSystem _clothing = default!;
|
2022-07-29 13:02:09 +12:00
|
|
|
[Dependency] private readonly SharedItemSystem _items = default!;
|
2023-10-11 02:18:49 -07:00
|
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2023-12-15 04:52:55 -05:00
|
|
|
[Dependency] private readonly ForensicsSystem _forensics = default!;
|
2022-07-27 03:53:47 -07:00
|
|
|
|
2021-09-26 15:19:00 +02:00
|
|
|
private const float UpdateTimer = 3f;
|
|
|
|
|
|
2023-10-11 02:18:49 -07:00
|
|
|
private float _timer;
|
2021-09-26 15:19:00 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We keep a list of active smokables, because iterating all existing smokables would be dumb.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly HashSet<EntityUid> _active = new();
|
|
|
|
|
|
2021-09-22 11:05:33 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
2021-09-26 15:19:00 +02:00
|
|
|
SubscribeLocalEvent<SmokableComponent, IsHotEvent>(OnSmokableIsHotEvent);
|
|
|
|
|
SubscribeLocalEvent<SmokableComponent, ComponentShutdown>(OnSmokableShutdownEvent);
|
2023-12-15 04:52:55 -05:00
|
|
|
SubscribeLocalEvent<SmokableComponent, GotEquippedEvent>(OnSmokeableEquipEvent);
|
2021-09-26 15:19:00 +02:00
|
|
|
|
|
|
|
|
InitializeCigars();
|
2022-09-19 19:54:33 -04:00
|
|
|
InitializePipes();
|
2023-05-01 17:34:11 +03:00
|
|
|
InitializeVapes();
|
2021-09-26 15:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-07 01:45:02 +13:00
|
|
|
public void SetSmokableState(EntityUid uid, SmokableState state, SmokableComponent? smokable = null,
|
|
|
|
|
AppearanceComponent? appearance = null, ClothingComponent? clothing = null)
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
2022-01-07 01:45:02 +13:00
|
|
|
if (!Resolve(uid, ref smokable, ref appearance, ref clothing))
|
2021-09-26 15:19:00 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
smokable.State = state;
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, SmokingVisuals.Smoking, state, appearance);
|
2021-09-26 15:19:00 +02:00
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
var newState = state switch
|
2022-01-07 01:45:02 +13:00
|
|
|
{
|
|
|
|
|
SmokableState.Lit => smokable.LitPrefix,
|
|
|
|
|
SmokableState.Burnt => smokable.BurntPrefix,
|
|
|
|
|
_ => smokable.UnlitPrefix
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
_clothing.SetEquippedPrefix(uid, newState, clothing);
|
2022-07-29 13:02:09 +12:00
|
|
|
_items.SetHeldPrefix(uid, newState);
|
2022-07-27 03:53:47 -07:00
|
|
|
|
2021-09-26 15:19:00 +02:00
|
|
|
if (state == SmokableState.Lit)
|
|
|
|
|
_active.Add(uid);
|
|
|
|
|
else
|
|
|
|
|
_active.Remove(uid);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnSmokableIsHotEvent(Entity<SmokableComponent> entity, ref IsHotEvent args)
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
args.IsHot = entity.Comp.State == SmokableState.Lit;
|
2021-09-26 15:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnSmokableShutdownEvent(Entity<SmokableComponent> entity, ref ComponentShutdown args)
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
_active.Remove(entity);
|
2021-09-22 11:05:33 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnSmokeableEquipEvent(Entity<SmokableComponent> entity, ref GotEquippedEvent args)
|
2023-12-15 04:52:55 -05:00
|
|
|
{
|
|
|
|
|
if (args.Slot == "mask")
|
|
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
_forensics.TransferDna(entity.Owner, args.Equipee, false);
|
2023-12-15 04:52:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-26 15:19:00 +02:00
|
|
|
public override void Update(float frameTime)
|
2021-09-22 11:05:33 +02:00
|
|
|
{
|
2021-09-26 15:19:00 +02:00
|
|
|
_timer += frameTime;
|
|
|
|
|
|
|
|
|
|
if (_timer < UpdateTimer)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-04 16:51:34 +02:00
|
|
|
// TODO Use an "active smoke" component instead, EntityQuery over that.
|
2021-09-26 15:19:00 +02:00
|
|
|
foreach (var uid in _active.ToArray())
|
|
|
|
|
{
|
2022-01-18 07:35:17 +01:00
|
|
|
if (!TryComp(uid, out SmokableComponent? smokable))
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
|
|
|
|
_active.Remove(uid);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (!_solutionContainerSystem.TryGetSolution(uid, smokable.Solution, out var soln, out var solution))
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
|
|
|
|
_active.Remove(uid);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 07:35:17 +01:00
|
|
|
if (smokable.ExposeTemperature > 0 && smokable.ExposeVolume > 0)
|
|
|
|
|
{
|
|
|
|
|
var transform = Transform(uid);
|
2022-07-04 16:51:34 +02:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (transform.GridUid is { } gridUid)
|
2022-07-04 16:51:34 +02:00
|
|
|
{
|
|
|
|
|
var position = _transformSystem.GetGridOrMapTilePosition(uid, transform);
|
2023-02-28 14:43:24 -06:00
|
|
|
_atmos.HotspotExpose(gridUid, position, smokable.ExposeTemperature, smokable.ExposeVolume, uid, true);
|
2022-07-04 16:51:34 +02:00
|
|
|
}
|
2022-01-18 07:35:17 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
var inhaledSolution = _solutionContainerSystem.SplitSolution(soln.Value, smokable.InhaleAmount * _timer);
|
2021-09-26 15:19:00 +02:00
|
|
|
|
2023-01-12 16:41:40 +13:00
|
|
|
if (solution.Volume == FixedPoint2.Zero)
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(uid, new SmokableSolutionEmptyEvent(), true);
|
2021-09-26 15:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 16:41:40 +13:00
|
|
|
if (inhaledSolution.Volume == FixedPoint2.Zero)
|
2021-09-26 15:19:00 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// This is awful. I hate this so much.
|
|
|
|
|
// TODO: Please, someone refactor containers and free me from this bullshit.
|
2023-10-11 02:18:49 -07:00
|
|
|
if (!_container.TryGetContainingContainer(uid, out var containerManager) ||
|
|
|
|
|
!(_inventorySystem.TryGetSlotEntity(containerManager.Owner, "mask", out var inMaskSlotUid) && inMaskSlotUid == uid) ||
|
2022-01-18 07:35:17 +01:00
|
|
|
!TryComp(containerManager.Owner, out BloodstreamComponent? bloodstream))
|
2022-06-29 12:36:32 +01:00
|
|
|
{
|
2021-09-26 15:19:00 +02:00
|
|
|
continue;
|
2022-06-29 12:36:32 +01:00
|
|
|
}
|
2021-09-26 15:19:00 +02:00
|
|
|
|
2023-04-06 14:20:48 -07:00
|
|
|
_reactiveSystem.DoEntityReaction(containerManager.Owner, inhaledSolution, ReactionMethod.Ingestion);
|
2022-02-17 15:00:41 -07:00
|
|
|
_bloodstreamSystem.TryAddToChemicals(containerManager.Owner, inhaledSolution, bloodstream);
|
2021-09-26 15:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_timer -= UpdateTimer;
|
2021-09-22 11:05:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-26 15:19:00 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Directed event raised when the smokable solution is empty.
|
|
|
|
|
/// </summary>
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class SmokableSolutionEmptyEvent : EntityEventArgs
|
2021-09-26 15:19:00 +02:00
|
|
|
{
|
|
|
|
|
}
|
2021-09-22 11:05:33 +02:00
|
|
|
}
|