Files
OldThink/Content.Shared/Nutrition/EntitySystems/SharedDrinkSystem.cs
Jabak 381d904d4b почти важно (#135)
* Add data field for id card microwave behaviour (#28087)

* Move replacement chance from ReplacementAccentComponent to ReplacementAccentPrototype (#28049)

Move replacement chance to ReplacementAccentPrototype

* Resolves Bible summon message being sent to all users (#28104)

* Changed PopupEntity overload used to ensure message is only sent to user

* Updated uid for PopupEntity call

* Updating _popupSystem.PopupEntity call in AttemptSummon

* Random book story generator refactor (#28082)

* Randomized book overhaul

* Fix prototype names

* Improved setting paper content

* Praise Ratvar

* Fix activatable UI popup message spam (#28123)

Fixed activatable UI popup message spam

* Modify battery assert to avoid floating point errors (#28007)

* Update component query benchmarks (#27967)

* Add more component query benchmarks.

* Rename benchmark

* Use non-generic `TryComp()` for metadata & transform (#28133)

* sleeper agent appear later into the round and only once (#28160)

---------

Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com>
Co-authored-by: double_b <40827162+benjamin-burges@users.noreply.github.com>
Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Co-authored-by: Killerqu00 <47712032+Killerqu00@users.noreply.github.com>
2024-10-04 11:27:12 +03:00

91 lines
3.2 KiB
C#

using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Examine;
using Content.Shared.FixedPoint;
using Content.Shared.Nutrition.Components;
namespace Content.Shared.Nutrition.EntitySystems;
public abstract partial class SharedDrinkSystem : EntitySystem
{
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly OpenableSystem _openable = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DrinkComponent, AttemptShakeEvent>(OnAttemptShake);
SubscribeLocalEvent<DrinkComponent, ExaminedEvent>(OnExamined);
}
protected void OnAttemptShake(Entity<DrinkComponent> entity, ref AttemptShakeEvent args)
{
if (IsEmpty(entity, entity.Comp))
args.Cancelled = true;
}
protected void OnExamined(Entity<DrinkComponent> entity, ref ExaminedEvent args)
{
TryComp<OpenableComponent>(entity, out var openable);
if (_openable.IsClosed(entity.Owner, null, openable) || !args.IsInDetailsRange || !entity.Comp.Examinable)
return;
var empty = IsEmpty(entity, entity.Comp);
if (empty)
{
args.PushMarkup(Loc.GetString("drink-component-on-examine-is-empty"));
return;
}
if (HasComp<ExaminableSolutionComponent>(entity))
{
//provide exact measurement for beakers
args.PushText(Loc.GetString("drink-component-on-examine-exact-volume", ("amount", DrinkVolume(entity, entity.Comp))));
}
else
{
//general approximation
var remainingString = (int) _solutionContainer.PercentFull(entity) switch
{
100 => "drink-component-on-examine-is-full",
> 66 => "drink-component-on-examine-is-mostly-full",
> 33 => HalfEmptyOrHalfFull(args),
_ => "drink-component-on-examine-is-mostly-empty",
};
args.PushMarkup(Loc.GetString(remainingString));
}
}
protected FixedPoint2 DrinkVolume(EntityUid uid, DrinkComponent? component = null)
{
if (!Resolve(uid, ref component))
return FixedPoint2.Zero;
if (!_solutionContainer.TryGetSolution(uid, component.Solution, out _, out var sol))
return FixedPoint2.Zero;
return sol.Volume;
}
protected bool IsEmpty(EntityUid uid, DrinkComponent? component = null)
{
if (!Resolve(uid, ref component))
return true;
return DrinkVolume(uid, component) <= 0;
}
// some see half empty, and others see half full
private string HalfEmptyOrHalfFull(ExaminedEvent args)
{
string remainingString = "drink-component-on-examine-is-half-full";
if (TryComp(args.Examiner, out MetaDataComponent? examiner) && examiner.EntityName.Length > 0
&& string.Compare(examiner.EntityName.Substring(0, 1), "m", StringComparison.InvariantCultureIgnoreCase) > 0)
remainingString = "drink-component-on-examine-is-half-empty";
return remainingString;
}
}