diff --git a/Content.Server/_Sunrise/Footprints/FootPrintsSystem.cs b/Content.Server/_Sunrise/Footprints/FootPrintsSystem.cs index a610b1c0c77..9a24f41a753 100644 --- a/Content.Server/_Sunrise/Footprints/FootPrintsSystem.cs +++ b/Content.Server/_Sunrise/Footprints/FootPrintsSystem.cs @@ -8,6 +8,8 @@ using Content.Shared.Standing; using Robust.Shared.Map; using Robust.Shared.Random; +using System.Linq; +using Content.Shared.GameTicking; namespace Content.Server._Sunrise.Footprints; @@ -31,6 +33,10 @@ public sealed class FootprintSystem : EntitySystem private EntityQuery _appearanceQuery; #endregion + // Dictionary to track footprints per tile to prevent overcrowding + private readonly Dictionary<(EntityUid GridId, Vector2i TilePosition), HashSet> _tileFootprints = new(); + private const int MaxFootprintsPerTile = 2; // Maximum footprints allowed per tile + #region Initialization /// /// Initializes the footprint system and sets up required queries and subscriptions. @@ -45,6 +51,7 @@ public override void Initialize() SubscribeLocalEvent(OnEmitterStartup); SubscribeLocalEvent(OnEntityMove); + SubscribeNetworkEvent(Reset); } /// @@ -63,11 +70,11 @@ private void OnEmitterStartup(EntityUid uid, FootprintEmitterComponent component /// private void OnEntityMove(EntityUid uid, FootprintEmitterComponent emitter, ref MoveEvent args) { - // Check if footprints should be created. + // Check if footprints should be created if (emitter.TrackColor.A <= 0f || !_transformQuery.TryComp(uid, out var transform) || !_mobStateQuery.TryComp(uid, out var mobState) - || !_mapManager.TryFindGridAt(_transformSystem.GetMapCoordinates((uid, transform)), out var gridUid, out _)) + || !_mapManager.TryFindGridAt(_transformSystem.GetMapCoordinates((uid, transform)), out var gridUid, out var grid)) return; var isBeingDragged = @@ -81,17 +88,41 @@ mobState.CurrentThresholdState is MobState.Critical or MobState.Dead || if (!(distanceMoved > requiredDistance)) return; + var tilePos = grid.TileIndicesFor(transform.Coordinates); + var tileKey = (gridUid, tilePos); + + if (_tileFootprints.TryGetValue(tileKey, out var existingPrints) && + existingPrints.Count >= MaxFootprintsPerTile) + { + if (existingPrints.Count > 0) + { + var oldestPrint = existingPrints.First(); + existingPrints.Remove(oldestPrint); + QueueDel(oldestPrint); + } + } + emitter.IsRightStep = !emitter.IsRightStep; - // Create new footprint entity. + // Create new footprint entity var footprintEntity = SpawnFootprint(gridUid, emitter, uid, transform, isBeingDragged); - // Update footprint position and transfer reagents if applicable. - UpdateFootprint(footprintEntity, emitter, transform, isBeingDragged); + // Add the new footprint to tile tracking + if (!_tileFootprints.ContainsKey(tileKey)) + _tileFootprints[tileKey] = new HashSet(); - // Update emitter state. + _tileFootprints[tileKey].Add(footprintEntity); + + // Update footprint and emitter state + UpdateFootprint(footprintEntity, emitter, transform, isBeingDragged); UpdateEmitterState(emitter, transform); } + + private void Reset(RoundRestartCleanupEvent msg) + { + _tileFootprints.Clear(); + } + #endregion #region Footprint Creation and Management diff --git a/Resources/Prototypes/_Sunrise/Entities/Effects/puddle.yml b/Resources/Prototypes/_Sunrise/Entities/Effects/puddle.yml index 7ce84f9ec61..b09e15e3ba5 100644 --- a/Resources/Prototypes/_Sunrise/Entities/Effects/puddle.yml +++ b/Resources/Prototypes/_Sunrise/Entities/Effects/puddle.yml @@ -35,3 +35,5 @@ - type: Puddle solution: step - type: Appearance + - type: TimedDespawn + lifetime: 360