Files
wwdpublic/Content.Server/Fluids/EntitySystems/AbsorbentSystem.Footprints.cs
VMSolidus 8d59c57099 Footprints Performance Updates (#1439)
# Description

This is a port of https://github.com/Fansana/floofstation1/pull/445
Except I despise that this wasn't upstreamed so much that I didn't even
cherrypick it.

# Changelog

🆑
- add: Footprints are now cleaned in a small radius around the mouse
cursor when mopping them.

(cherry picked from commit 11678af96950f6af75f7effef40fc92a7af33350)
2025-01-14 01:31:23 +03:00

42 lines
1.7 KiB
C#

using System.Linq;
using Content.Shared.Chemistry.Components;
using Content.Shared.Fluids;
using Content.Shared.FootPrint;
namespace Content.Server.Fluids.EntitySystems;
public sealed partial class AbsorbentSystem
{
[Dependency] private readonly EntityLookupSystem _lookup = default!;
/// <summary>
/// Tries to clean a number of footprints in a range determined by the component. Returns the number of cleaned footprints.
/// </summary>
private int TryCleanNearbyFootprints(EntityUid user, EntityUid used, Entity<AbsorbentComponent> target, Entity<SolutionComponent> absorbentSoln)
{
var footprintQuery = GetEntityQuery<FootPrintComponent>();
var targetCoords = Transform(target).Coordinates;
var entities = _lookup.GetEntitiesInRange<FootPrintComponent>(targetCoords, target.Comp.FootprintCleaningRange, LookupFlags.Uncontained);
// Take up to [MaxCleanedFootprints] footprints closest to the target
var cleaned = entities.AsEnumerable()
.Select(uid => (uid, dst: Transform(uid).Coordinates.TryDistance(EntityManager, _transform, targetCoords, out var dst) ? dst : 0f))
.Where(ent => ent.dst > 0f)
.OrderBy(ent => ent.dst)
.Select(ent => (ent.uid, comp: footprintQuery.GetComponent(ent.uid)));
// And try to interact with each one of them, ignoring useDelay
var processed = 0;
foreach (var (uid, footprintComp) in cleaned)
{
if (TryPuddleInteract(user, used, uid, target.Comp, useDelay: null, absorbentSoln))
processed++;
if (processed >= target.Comp.MaxCleanedFootprints)
break;
}
return processed;
}
}