Skip to content

Commit 6f43a1d

Browse files
authored
footprint fix (#266)
* Fixes * Crash fix * Weh * Valid
1 parent 6313c96 commit 6f43a1d

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

Content.Server/_CorvaxNext/Footprints/FootprintSystem.cs

+21-23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Robust.Server.GameObjects;
1111
using Robust.Shared.Map;
1212
using Robust.Shared.Map.Components;
13+
using Robust.Shared.Player;
1314
using Robust.Shared.Prototypes;
1415

1516
namespace Content.Server._CorvaxNext.Footprints;
@@ -34,36 +35,26 @@ public sealed class FootprintSystem : EntitySystem
3435

3536
public override void Initialize()
3637
{
37-
SubscribeLocalEvent<FootprintComponent, FootprintCleanEvent>(OnAbsorbentPuddleInteract);
38+
SubscribeLocalEvent<FootprintComponent, FootprintCleanEvent>(OnFootprintClean);
3839

3940
SubscribeLocalEvent<FootprintOwnerComponent, MoveEvent>(OnMove);
4041

4142
SubscribeLocalEvent<PuddleComponent, MapInitEvent>(OnMapInit);
4243
}
4344

44-
private void OnAbsorbentPuddleInteract(Entity<FootprintComponent> entity, ref FootprintCleanEvent e)
45+
private void OnFootprintClean(Entity<FootprintComponent> entity, ref FootprintCleanEvent e)
4546
{
46-
if (!_solution.TryGetSolution(entity.Owner, FootprintSolution, out _, out var puddleSolution))
47-
return;
48-
49-
var color = puddleSolution.GetColor(_prototype);
50-
51-
for (var i = 0; i < entity.Comp.Footprints.Count; i++)
52-
entity.Comp.Footprints[i] = entity.Comp.Footprints[i] with
53-
{
54-
Color = color
55-
};
56-
57-
Dirty(entity);
58-
59-
if (!TryGetNetEntity(entity, out var netFootprint))
60-
return;
61-
62-
RaiseNetworkEvent(new FootprintChangedEvent(netFootprint.Value));
47+
ToPuddle(entity);
6348
}
6449

6550
private void OnMove(Entity<FootprintOwnerComponent> entity, ref MoveEvent e)
6651
{
52+
if (!e.OldPosition.IsValid(EntityManager))
53+
return;
54+
55+
if (!e.NewPosition.IsValid(EntityManager))
56+
return;
57+
6758
var oldPosition = _transform.ToMapCoordinates(e.OldPosition).Position;
6859
var newPosition = _transform.ToMapCoordinates(e.NewPosition).Position;
6960

@@ -123,7 +114,7 @@ private bool TryPuddleInteraction(Entity<FootprintOwnerComponent> entity, Entity
123114

124115
_solution.TryTransferSolution(puddleSolution.Value, solution.Value.Comp.Solution, GetFootprintVolume(entity, solution.Value));
125116

126-
_solution.TryTransferSolution(solution.Value, puddleSolution.Value.Comp.Solution, (standing ? entity.Comp.MaxFootVolume : entity.Comp.MaxBodyVolume) - solution.Value.Comp.Solution.Volume);
117+
_solution.TryTransferSolution(solution.Value, puddleSolution.Value.Comp.Solution, FixedPoint2.Max(0, (standing ? entity.Comp.MaxFootVolume : entity.Comp.MaxBodyVolume) - solution.Value.Comp.Solution.Volume));
127118

128119
_solution.UpdateChemicals(puddleSolution.Value, false);
129120

@@ -182,7 +173,7 @@ private void FootprintInteraction(Entity<FootprintOwnerComponent> entity, Entity
182173
if (!TryGetNetEntity(footprint, out var netFootprint))
183174
return;
184175

185-
RaiseNetworkEvent(new FootprintChangedEvent(netFootprint.Value));
176+
RaiseNetworkEvent(new FootprintChangedEvent(netFootprint.Value), Filter.Pvs(footprint.Value));
186177
}
187178

188179
private void OnMapInit(Entity<PuddleComponent> entity, ref MapInitEvent e)
@@ -203,14 +194,21 @@ private void OnMapInit(Entity<PuddleComponent> entity, ref MapInitEvent e)
203194
if (!TryGetAnchoredEntity<FootprintComponent>((transform.GridUid.Value, gridComponent), tile, out var footprint))
204195
return;
205196

206-
if (!_solution.TryGetSolution(footprint.Value.Owner, FootprintSolution, out _, out var footprintSolution))
197+
ToPuddle(footprint.Value, transform.Coordinates);
198+
}
199+
200+
private void ToPuddle(EntityUid footprint, EntityCoordinates? coordinates = null)
201+
{
202+
coordinates ??= Transform(footprint).Coordinates;
203+
204+
if (!_solution.TryGetSolution(footprint, FootprintSolution, out _, out var footprintSolution))
207205
return;
208206

209207
footprintSolution = footprintSolution.Clone();
210208

211209
Del(footprint);
212210

213-
_puddle.TrySpillAt(transform.Coordinates, footprintSolution, out _, false);
211+
_puddle.TrySpillAt(coordinates.Value, footprintSolution, out _, false);
214212
}
215213

216214
private static FixedPoint2 GetFootprintVolume(Entity<FootprintOwnerComponent> entity, Entity<SolutionComponent> solution)

0 commit comments

Comments
 (0)