private void OnSlip(Entity<SleepingComponent> ent, ref SlipAttemptEvent args)
{
- args.Cancel();
+ args.NoSlip = true;
}
private void OnConsciousAttempt(Entity<SleepingComponent> ent, ref ConsciousAttemptEvent args)
--- /dev/null
+using Content.Shared.Clothing.EntitySystems;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Clothing.Components;
+
+/// <summary>
+/// When equipped, sets a max cap to the slowdown applied from contact speed modifiers. (E.g. glue puddles, kudzu).
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SpeedModifierContactCapClothingSystem))]
+public sealed partial class SpeedModifierContactCapClothingComponent : Component
+{
+ [DataField, AutoNetworkedField]
+ public float MaxContactSprintSlowdown = 1f;
+
+ [DataField, AutoNetworkedField]
+ public float MaxContactWalkSlowdown = 1f;
+}
--- /dev/null
+using Content.Shared.Clothing.Components;
+using Content.Shared.Inventory;
+using Content.Shared.Movement.Events;
+
+namespace Content.Shared.Clothing.EntitySystems;
+
+public sealed class SpeedModifierContactCapClothingSystem : EntitySystem
+{
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ SubscribeLocalEvent<SpeedModifierContactCapClothingComponent, InventoryRelayedEvent<GetSpeedModifierContactCapEvent>>(OnGetMaxSlow);
+ }
+
+ private void OnGetMaxSlow(Entity<SpeedModifierContactCapClothingComponent> ent, ref InventoryRelayedEvent<GetSpeedModifierContactCapEvent> args)
+ {
+ args.Args.SetIfMax(ent.Comp.MaxContactSprintSlowdown, ent.Comp.MaxContactWalkSlowdown);
+ }
+}
private void OnSlipAttempt(EntityUid uid, GodmodeComponent component, SlipAttemptEvent args)
{
- args.Cancel();
+ args.NoSlip = true;
}
private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args)
using Content.Shared.Gravity;
using Content.Shared.IdentityManagement.Components;
using Content.Shared.Inventory.Events;
+using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.NameModifier.EntitySystems;
using Content.Shared.Overlays;
// by-ref events
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, IsWeightlessEvent>(RefRelayInventoryEvent);
+ SubscribeLocalEvent<InventoryComponent, GetSpeedModifierContactCapEvent>(RefRelayInventoryEvent);
+ SubscribeLocalEvent<InventoryComponent, GetSlowedOverSlipperyModifierEvent>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, ModifySlowOnDamageSpeedEvent>(RefRelayInventoryEvent);
// Eye/vision events
--- /dev/null
+using Content.Shared.Inventory;
+
+namespace Content.Shared.Movement.Events;
+
+/// <summary>
+/// Raised on an entity to check if it has a max contact slowdown.
+/// </summary>
+[ByRefEvent]
+public record struct GetSpeedModifierContactCapEvent() : IInventoryRelayEvent
+{
+ SlotFlags IInventoryRelayEvent.TargetSlots => ~SlotFlags.POCKET;
+
+ public float MaxSprintSlowdown = 0f;
+
+ public float MaxWalkSlowdown = 0f;
+
+ public void SetIfMax(float valueSprint, float valueWalk)
+ {
+ MaxSprintSlowdown = MathF.Max(MaxSprintSlowdown, valueSprint);
+ MaxWalkSlowdown = MathF.Max(MaxWalkSlowdown, valueWalk);
+ }
+}
+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;
var entries = 0;
foreach (var ent in _physics.GetContactingEntities(uid, physicsComponent))
{
- if (!TryComp<SpeedModifierContactsComponent>(ent, out var slowContactsComponent))
- continue;
-
- if (_whitelistSystem.IsWhitelistPass(slowContactsComponent.IgnoreWhitelist, uid))
- continue;
-
- walkSpeed += slowContactsComponent.WalkSpeedModifier;
- sprintSpeed += slowContactsComponent.SprintSpeedModifier;
- remove = false;
- entries++;
+ bool speedModified = false;
+
+ if (TryComp<SpeedModifierContactsComponent>(ent, out var slowContactsComponent))
+ {
+ if (_whitelistSystem.IsWhitelistPass(slowContactsComponent.IgnoreWhitelist, uid))
+ continue;
+
+ 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)
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);
}
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);
}
}
--- /dev/null
+using Content.Shared.Inventory;
+
+namespace Content.Shared.Slippery;
+[ByRefEvent]
+public record struct GetSlowedOverSlipperyModifierEvent() : IInventoryRelayEvent
+{
+ SlotFlags IInventoryRelayEvent.TargetSlots => ~SlotFlags.POCKET;
+
+ public float SlowdownModifier = 1f;
+}
using Content.Shared.Database;
using Content.Shared.Inventory;
using Robust.Shared.Network;
+using Content.Shared.Movement.Components;
+using Content.Shared.Movement.Systems;
using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Content.Shared.StepTrigger.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
+using Robust.Shared.Physics.Events;
using Robust.Shared.Utility;
namespace Content.Shared.Slippery;
-[UsedImplicitly]
+[UsedImplicitly]
public sealed class SlipperySystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
+ [Dependency] private readonly SpeedModifierContactsSystem _speedModifier = default!;
public override void Initialize()
{
SubscribeLocalEvent<SlipperyComponent, StepTriggerAttemptEvent>(HandleAttemptCollide);
SubscribeLocalEvent<SlipperyComponent, StepTriggeredOffEvent>(HandleStepTrigger);
SubscribeLocalEvent<NoSlipComponent, SlipAttemptEvent>(OnNoSlipAttempt);
+ SubscribeLocalEvent<SlowedOverSlipperyComponent, SlipAttemptEvent>(OnSlowedOverSlipAttempt);
SubscribeLocalEvent<ThrownItemComponent, SlipCausingAttemptEvent>(OnThrownSlipAttempt);
// as long as slip-resistant mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer).
SubscribeLocalEvent<NoSlipComponent, InventoryRelayedEvent<SlipAttemptEvent>>((e, c, ev) => OnNoSlipAttempt(e, c, ev.Args));
+ SubscribeLocalEvent<SlowedOverSlipperyComponent, InventoryRelayedEvent<SlipAttemptEvent>>((e, c, ev) => OnSlowedOverSlipAttempt(e, c, ev.Args));
+ SubscribeLocalEvent<SlowedOverSlipperyComponent, InventoryRelayedEvent<GetSlowedOverSlipperyModifierEvent>>(OnGetSlowedOverSlipperyModifier);
+ SubscribeLocalEvent<SlipperyComponent, EndCollideEvent>(OnEntityExit);
}
private void HandleStepTrigger(EntityUid uid, SlipperyComponent component, ref StepTriggeredOffEvent args)
private static void OnNoSlipAttempt(EntityUid uid, NoSlipComponent component, SlipAttemptEvent args)
{
- args.Cancel();
+ args.NoSlip = true;
+ }
+
+ private void OnSlowedOverSlipAttempt(EntityUid uid, SlowedOverSlipperyComponent component, SlipAttemptEvent args)
+ {
+ args.SlowOverSlippery = true;
}
private void OnThrownSlipAttempt(EntityUid uid, ThrownItemComponent comp, ref SlipCausingAttemptEvent args)
args.Cancelled = true;
}
+ private void OnGetSlowedOverSlipperyModifier(EntityUid uid, SlowedOverSlipperyComponent comp, ref InventoryRelayedEvent<GetSlowedOverSlipperyModifierEvent> args)
+ {
+ args.Args.SlowdownModifier *= comp.SlowdownModifier;
+ }
+
+ private void OnEntityExit(EntityUid uid, SlipperyComponent component, ref EndCollideEvent args)
+ {
+ if (HasComp<SpeedModifiedByContactComponent>(args.OtherEntity))
+ _speedModifier.AddModifiedEntity(args.OtherEntity);
+ }
+
private bool CanSlip(EntityUid uid, EntityUid toSlip)
{
return !_container.IsEntityInContainer(uid)
var attemptEv = new SlipAttemptEvent();
RaiseLocalEvent(other, attemptEv);
- if (attemptEv.Cancelled)
+ if (attemptEv.SlowOverSlippery)
+ _speedModifier.AddModifiedEntity(other);
+
+ if (attemptEv.NoSlip)
return;
var attemptCausingEv = new SlipCausingAttemptEvent();
/// <summary>
/// Raised on an entity to determine if it can slip or not.
/// </summary>
-public sealed class SlipAttemptEvent : CancellableEntityEventArgs, IInventoryRelayEvent
+public sealed class SlipAttemptEvent : EntityEventArgs, IInventoryRelayEvent
{
+ public bool NoSlip;
+
+ public bool SlowOverSlippery;
+
public SlotFlags TargetSlots { get; } = SlotFlags.FEET;
}
--- /dev/null
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Slippery;
+
+/// <summary>
+/// Slows down the user when passing over an entity with <see cref="SlipperyComponent"/>. Does not prevent slipping, see <see cref="NoSlipComponent"/>.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SlipperySystem))]
+public sealed partial class SlowedOverSlipperyComponent : Component
+{
+ [DataField(required: true), AutoNetworkedField]
+ public float SlowdownModifier = 1f;
+}
- type: Clothing
sprite: Clothing/Shoes/Specific/galoshes.rsi
- type: NoSlip
+ - type: SlowedOverSlippery
+ slowdownModifier: 0.7
+ - type: SpeedModifierContactCapClothing
+ maxContactSprintSlowdown: 0.7
+ maxContactWalkSlowdown: 0.7
- type: entity
parent: [ClothingShoesBaseButcherable, BaseMajorContraband]