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 Content.Shared.Standing;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
using System.Linq;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
|
|
||||||
namespace Content.Server._Sunrise.Footprints;
|
namespace Content.Server._Sunrise.Footprints;
|
||||||
|
|
||||||
|
|
@ -31,6 +33,10 @@ public sealed class FootprintSystem : EntitySystem
|
||||||
private EntityQuery<AppearanceComponent> _appearanceQuery;
|
private EntityQuery<AppearanceComponent> _appearanceQuery;
|
||||||
#endregion
|
#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
|
#region Initialization
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the footprint system and sets up required queries and subscriptions.
|
/// 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, ComponentStartup>(OnEmitterStartup);
|
||||||
SubscribeLocalEvent<FootprintEmitterComponent, MoveEvent>(OnEntityMove);
|
SubscribeLocalEvent<FootprintEmitterComponent, MoveEvent>(OnEntityMove);
|
||||||
|
SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -63,11 +70,11 @@ public sealed class FootprintSystem : EntitySystem
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnEntityMove(EntityUid uid, FootprintEmitterComponent emitter, ref MoveEvent args)
|
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
|
if (emitter.TrackColor.A <= 0f
|
||||||
|| !_transformQuery.TryComp(uid, out var transform)
|
|| !_transformQuery.TryComp(uid, out var transform)
|
||||||
|| !_mobStateQuery.TryComp(uid, out var mobState)
|
|| !_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;
|
return;
|
||||||
|
|
||||||
var isBeingDragged =
|
var isBeingDragged =
|
||||||
|
|
@ -81,17 +88,41 @@ public sealed class FootprintSystem : EntitySystem
|
||||||
if (!(distanceMoved > requiredDistance))
|
if (!(distanceMoved > requiredDistance))
|
||||||
return;
|
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;
|
emitter.IsRightStep = !emitter.IsRightStep;
|
||||||
|
|
||||||
// Create new footprint entity.
|
// Create new footprint entity
|
||||||
var footprintEntity = SpawnFootprint(gridUid, emitter, uid, transform, isBeingDragged);
|
var footprintEntity = SpawnFootprint(gridUid, emitter, uid, transform, isBeingDragged);
|
||||||
|
|
||||||
// Update footprint position and transfer reagents if applicable.
|
// Add the new footprint to tile tracking
|
||||||
UpdateFootprint(footprintEntity, emitter, transform, isBeingDragged);
|
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);
|
UpdateEmitterState(emitter, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Reset(RoundRestartCleanupEvent msg)
|
||||||
|
{
|
||||||
|
_tileFootprints.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Footprint Creation and Management
|
#region Footprint Creation and Management
|
||||||
|
|
|
||||||
|
|
@ -35,3 +35,5 @@
|
||||||
- type: Puddle
|
- type: Puddle
|
||||||
solution: step
|
solution: step
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
|
- type: TimedDespawn
|
||||||
|
lifetime: 360
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue