using System.Linq; using Content.Server.Fluids.EntitySystems; using Content.Shared.FootPrint; using Content.Shared.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Fluids; using Content.Shared.Fluids.Components; using Content.Shared.Maps; using Robust.Shared.Physics.Events; namespace Content.Server.FootPrint; public sealed class PuddleFootPrintsSystem : EntitySystem { [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnStepTrigger); } private void OnStepTrigger(EntityUid uid, PuddleFootPrintsComponent component, ref EndCollideEvent args) { if (!TryComp(uid, out var appearance) || !TryComp(uid, out var puddle) || !TryComp(args.OtherEntity, out var tripper) || !TryComp(uid, out var solutionManager) || !_solutionContainer.ResolveSolution((uid, solutionManager), puddle.SolutionName, ref puddle.Solution, out var solutions)) return; var totalSolutionQuantity = solutions.Contents.Sum(sol => (float) sol.Quantity); var waterQuantity = (from sol in solutions.Contents where sol.Reagent.Prototype == "Water" select (float) sol.Quantity).FirstOrDefault(); if (waterQuantity / (totalSolutionQuantity / 100f) > component.OffPercent || solutions.Contents.Count <= 0) return; tripper.ReagentToTransfer = solutions.Contents.Aggregate((l, r) => l.Quantity > r.Quantity ? l : r).Reagent.Prototype; if (_appearance.TryGetData(uid, PuddleVisuals.SolutionColor, out var color, appearance) && _appearance.TryGetData(uid, PuddleVisuals.CurrentVolume, out var volume, appearance)) AddColor((Color) color, (float) volume * component.SizeRatio, tripper); _solutionContainer.RemoveEachReagent(puddle.Solution.Value, 1); } private void AddColor(Color col, float quantity, FootPrintsComponent component) { component.PrintsColor = component.ColorQuantity == 0f ? col : Color.InterpolateBetween(component.PrintsColor, col, component.ColorInterpolationFactor); component.ColorQuantity += quantity; } }