Skip to content

Commit

Permalink
ayo (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhailrake authored Nov 15, 2024
1 parent 53ec07a commit fdce70c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
43 changes: 37 additions & 6 deletions Content.Server/_Sunrise/Footprints/FootPrintsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -45,6 +51,7 @@ public override void Initialize()

SubscribeLocalEvent<FootprintEmitterComponent, ComponentStartup>(OnEmitterStartup);
SubscribeLocalEvent<FootprintEmitterComponent, MoveEvent>(OnEntityMove);
SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
}

/// <summary>
Expand All @@ -63,11 +70,11 @@ private void OnEmitterStartup(EntityUid uid, FootprintEmitterComponent component
/// </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 =
Expand All @@ -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<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
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/_Sunrise/Entities/Effects/puddle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@
- type: Puddle
solution: step
- type: Appearance
- type: TimedDespawn
lifetime: 360

0 comments on commit fdce70c

Please sign in to comment.