2023-04-10 15:37:03 +10:00
|
|
|
using Content.Shared.Chemistry.Components;
|
2023-10-14 09:45:28 -07:00
|
|
|
using Content.Shared.Chemistry.Components.SolutionManager;
|
|
|
|
|
using Content.Shared.Chemistry.EntitySystems;
|
2021-10-03 06:56:29 +02:00
|
|
|
using Content.Shared.Nutrition.Components;
|
2024-04-01 06:27:39 +00:00
|
|
|
using Content.Shared.Nutrition.EntitySystems;
|
2025-08-06 09:53:38 -07:00
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2023-07-25 21:32:10 +00:00
|
|
|
namespace Content.Server.Nutrition.EntitySystems;
|
|
|
|
|
|
2024-04-17 21:49:58 -04:00
|
|
|
public sealed class DrinkSystem : SharedDrinkSystem
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-07-25 21:32:10 +00:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2024-09-02 06:26:04 -05:00
|
|
|
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
|
2023-07-25 21:32:10 +00:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-07-25 21:32:10 +00:00
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
// TODO add InteractNoHandEvent for entities like mice.
|
2023-12-29 04:47:43 -08:00
|
|
|
SubscribeLocalEvent<DrinkComponent, SolutionContainerChangedEvent>(OnSolutionChange);
|
2023-07-25 21:32:10 +00:00
|
|
|
SubscribeLocalEvent<DrinkComponent, ComponentInit>(OnDrinkInit);
|
2023-09-23 03:10:04 +01:00
|
|
|
// run before inventory so for bucket it always tries to drink before equipping (when empty)
|
|
|
|
|
// run after openable so its always open -> drink
|
2023-07-25 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnDrinkInit(Entity<DrinkComponent> entity, ref ComponentInit args)
|
2023-07-25 21:32:10 +00:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (TryComp<DrainableSolutionComponent>(entity, out var existingDrainable))
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-07-25 21:32:10 +00:00
|
|
|
// Beakers have Drink component but they should use the existing Drainable
|
2023-12-29 04:47:43 -08:00
|
|
|
entity.Comp.Solution = existingDrainable.Solution;
|
2023-07-25 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-09-02 06:26:04 -05:00
|
|
|
_solutionContainer.EnsureSolution(entity.Owner, entity.Comp.Solution, out _);
|
2023-07-25 21:32:10 +00:00
|
|
|
}
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
UpdateAppearance(entity, entity.Comp);
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (TryComp(entity, out RefillableSolutionComponent? refillComp))
|
|
|
|
|
refillComp.Solution = entity.Comp.Solution;
|
2022-04-15 23:17:48 +02:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
if (TryComp(entity, out DrainableSolutionComponent? drainComp))
|
|
|
|
|
drainComp.Solution = entity.Comp.Solution;
|
2023-07-25 21:32:10 +00:00
|
|
|
}
|
2022-08-17 12:47:58 +12:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnSolutionChange(Entity<DrinkComponent> entity, ref SolutionContainerChangedEvent args)
|
2023-07-25 21:32:10 +00:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
UpdateAppearance(entity, entity.Comp);
|
2023-07-25 21:32:10 +00:00
|
|
|
}
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2023-07-25 21:32:10 +00:00
|
|
|
public void UpdateAppearance(EntityUid uid, DrinkComponent component)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<AppearanceComponent>(uid, out var appearance) ||
|
|
|
|
|
!HasComp<SolutionContainerManagerComponent>(uid))
|
2021-09-06 15:49:44 +02:00
|
|
|
{
|
2023-07-25 21:32:10 +00:00
|
|
|
return;
|
2021-10-03 06:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-25 21:32:10 +00:00
|
|
|
var drainAvailable = DrinkVolume(uid, component);
|
|
|
|
|
_appearance.SetData(uid, FoodVisuals.Visual, drainAvailable.Float(), appearance);
|
|
|
|
|
}
|
2021-09-06 15:49:44 +02:00
|
|
|
}
|