Fixes storage eating buckled players (#9096)

Co-authored-by: Kara <lunarautomaton6@gmail.com>
This commit is contained in:
Júlio César Ueti
2022-06-24 16:26:56 -03:00
committed by GitHub
parent 8761dec4e9
commit d1a0340343
4 changed files with 32 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
using Content.Server.Buckle.Components;
using Content.Server.Interaction;
using Content.Server.Storage.Components;
using Content.Shared.Buckle;
using Content.Shared.Interaction;
using Content.Shared.Verbs;
@@ -32,6 +33,7 @@ namespace Content.Server.Buckle.Systems
SubscribeLocalEvent<BuckleComponent, InteractHandEvent>(HandleInteractHand);
SubscribeLocalEvent<BuckleComponent, GetVerbsEvent<InteractionVerb>>(AddUnbuckleVerb);
SubscribeLocalEvent<BuckleComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
}
private void AddUnbuckleVerb(EntityUid uid, BuckleComponent component, GetVerbsEvent<InteractionVerb> args)
@@ -133,5 +135,11 @@ namespace Content.Server.Buckle.Systems
buckle.ReAttach(strap);
}
}
public void OnEntityStorageInsertAttempt(EntityUid uid, BuckleComponent comp, InsertIntoEntityStorageAttemptEvent args)
{
if (comp.Buckled)
args.Cancel();
}
}
}

View File

@@ -19,6 +19,7 @@ namespace Content.Server.Foldable
SubscribeLocalEvent<FoldableComponent, StorageOpenAttemptEvent>(OnFoldableOpenAttempt);
SubscribeLocalEvent<FoldableComponent, GetVerbsEvent<AlternativeVerb>>(AddFoldVerb);
SubscribeLocalEvent<FoldableComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
}
private void OnFoldableOpenAttempt(EntityUid uid, FoldableComponent component, StorageOpenAttemptEvent args)
@@ -86,6 +87,12 @@ namespace Content.Server.Foldable
strap.Enabled = !component.IsFolded;
}
public void OnEntityStorageInsertAttempt(EntityUid uid, FoldableComponent comp, InsertIntoEntityStorageAttemptEvent args)
{
if (!comp.IsFolded)
args.Cancel();
}
#region Verb
private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent<AlternativeVerb> args)

View File

@@ -4,6 +4,7 @@ using Content.Server.Ghost.Components;
using Content.Server.Mind;
using Content.Server.Mind.Components;
using Content.Server.Players;
using Content.Server.Storage.Components;
using Content.Server.Visible;
using Content.Server.Warps;
using Content.Shared.Actions;
@@ -51,6 +52,7 @@ namespace Content.Server.Ghost
SubscribeNetworkEvent<GhostWarpToTargetRequestEvent>(OnGhostWarpToTargetRequest);
SubscribeLocalEvent<GhostComponent, BooActionEvent>(OnActionPerform);
SubscribeLocalEvent<GhostComponent, InsertIntoEntityStorageAttemptEvent>(OnEntityStorageInsertAttempt);
}
private void OnActionPerform(EntityUid uid, GhostComponent component, BooActionEvent args)
{
@@ -265,5 +267,10 @@ namespace Content.Server.Ghost
return players;
}
public void OnEntityStorageInsertAttempt(EntityUid uid, GhostComponent comp, InsertIntoEntityStorageAttemptEvent args)
{
args.Cancel();
}
}
}

View File

@@ -1,5 +1,7 @@
using System.Linq;
using Content.Server.Buckle.Components;
using Content.Server.Construction;
using Content.Server.Construction.Completions;
using Content.Server.Construction.Components;
using Content.Server.Ghost.Components;
using Content.Server.Storage.EntitySystems;
@@ -215,8 +217,9 @@ namespace Content.Server.Storage.Components
// 5. if this is NOT AN ITEM, then mobs can always be eaten unless unless a previous law prevents it
// 6. if this is an item, then mobs must only be eaten if some other component prevents pick-up interactions while a mob is inside (e.g. foldable)
// Let's not insert admin ghosts, yeah? This is really a a hack and should be replaced by attempt events
if (_entMan.HasComponent<GhostComponent>(entity))
var attemptEvent = new InsertIntoEntityStorageAttemptEvent();
_entMan.EventBus.RaiseLocalEvent(entity, attemptEvent);
if (attemptEvent.Cancelled)
return false;
// checks
@@ -236,13 +239,9 @@ namespace Content.Server.Storage.Components
{
if (!storageIsItem)
allowedToEat = true;
else
{
// make an exception if this is a foldable-item that is currently un-folded (e.g., body bags).
allowedToEat = _entMan.TryGetComponent(Owner, out FoldableComponent? foldable) && !foldable.IsFolded;
}
}
_entMan.EventBus.RaiseLocalEvent(entity, allowedToEat);
return allowedToEat;
}
@@ -365,6 +364,10 @@ namespace Content.Server.Storage.Components
}
}
public sealed class InsertIntoEntityStorageAttemptEvent : CancellableEntityEventArgs
{
}
public sealed class StorageOpenAttemptEvent : CancellableEntityEventArgs
{