ayo (#635)
This commit is contained in:
parent
53ec07a03a
commit
fdce70c8d4
2 changed files with 39 additions and 6 deletions
|
|
@ -8,6 +8,8 @@ using Content.Shared.Mobs.Components;
|
|||
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<AppearanceComponent> _appearanceQuery;
|
||||
#endregion
|
||||
|
||||
// Dictionary to track footprints per tile to prevent overcrowding
|
||||
private readonly Dictionary<(EntityUid GridId, Vector2i TilePosition), HashSet<EntityUid>> _tileFootprints = new();
|
||||
private const int MaxFootprintsPerTile = 2; // Maximum footprints allowed per tile
|
||||
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Initializes the footprint system and sets up required queries and subscriptions.
|
||||
|
|
@ -45,6 +51,7 @@ public sealed class FootprintSystem : EntitySystem
|
|||
|
||||
SubscribeLocalEvent<FootprintEmitterComponent, ComponentStartup>(OnEmitterStartup);
|
||||
SubscribeLocalEvent<FootprintEmitterComponent, MoveEvent>(OnEntityMove);
|
||||
SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -63,11 +70,11 @@ public sealed class FootprintSystem : EntitySystem
|
|||
/// </summary>
|
||||
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 @@ public sealed class FootprintSystem : EntitySystem
|
|||
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<EntityUid>();
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -35,3 +35,5 @@
|
|||
- type: Puddle
|
||||
solution: step
|
||||
- type: Appearance
|
||||
- type: TimedDespawn
|
||||
lifetime: 360
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue