10
10
using Robust . Server . GameObjects ;
11
11
using Robust . Shared . Map ;
12
12
using Robust . Shared . Map . Components ;
13
+ using Robust . Shared . Player ;
13
14
using Robust . Shared . Prototypes ;
14
15
15
16
namespace Content . Server . _CorvaxNext . Footprints ;
@@ -34,36 +35,26 @@ public sealed class FootprintSystem : EntitySystem
34
35
35
36
public override void Initialize ( )
36
37
{
37
- SubscribeLocalEvent < FootprintComponent , FootprintCleanEvent > ( OnAbsorbentPuddleInteract ) ;
38
+ SubscribeLocalEvent < FootprintComponent , FootprintCleanEvent > ( OnFootprintClean ) ;
38
39
39
40
SubscribeLocalEvent < FootprintOwnerComponent , MoveEvent > ( OnMove ) ;
40
41
41
42
SubscribeLocalEvent < PuddleComponent , MapInitEvent > ( OnMapInit ) ;
42
43
}
43
44
44
- private void OnAbsorbentPuddleInteract ( Entity < FootprintComponent > entity , ref FootprintCleanEvent e )
45
+ private void OnFootprintClean ( Entity < FootprintComponent > entity , ref FootprintCleanEvent e )
45
46
{
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 ) ;
63
48
}
64
49
65
50
private void OnMove ( Entity < FootprintOwnerComponent > entity , ref MoveEvent e )
66
51
{
52
+ if ( ! e . OldPosition . IsValid ( EntityManager ) )
53
+ return ;
54
+
55
+ if ( ! e . NewPosition . IsValid ( EntityManager ) )
56
+ return ;
57
+
67
58
var oldPosition = _transform . ToMapCoordinates ( e . OldPosition ) . Position ;
68
59
var newPosition = _transform . ToMapCoordinates ( e . NewPosition ) . Position ;
69
60
@@ -123,7 +114,7 @@ private bool TryPuddleInteraction(Entity<FootprintOwnerComponent> entity, Entity
123
114
124
115
_solution . TryTransferSolution ( puddleSolution . Value , solution . Value . Comp . Solution , GetFootprintVolume ( entity , solution . Value ) ) ;
125
116
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 ) ) ;
127
118
128
119
_solution . UpdateChemicals ( puddleSolution . Value , false ) ;
129
120
@@ -182,7 +173,7 @@ private void FootprintInteraction(Entity<FootprintOwnerComponent> entity, Entity
182
173
if ( ! TryGetNetEntity ( footprint , out var netFootprint ) )
183
174
return ;
184
175
185
- RaiseNetworkEvent ( new FootprintChangedEvent ( netFootprint . Value ) ) ;
176
+ RaiseNetworkEvent ( new FootprintChangedEvent ( netFootprint . Value ) , Filter . Pvs ( footprint . Value ) ) ;
186
177
}
187
178
188
179
private void OnMapInit ( Entity < PuddleComponent > entity , ref MapInitEvent e )
@@ -203,14 +194,21 @@ private void OnMapInit(Entity<PuddleComponent> entity, ref MapInitEvent e)
203
194
if ( ! TryGetAnchoredEntity < FootprintComponent > ( ( transform . GridUid . Value , gridComponent ) , tile , out var footprint ) )
204
195
return ;
205
196
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 ) )
207
205
return ;
208
206
209
207
footprintSolution = footprintSolution . Clone ( ) ;
210
208
211
209
Del ( footprint ) ;
212
210
213
- _puddle . TrySpillAt ( transform . Coordinates , footprintSolution , out _ , false ) ;
211
+ _puddle . TrySpillAt ( coordinates . Value , footprintSolution , out _ , false ) ;
214
212
}
215
213
216
214
private static FixedPoint2 GetFootprintVolume ( Entity < FootprintOwnerComponent > entity , Entity < SolutionComponent > solution )
0 commit comments