Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thrown soap/banana/(etc?) will fail to slip until it lands #24494

Merged
merged 10 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Content.Shared/Slippery/SlipperySystem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
using Content.Shared.Inventory;
using Robust.Shared.Network;
using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Content.Shared.StepTrigger.Systems;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;
using JetBrains.Annotations;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
Expand All @@ -18,6 +21,8 @@ public sealed class SlipperySystem : EntitySystem
{
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedStunSystem _stun = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
Expand All @@ -30,6 +35,7 @@ public override void Initialize()
SubscribeLocalEvent<SlipperyComponent, StepTriggerAttemptEvent>(HandleAttemptCollide);
SubscribeLocalEvent<SlipperyComponent, StepTriggeredEvent>(HandleStepTrigger);
SubscribeLocalEvent<NoSlipComponent, SlipAttemptEvent>(OnNoSlipAttempt);
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));
}
Expand All @@ -52,6 +58,16 @@ private static void OnNoSlipAttempt(EntityUid uid, NoSlipComponent component, Sl
args.Cancel();
}

private void OnThrownSlipAttempt(EntityUid uid, ThrownItemComponent comp, ref SlipCausingAttemptEvent args)
{
args.Cancelled = true;

//TODO: If it's after 2024 April and this popup is still here, remove it
// Only here so people who don't read even the changelog won't think soap suddenly broke
if (_netManager.IsServer)
_popup.PopupEntity(Loc.GetString("thrown-slippery-missed"), uid, PopupType.Medium);
}

private bool CanSlip(EntityUid uid, EntityUid toSlip)
{
return !_container.IsEntityInContainer(uid)
Expand All @@ -68,6 +84,11 @@ private void TrySlip(EntityUid uid, SlipperyComponent component, EntityUid other
if (attemptEv.Cancelled)
return;

var attemptCausingEv = new SlipCausingAttemptEvent();
RaiseLocalEvent(uid, ref attemptCausingEv);
if (attemptCausingEv.Cancelled)
return;

var ev = new SlipEvent(other);
RaiseLocalEvent(uid, ref ev);

Expand Down Expand Up @@ -107,7 +128,13 @@ public sealed class SlipAttemptEvent : CancellableEntityEventArgs, IInventoryRel
}

/// <summary>
/// This event is raised directed at an entity that CAUSED some other entity to slip (e.g., the banana peel).
/// Raised on an entity that is causing the slip event (e.g, the banana peel), to determine if the slip attempt should be cancelled.
/// </summary>
/// <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>
[ByRefEvent]
public readonly record struct SlipEvent(EntityUid Slipped);
1 change: 1 addition & 0 deletions Resources/Locale/en-US/movement/slipping.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
thrown-slippery-missed = MISS
Loading