Skip to content

Commit 0b94f7c

Browse files
committed
FUCKING ENTITYTEST
1 parent a273f31 commit 0b94f7c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

Content.Server/_EE/FootPrint/FootPrintsSystem.cs

+24-6
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,35 @@ private void OnFootPrintInit(Entity<FootPrintComponent> ent, ref ComponentInit a
163163
/// </summary>
164164
private void OnFootPrintRemove(Entity<FootPrintComponent> ent, ref ComponentRemove args)
165165
{
166-
if (!TryGetTilePos(ent.Owner, out var tilePos))
167-
return;
166+
// Try to get tile pos if entity is still valid
167+
Vector2i? tilePos = null;
168+
if (!Deleted(ent) && !EntityManager.IsQueuedForDeletion(ent) && Transform(ent).ParentUid.IsValid())
169+
{
170+
TryGetTilePos(ent.Owner, out var pos);
171+
tilePos = pos;
172+
}
173+
174+
// If we couldn't get tile pos, search all tiles to find and remove this footprint
175+
if (tilePos == null)
176+
{
177+
foreach (var (pos, prints) in _footprintsPerTile)
178+
{
179+
if (!prints.Contains(ent.Owner))
180+
continue;
181+
182+
tilePos = pos;
183+
break;
184+
}
185+
}
168186

169-
if (_footprintsPerTile.TryGetValue(tilePos, out var footprints))
187+
// Clean up the footprint tracking if we found it
188+
if (tilePos.HasValue && _footprintsPerTile.TryGetValue(tilePos.Value, out var footprints))
170189
{
171-
// Create a new queue without the removed footprint
172190
var newQueue = new Queue<EntityUid>(footprints.Where(x => x != ent.Owner));
173191
if (newQueue.Count > 0)
174-
_footprintsPerTile[tilePos] = newQueue;
192+
_footprintsPerTile[tilePos.Value] = newQueue;
175193
else
176-
_footprintsPerTile.Remove(tilePos);
194+
_footprintsPerTile.Remove(tilePos.Value);
177195
}
178196
}
179197

0 commit comments

Comments
 (0)