Add Galoshes slowdown over slippery surfaces (#30967)
* first draft * Fixed it all, just need to rename stuff * Rename and add comments * Clean-up * Access added
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Slippery;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
@@ -85,16 +88,37 @@ public sealed class SpeedModifierContactsSystem : EntitySystem
|
||||
var entries = 0;
|
||||
foreach (var ent in _physics.GetContactingEntities(uid, physicsComponent))
|
||||
{
|
||||
if (!TryComp<SpeedModifierContactsComponent>(ent, out var slowContactsComponent))
|
||||
continue;
|
||||
bool speedModified = false;
|
||||
|
||||
if (_whitelistSystem.IsWhitelistPass(slowContactsComponent.IgnoreWhitelist, uid))
|
||||
continue;
|
||||
if (TryComp<SpeedModifierContactsComponent>(ent, out var slowContactsComponent))
|
||||
{
|
||||
if (_whitelistSystem.IsWhitelistPass(slowContactsComponent.IgnoreWhitelist, uid))
|
||||
continue;
|
||||
|
||||
walkSpeed += slowContactsComponent.WalkSpeedModifier;
|
||||
sprintSpeed += slowContactsComponent.SprintSpeedModifier;
|
||||
remove = false;
|
||||
entries++;
|
||||
walkSpeed += slowContactsComponent.WalkSpeedModifier;
|
||||
sprintSpeed += slowContactsComponent.SprintSpeedModifier;
|
||||
speedModified = true;
|
||||
}
|
||||
|
||||
// SpeedModifierContactsComponent takes priority over SlowedOverSlipperyComponent, effectively overriding the slippery slow.
|
||||
if (TryComp<SlipperyComponent>(ent, out var slipperyComponent) && speedModified == false)
|
||||
{
|
||||
var evSlippery = new GetSlowedOverSlipperyModifierEvent();
|
||||
RaiseLocalEvent(uid, ref evSlippery);
|
||||
|
||||
if (evSlippery.SlowdownModifier != 1)
|
||||
{
|
||||
walkSpeed += evSlippery.SlowdownModifier;
|
||||
sprintSpeed += evSlippery.SlowdownModifier;
|
||||
speedModified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (speedModified)
|
||||
{
|
||||
remove = false;
|
||||
entries++;
|
||||
}
|
||||
}
|
||||
|
||||
if (entries > 0)
|
||||
@@ -102,6 +126,12 @@ public sealed class SpeedModifierContactsSystem : EntitySystem
|
||||
walkSpeed /= entries;
|
||||
sprintSpeed /= entries;
|
||||
|
||||
var evMax = new GetSpeedModifierContactCapEvent();
|
||||
RaiseLocalEvent(uid, ref evMax);
|
||||
|
||||
walkSpeed = MathF.Max(walkSpeed, evMax.MaxWalkSlowdown);
|
||||
sprintSpeed = MathF.Max(sprintSpeed, evMax.MaxSprintSlowdown);
|
||||
|
||||
args.ModifySpeed(walkSpeed, sprintSpeed);
|
||||
}
|
||||
|
||||
@@ -118,11 +148,19 @@ public sealed class SpeedModifierContactsSystem : EntitySystem
|
||||
|
||||
private void OnEntityEnter(EntityUid uid, SpeedModifierContactsComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
var otherUid = args.OtherEntity;
|
||||
if (!HasComp<MovementSpeedModifierComponent>(otherUid))
|
||||
AddModifiedEntity(args.OtherEntity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an entity to be checked for speed modification from contact with another entity.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity to be added.</param>
|
||||
public void AddModifiedEntity(EntityUid uid)
|
||||
{
|
||||
if (!HasComp<MovementSpeedModifierComponent>(uid))
|
||||
return;
|
||||
|
||||
EnsureComp<SpeedModifiedByContactComponent>(otherUid);
|
||||
_toUpdate.Add(otherUid);
|
||||
EnsureComp<SpeedModifiedByContactComponent>(uid);
|
||||
_toUpdate.Add(uid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user