mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
* PredictedRandom Helpers * fixxxx * documentation!!! * pram --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using Content.Shared.Fluids;
|
|
using Content.Shared.Nutrition.Components;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Random.Helpers;
|
|
using Content.Shared.Tag;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Nutrition.EntitySystems;
|
|
|
|
public sealed class MessyDrinkerSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IngestionSystem _ingestion = default!;
|
|
[Dependency] private readonly SharedPuddleSystem _puddle = default!;
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
[Dependency] private readonly TagSystem _tag = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<MessyDrinkerComponent, IngestingEvent>(OnIngested);
|
|
}
|
|
|
|
private void OnIngested(Entity<MessyDrinkerComponent> ent, ref IngestingEvent ev)
|
|
{
|
|
if (ent.Comp.SpillImmuneTag != null && _tag.HasTag(ev.Food, ent.Comp.SpillImmuneTag.Value))
|
|
return;
|
|
|
|
// Cannot spill if you're being forced to drink.
|
|
if (ev.ForceFed)
|
|
return;
|
|
|
|
var proto = _ingestion.GetEdibleType(ev.Food);
|
|
|
|
if (proto == null || !ent.Comp.SpillableTypes.Contains(proto.Value))
|
|
return;
|
|
|
|
if (!SharedRandomExtensions.PredictedProb(_timing, ent.Comp.SpillChance, GetNetEntity(ent)))
|
|
return;
|
|
|
|
if (ent.Comp.SpillMessagePopup != null)
|
|
_popup.PopupPredicted(Loc.GetString(ent.Comp.SpillMessagePopup), null, ent, ent, PopupType.MediumCaution);
|
|
|
|
var split = ev.Split.SplitSolution(ent.Comp.SpillAmount);
|
|
|
|
_puddle.TrySpillAt(ent, split, out _);
|
|
}
|
|
}
|