2022-08-04 01:52:08 -07:00
|
|
|
using Content.Server.Nutrition.Components;
|
|
|
|
|
using Content.Shared.Chemistry.Components;
|
2023-10-14 09:45:28 -07:00
|
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2022-08-04 01:52:08 -07:00
|
|
|
using Content.Shared.Tag;
|
2025-04-05 00:20:19 +00:00
|
|
|
using Robust.Shared.Prototypes;
|
2022-08-04 01:52:08 -07:00
|
|
|
|
|
|
|
|
namespace Content.Server.Nutrition.EntitySystems
|
|
|
|
|
{
|
2023-10-31 21:39:12 +01:00
|
|
|
public sealed class TrashOnSolutionEmptySystem : EntitySystem
|
2022-08-04 01:52:08 -07:00
|
|
|
{
|
2024-09-02 06:26:04 -05:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
|
2022-08-04 01:52:08 -07:00
|
|
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
|
|
|
|
|
2025-04-05 00:20:19 +00:00
|
|
|
private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
|
|
|
|
|
|
2022-08-04 01:52:08 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2024-01-09 10:11:22 -08:00
|
|
|
SubscribeLocalEvent<TrashOnSolutionEmptyComponent, MapInitEvent>(OnMapInit);
|
2023-12-29 04:47:43 -08:00
|
|
|
SubscribeLocalEvent<TrashOnSolutionEmptyComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
2022-08-04 01:52:08 -07:00
|
|
|
}
|
|
|
|
|
|
2024-01-09 10:11:22 -08:00
|
|
|
public void OnMapInit(Entity<TrashOnSolutionEmptyComponent> entity, ref MapInitEvent args)
|
2022-08-04 01:52:08 -07:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
CheckSolutions(entity);
|
2022-08-04 01:52:08 -07:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
public void OnSolutionChange(Entity<TrashOnSolutionEmptyComponent> entity, ref SolutionContainerChangedEvent args)
|
2022-08-04 01:52:08 -07:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
CheckSolutions(entity);
|
2022-08-04 01:52:08 -07:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
public void CheckSolutions(Entity<TrashOnSolutionEmptyComponent> entity)
|
2022-08-04 01:52:08 -07:00
|
|
|
{
|
2025-06-26 19:50:49 -04:00
|
|
|
if (!HasComp<SolutionContainerManagerComponent>(entity))
|
2022-08-04 01:52:08 -07:00
|
|
|
return;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (_solutionContainerSystem.TryGetSolution(entity.Owner, entity.Comp.Solution, out _, out var solution))
|
|
|
|
|
UpdateTags(entity, solution);
|
2022-08-04 01:52:08 -07:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
public void UpdateTags(Entity<TrashOnSolutionEmptyComponent> entity, Solution solution)
|
2022-08-04 01:52:08 -07:00
|
|
|
{
|
2023-01-12 16:41:40 +13:00
|
|
|
if (solution.Volume <= 0)
|
2022-08-04 01:52:08 -07:00
|
|
|
{
|
2025-04-05 00:20:19 +00:00
|
|
|
_tagSystem.AddTag(entity.Owner, TrashTag);
|
2022-08-04 01:52:08 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2025-04-05 00:20:19 +00:00
|
|
|
|
|
|
|
|
_tagSystem.RemoveTag(entity.Owner, TrashTag);
|
2022-08-04 01:52:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|