Adds trash tag to more items. New component "TrashOnEmpty" (#10166)
This commit is contained in:
53
Content.Server/Nutrition/EntitySystems/TrashOnEmptySystem.cs
Normal file
53
Content.Server/Nutrition/EntitySystems/TrashOnEmptySystem.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Tag;
|
||||
|
||||
namespace Content.Server.Nutrition.EntitySystems
|
||||
{
|
||||
public sealed class TrashOnEmptySystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<TrashOnEmptyComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<TrashOnEmptyComponent, SolutionChangedEvent>(OnSolutionChange);
|
||||
}
|
||||
|
||||
public void OnStartup(EntityUid uid, TrashOnEmptyComponent component, ComponentStartup args)
|
||||
{
|
||||
CheckSolutions(component);
|
||||
}
|
||||
|
||||
public void OnSolutionChange(EntityUid uid, TrashOnEmptyComponent component, SolutionChangedEvent args)
|
||||
{
|
||||
CheckSolutions(component);
|
||||
}
|
||||
|
||||
public void CheckSolutions(TrashOnEmptyComponent component)
|
||||
{
|
||||
EntityManager.EnsureComponent<TagComponent>(component.Owner);
|
||||
|
||||
if (!EntityManager.HasComponent<SolutionContainerManagerComponent>((component).Owner))
|
||||
return;
|
||||
|
||||
if (_solutionContainerSystem.TryGetSolution(component.Owner, component.Solution, out var solution))
|
||||
UpdateTags(component, solution);
|
||||
}
|
||||
|
||||
public void UpdateTags(TrashOnEmptyComponent component, Solution solution)
|
||||
{
|
||||
if (solution.DrainAvailable <= 0)
|
||||
{
|
||||
_tagSystem.AddTag(component.Owner, "Trash");
|
||||
return;
|
||||
}
|
||||
if (_tagSystem.HasTag(component.Owner, "Trash"))
|
||||
_tagSystem.RemoveTag(component.Owner, "Trash");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user