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;
|
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-01-28 18:37:24 +07:00
|
|
|
using Content.Shared._White;
|
|
|
|
|
using Content.Shared._White.Mood;
|
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;
|
2023-10-19 02:32:18 +09:00
|
|
|
using Robust.Shared.Configuration;
|
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-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;
|
|
|
|
|
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
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!;
|
2024-03-26 15:52:23 +07:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
|
|
|
|
|
2023-10-19 02:32:18 +09:00
|
|
|
// WD START
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
|
|
|
|
|
|
private float SlipPowerModifier { get; set; }
|
|
|
|
|
// WD END
|
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-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).
|
2024-03-26 15:52:23 +07:00
|
|
|
SubscribeLocalEvent<NoSlipComponent, InventoryRelayedEvent<SlipAttemptEvent>>((e, c, ev) =>
|
|
|
|
|
OnNoSlipAttempt(e, c, ev.Args));
|
2023-10-19 02:32:18 +09:00
|
|
|
|
|
|
|
|
_cfg.OnValueChanged(WhiteCVars.SlipPowerModifier, x => SlipPowerModifier = x, true); // WD
|
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)
|
|
|
|
|
{
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
private bool CanSlip(EntityUid uid, EntityUid toSlip)
|
|
|
|
|
{
|
|
|
|
|
return !_container.IsEntityInContainer(uid)
|
2024-03-26 15:52:23 +07:00
|
|
|
&& _statusEffects.CanApplyEffect(toSlip, "Stun"); //Should be KnockedDown instead?
|
2023-03-23 18:54:14 +03:00
|
|
|
}
|
2022-05-01 01:02:29 -05:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
private void TrySlip(EntityUid uid, SlipperyComponent component, EntityUid other)
|
|
|
|
|
{
|
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);
|
|
|
|
|
if (attemptEv.Cancelled)
|
|
|
|
|
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))
|
|
|
|
|
{
|
2024-03-26 15:52:23 +07:00
|
|
|
_physics.SetLinearVelocity(other,
|
|
|
|
|
physics.LinearVelocity * component.LaunchForwardsMultiplier * SlipPowerModifier, body: physics);
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2024-02-01 11:39:10 +01:00
|
|
|
if (component.SuperSlippery)
|
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
|
|
|
}
|
2021-07-21 22:13:58 +10:00
|
|
|
|
2023-03-23 18:54:14 +03:00
|
|
|
var playSound = !_statusEffects.HasStatusEffect(other, "KnockedDown");
|
2021-11-22 20:36:50 +01:00
|
|
|
|
2023-10-19 02:32:18 +09:00
|
|
|
_stun.TryParalyze(other, TimeSpan.FromSeconds(component.ParalyzeTime * SlipPowerModifier), true); // WD EDIT
|
2022-11-15 12:30:59 +01:00
|
|
|
|
2023-09-25 01:44:44 +03:00
|
|
|
RaiseLocalEvent(other, new MoodEffectEvent("MobSlipped")); // WD edit
|
|
|
|
|
|
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>
|
|
|
|
|
public sealed class SlipAttemptEvent : CancellableEntityEventArgs, IInventoryRelayEvent
|
|
|
|
|
{
|
2024-03-26 15:52:23 +07:00
|
|
|
public SlotFlags TargetSlots => SlotFlags.FEET;
|
2023-03-23 18:54:14 +03:00
|
|
|
}
|
|
|
|
|
|
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]
|
2024-03-26 15:52:23 +07:00
|
|
|
public record struct SlipCausingAttemptEvent(bool Cancelled);
|
2024-03-20 12:57:39 +01:00
|
|
|
|
|
|
|
|
/// 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]
|
2024-03-26 15:52:23 +07:00
|
|
|
public readonly record struct SlipEvent(EntityUid Slipped);
|