Reduce knocked down players tile friction (#11035)

This commit is contained in:
metalgearsloth
2022-09-11 16:49:10 +10:00
committed by GitHub
parent 47dd0ff2e8
commit 12e1a961d6
12 changed files with 80 additions and 124 deletions

View File

@@ -1,7 +1,6 @@
using Content.Shared.CCVar;
using Content.Shared.Gravity;
using Content.Shared.Movement;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;
@@ -16,13 +15,13 @@ using Robust.Shared.Utility;
namespace Content.Shared.Friction
{
public abstract class SharedTileFrictionController : VirtualController
public sealed class TileFrictionController : VirtualController
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
protected SharedMoverController Mover = default!;
[Dependency] private readonly SharedMoverController _mover = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
private float _stopSpeed;
private float _frictionModifier;
@@ -79,7 +78,10 @@ namespace Content.Shared.Friction
// Only apply friction when it's not a mob (or the mob doesn't have control)
if (prediction && !body.Predict ||
body.BodyStatus == BodyStatus.InAir ||
Mover.UseMobMovement(body.Owner)) continue;
_mover.UseMobMovement(body.Owner))
{
continue;
}
if (body.LinearVelocity.Equals(Vector2.Zero) && body.AngularVelocity.Equals(0f)) continue;
@@ -99,6 +101,11 @@ namespace Content.Shared.Friction
bodyModifier = frictionComp.Modifier;
}
var ev = new TileFrictionEvent(bodyModifier);
RaiseLocalEvent(body.Owner, ref ev);
bodyModifier = ev.Modifier;
// If we're sandwiched between 2 pullers reduce friction
// Might be better to make this dynamic and check how many are in the pull chain?
// Either way should be much faster for now.
@@ -143,7 +150,7 @@ namespace Content.Shared.Friction
var newSpeed = MathF.Max(0.0f, speed - drop);
newSpeed /= speed;
body.LinearVelocity *= newSpeed;
_physics.SetLinearVelocity(body, body.LinearVelocity * newSpeed);
}
private void ReduceAngularVelocity(bool prediction, PhysicsComponent body, float friction, float frameTime)
@@ -174,7 +181,7 @@ namespace Content.Shared.Friction
var newSpeed = MathF.Max(0.0f, speed - drop);
newSpeed /= speed;
body.AngularVelocity *= newSpeed;
_physics.SetAngularVelocity(body, body.AngularVelocity * newSpeed);
}
[Pure]

View File

@@ -1,7 +1,7 @@
namespace Content.Shared.Friction
{
[RegisterComponent]
[Access(typeof(SharedTileFrictionController))]
[Access(typeof(TileFrictionController))]
public sealed class TileFrictionModifierComponent : Component
{
/// <summary>