Skip to content

Commit 5396a26

Browse files
committed
Implement LocomotionState.GetFieldFlags()
1 parent 3688bdf commit 5396a26

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/MHServerEmu.Games/Entities/Locomotion/LocomotionState.cs

+72
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,78 @@ public static bool SerializeFrom(Archive archive, LocomotionState state, Locomot
295295
return success;
296296
}
297297

298+
public static LocomotionMessageFlags GetFieldFlags(LocomotionState currentState, LocomotionState previousState, bool withPathNodes)
299+
{
300+
if (currentState == null) return LocomotionMessageFlags.NoLocomotionState;
301+
302+
LocomotionMessageFlags flags = LocomotionMessageFlags.None;
303+
304+
if (previousState != null)
305+
{
306+
// If we have a previous state, it means we are sending a relative update that contains only what has changed
307+
flags |= LocomotionMessageFlags.RelativeToPreviousState;
308+
309+
if (currentState.LocomotionFlags != previousState.LocomotionFlags)
310+
flags |= LocomotionMessageFlags.HasLocomotionFlags;
311+
312+
if (currentState.Method != previousState.Method)
313+
flags |= LocomotionMessageFlags.HasMethod;
314+
315+
if (currentState.BaseMoveSpeed != previousState.BaseMoveSpeed)
316+
flags |= LocomotionMessageFlags.HasMoveSpeed;
317+
318+
if (currentState.Height != previousState.Height)
319+
flags |= LocomotionMessageFlags.HasHeight;
320+
321+
if (currentState.FollowEntityId != previousState.FollowEntityId)
322+
flags |= LocomotionMessageFlags.HasFollowEntityId;
323+
324+
if (currentState.FollowEntityRangeStart != previousState.FollowEntityRangeStart)
325+
flags |= LocomotionMessageFlags.HasFollowEntityRange;
326+
327+
if (withPathNodes)
328+
{
329+
bool isLocomoting = currentState.LocomotionFlags.HasFlag(LocomotionFlags.IsLocomoting);
330+
bool isLooking = currentState.LocomotionFlags.HasFlag(LocomotionFlags.IsLooking);
331+
332+
if (isLocomoting || isLooking)
333+
flags |= LocomotionMessageFlags.UpdatePathNodes;
334+
else if ((previousState.LocomotionFlags.HasFlag(LocomotionFlags.IsLocomoting) && isLocomoting == false)
335+
|| (previousState.LocomotionFlags.HasFlag(LocomotionFlags.IsLooking) && isLooking == false))
336+
{
337+
// If we were locomoting or looking, and no longer are, flag the current locomotion state as finished
338+
flags |= LocomotionMessageFlags.LocomotionFinished;
339+
}
340+
}
341+
}
342+
else
343+
{
344+
// If no previous state is provided, it means we are sending a full locomotion state (we still omit default values)
345+
if (currentState.LocomotionFlags != LocomotionFlags.None)
346+
flags |= LocomotionMessageFlags.HasLocomotionFlags;
347+
348+
if (currentState.Method != LocomotorMethod.Ground)
349+
flags |= LocomotionMessageFlags.HasMethod;
350+
351+
if (currentState.BaseMoveSpeed != 0f)
352+
flags |= LocomotionMessageFlags.HasMoveSpeed;
353+
354+
if (currentState.Height != 0)
355+
flags |= LocomotionMessageFlags.HasHeight;
356+
357+
if (currentState.FollowEntityId != 0)
358+
flags |= LocomotionMessageFlags.HasFollowEntityId;
359+
360+
if (currentState.FollowEntityRangeStart != 0f)
361+
flags |= LocomotionMessageFlags.HasFollowEntityRange;
362+
363+
if (withPathNodes)
364+
flags |= LocomotionMessageFlags.UpdatePathNodes;
365+
}
366+
367+
return flags;
368+
}
369+
298370
public void Decode(CodedInputStream stream, LocomotionMessageFlags flags)
299371
{
300372
PathNodes.Clear();

0 commit comments

Comments
 (0)