using Content.Server.Nutrition.Components; using Content.Shared.Chemistry.Components.SolutionManager; using Content.Shared.Containers.ItemSlots; using Content.Shared.Interaction; using Content.Shared.Nutrition.Components; using Content.Shared.Smoking; using Content.Shared.Temperature; namespace Content.Server.Nutrition.EntitySystems { public sealed partial class SmokingSystem { [Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!; private void InitializePipes() { SubscribeLocalEvent(OnPipeInteractUsingEvent); SubscribeLocalEvent(OnPipeSolutionEmptyEvent); SubscribeLocalEvent(OnPipeAfterInteract); SubscribeLocalEvent(OnComponentInit); } public void OnComponentInit(Entity entity, ref ComponentInit args) { _itemSlotsSystem.AddItemSlot(entity, SmokingPipeComponent.BowlSlotId, entity.Comp.BowlSlot); } private void OnPipeInteractUsingEvent(Entity entity, ref InteractUsingEvent args) { if (args.Handled) return; if (!EntityManager.TryGetComponent(entity, out SmokableComponent? smokable)) return; if (smokable.State != SmokableState.Unlit) return; var isHotEvent = new IsHotEvent(); RaiseLocalEvent(args.Used, isHotEvent, false); if (!isHotEvent.IsHot) return; if (TryTransferReagents(entity, (entity.Owner, smokable))) SetSmokableState(entity, SmokableState.Lit, smokable); args.Handled = true; } public void OnPipeAfterInteract(Entity entity, ref AfterInteractEvent args) { var targetEntity = args.Target; if (targetEntity == null || !args.CanReach || !EntityManager.TryGetComponent(entity, out SmokableComponent? smokable) || smokable.State == SmokableState.Lit) return; var isHotEvent = new IsHotEvent(); RaiseLocalEvent(targetEntity.Value, isHotEvent, true); if (!isHotEvent.IsHot) return; if (TryTransferReagents(entity, (entity.Owner, smokable))) SetSmokableState(entity, SmokableState.Lit, smokable); args.Handled = true; } private void OnPipeSolutionEmptyEvent(Entity entity, ref SmokableSolutionEmptyEvent args) { _itemSlotsSystem.SetLock(entity, entity.Comp.BowlSlot, false); SetSmokableState(entity, SmokableState.Unlit); } // Convert smokable item into reagents to be smoked private bool TryTransferReagents(Entity entity, Entity smokable) { if (entity.Comp.BowlSlot.Item == null) return false; EntityUid contents = entity.Comp.BowlSlot.Item.Value; if (!TryComp(contents, out var reagents) || !_solutionContainerSystem.TryGetSolution(smokable.Owner, smokable.Comp.Solution, out var pipeSolution, out _)) return false; foreach (var (_, soln) in _solutionContainerSystem.EnumerateSolutions((contents, reagents))) { var reagentSolution = soln.Comp.Solution; _solutionContainerSystem.TryAddSolution(pipeSolution.Value, reagentSolution); } EntityManager.DeleteEntity(contents); _itemSlotsSystem.SetLock(entity.Owner, entity.Comp.BowlSlot, true); //no inserting more until current runs out return true; } } }