2021-11-22 20:36:50 +01:00
|
|
|
using Content.Shared.Administration.Logs;
|
2021-11-28 14:56:53 +01:00
|
|
|
using Content.Shared.Database;
|
2022-01-10 17:37:20 +13:00
|
|
|
using Content.Shared.Inventory;
|
2024-03-20 12:57:39 +01:00
|
|
|
using Robust.Shared.Network;
|
2024-08-23 11:59:51 +02:00
|
|
|
using Content.Shared.Movement.Components;
|
|
|
|
|
using Content.Shared.Movement.Systems;
|
2024-03-20 12:57:39 +01:00
|
|
|
using Content.Shared.Popups;
|
2021-10-15 14:45:04 -07:00
|
|
|
using Content.Shared.StatusEffect;
|
2022-07-10 02:28:37 -07:00
|
|
|
using Content.Shared.StepTrigger.Systems;
|
2021-07-21 22:13:58 +10:00
|
|
|
using Content.Shared.Stunnable;
|
2024-03-20 12:57:39 +01:00
|
|
|
using Content.Shared.Throwing;
|
2021-07-21 22:13:58 +10:00
|
|
|
using JetBrains.Annotations;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2021-07-21 22:13:58 +10:00
|
|
|
using Robust.Shared.Containers;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
2022-10-17 02:49:22 +11:00
|
|
|
using Robust.Shared.Physics.Systems;
|
2024-08-23 11:59:51 +02:00
|
|
|
using Robust.Shared.Physics.Events;
|
2024-02-03 09:10:50 +01:00
|
|
|
using Robust.Shared.Utility;
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
namespace Content.Shared.Slippery;
|
|
|
|
|
|
2024-08-23 11:59:51 +02:00
|
|
|
[UsedImplicitly]
|
2023-03-23 18:54:14 +03:00
|
|
|
public sealed class SlipperySystem : EntitySystem
|
2021-07-21 22:13:58 +10:00
|
|
|
{
|
2023-03-23 18:54:14 +03:00
|
|
|
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
[Dependency] private readonly SharedStunSystem _stun = default!;
|
|
|
|
|
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
|
|
|
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
|
|
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
2024-08-23 11:59:51 +02:00
|
|
|
[Dependency] private readonly SpeedModifierContactsSystem _speedModifier = default!;
|
2023-03-23 18:54:14 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
2021-07-21 22:13:58 +10:00
|
|
|
{
|
2023-03-23 18:54:14 +03:00
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<SlipperyComponent, StepTriggerAttemptEvent>(HandleAttemptCollide);
|
2024-03-24 07:33:45 +02:00
|
|
|
SubscribeLocalEvent<SlipperyComponent, StepTriggeredOffEvent>(HandleStepTrigger);
|
2023-03-23 18:54:14 +03:00
|
|
|
SubscribeLocalEvent<NoSlipComponent, SlipAttemptEvent>(OnNoSlipAttempt);
|
2024-08-23 11:59:51 +02:00
|
|
|
SubscribeLocalEvent<SlowedOverSlipperyComponent, SlipAttemptEvent>(OnSlowedOverSlipAttempt);
|
2024-03-20 12:57:39 +01:00
|
|
|
SubscribeLocalEvent<ThrownItemComponent, SlipCausingAttemptEvent>(OnThrownSlipAttempt);
|
2023-03-23 18:54:14 +03:00
|
|
|
// 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));
|
2024-08-23 11:59:51 +02:00
|
|
|
SubscribeLocalEvent<SlowedOverSlipperyComponent, InventoryRelayedEvent<SlipAttemptEvent>>((e, c, ev) => OnSlowedOverSlipAttempt(e, c, ev.Args));
|
|
|
|
|
SubscribeLocalEvent<SlowedOverSlipperyComponent, InventoryRelayedEvent<GetSlowedOverSlipperyModifierEvent>>(OnGetSlowedOverSlipperyModifier);
|
|
|
|
|
SubscribeLocalEvent<SlipperyComponent, EndCollideEvent>(OnEntityExit);
|
2023-03-23 18:54:14 +03:00
|
|
|
}
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2024-03-24 07:33:45 +02:00
|
|
|
private void HandleStepTrigger(EntityUid uid, SlipperyComponent component, ref StepTriggeredOffEvent args)
|
2023-03-23 18:54:14 +03:00
|
|
|
{
|
|
|
|
|
TrySlip(uid, component, args.Tripper);
|
|
|
|
|
}
|
2021-10-24 23:43:49 -07:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
private void HandleAttemptCollide(
|
|
|
|
|
EntityUid uid,
|
|
|
|
|
SlipperyComponent component,
|
|
|
|
|
ref StepTriggerAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Continue |= CanSlip(uid, args.Tripper);
|
|
|
|
|
}
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
private static void OnNoSlipAttempt(EntityUid uid, NoSlipComponent component, SlipAttemptEvent args)
|
|
|
|
|
{
|
2024-08-23 11:59:51 +02:00
|
|
|
args.NoSlip = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSlowedOverSlipAttempt(EntityUid uid, SlowedOverSlipperyComponent component, SlipAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.SlowOverSlippery = true;
|
2023-03-23 18:54:14 +03:00
|
|
|
}
|
2021-09-06 23:49:05 +10:00
|
|
|
|
2024-03-20 12:57:39 +01:00
|
|
|
private void OnThrownSlipAttempt(EntityUid uid, ThrownItemComponent comp, ref SlipCausingAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 11:59:51 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
private bool CanSlip(EntityUid uid, EntityUid toSlip)
|
|
|
|
|
{
|
|
|
|
|
return !_container.IsEntityInContainer(uid)
|
|
|
|
|
&& _statusEffects.CanApplyEffect(toSlip, "Stun"); //Should be KnockedDown instead?
|
|
|
|
|
}
|
2022-05-01 01:02:29 -05:00
|
|
|
|
2024-05-11 21:01:58 -05:00
|
|
|
public void TrySlip(EntityUid uid, SlipperyComponent component, EntityUid other, bool requiresContact = true)
|
2023-03-23 18:54:14 +03:00
|
|
|
{
|
2024-02-01 11:39:10 +01:00
|
|
|
if (HasComp<KnockedDownComponent>(other) && !component.SuperSlippery)
|
2023-03-23 18:54:14 +03:00
|
|
|
return;
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
var attemptEv = new SlipAttemptEvent();
|
|
|
|
|
RaiseLocalEvent(other, attemptEv);
|
2024-08-23 11:59:51 +02:00
|
|
|
if (attemptEv.SlowOverSlippery)
|
|
|
|
|
_speedModifier.AddModifiedEntity(other);
|
|
|
|
|
|
|
|
|
|
if (attemptEv.NoSlip)
|
2023-03-23 18:54:14 +03:00
|
|
|
return;
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2024-03-20 12:57:39 +01:00
|
|
|
var attemptCausingEv = new SlipCausingAttemptEvent();
|
|
|
|
|
RaiseLocalEvent(uid, ref attemptCausingEv);
|
|
|
|
|
if (attemptCausingEv.Cancelled)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
var ev = new SlipEvent(other);
|
|
|
|
|
RaiseLocalEvent(uid, ref ev);
|
2021-12-07 09:18:07 +03:00
|
|
|
|
2024-02-01 11:39:10 +01:00
|
|
|
if (TryComp(other, out PhysicsComponent? physics) && !HasComp<SlidingComponent>(other))
|
|
|
|
|
{
|
2023-03-23 18:54:14 +03:00
|
|
|
_physics.SetLinearVelocity(other, physics.LinearVelocity * component.LaunchForwardsMultiplier, body: physics);
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2024-05-11 21:01:58 -05:00
|
|
|
if (component.SuperSlippery && requiresContact)
|
2024-02-03 09:10:50 +01:00
|
|
|
{
|
|
|
|
|
var sliding = EnsureComp<SlidingComponent>(other);
|
|
|
|
|
sliding.CollidingEntities.Add(uid);
|
|
|
|
|
DebugTools.Assert(_physics.GetContactingEntities(other, physics).Contains(uid));
|
|
|
|
|
}
|
2024-02-01 11:39:10 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
var playSound = !_statusEffects.HasStatusEffect(other, "KnockedDown");
|
2021-11-22 20:36:50 +01:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
_stun.TryParalyze(other, TimeSpan.FromSeconds(component.ParalyzeTime), true);
|
2022-11-15 12:30:59 +01:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
// Preventing from playing the slip sound when you are already knocked down.
|
|
|
|
|
if (playSound)
|
2022-11-15 12:30:59 +01:00
|
|
|
{
|
2023-03-23 18:54:14 +03:00
|
|
|
_audio.PlayPredicted(component.SlipSound, other, other);
|
2022-11-15 12:30:59 +01:00
|
|
|
}
|
2023-03-23 18:54:14 +03:00
|
|
|
|
|
|
|
|
_adminLogger.Add(LogType.Slip, LogImpact.Low,
|
|
|
|
|
$"{ToPrettyString(other):mob} slipped on collision with {ToPrettyString(uid):entity}");
|
2021-07-21 22:13:58 +10:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-23 18:54:14 +03:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Raised on an entity to determine if it can slip or not.
|
|
|
|
|
/// </summary>
|
2024-08-23 11:59:51 +02:00
|
|
|
public sealed class SlipAttemptEvent : EntityEventArgs, IInventoryRelayEvent
|
2023-03-23 18:54:14 +03:00
|
|
|
{
|
2024-08-23 11:59:51 +02:00
|
|
|
public bool NoSlip;
|
|
|
|
|
|
|
|
|
|
public bool SlowOverSlippery;
|
|
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
public SlotFlags TargetSlots { get; } = SlotFlags.FEET;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 18:07:03 +12:00
|
|
|
/// <summary>
|
2024-03-20 12:57:39 +01:00
|
|
|
/// Raised on an entity that is causing the slip event (e.g, the banana peel), to determine if the slip attempt should be cancelled.
|
2023-04-17 18:07:03 +12:00
|
|
|
/// </summary>
|
2024-03-20 12:57:39 +01:00
|
|
|
/// <param name="Cancelled">If the slip should be cancelled</param>
|
|
|
|
|
[ByRefEvent]
|
|
|
|
|
public record struct SlipCausingAttemptEvent (bool Cancelled);
|
|
|
|
|
|
|
|
|
|
/// Raised on an entity that CAUSED some other entity to slip (e.g., the banana peel).
|
|
|
|
|
/// <param name="Slipped">The entity being slipped</param>
|
2023-03-23 18:54:14 +03:00
|
|
|
[ByRefEvent]
|
|
|
|
|
public readonly record struct SlipEvent(EntityUid Slipped);
|