Strap bug fixes (#10142)

This commit is contained in:
Leon Friedrich
2022-07-31 14:53:17 +12:00
committed by GitHub
parent a5c4cec498
commit 7500303bed
2 changed files with 31 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.Buckle.Components;
using Content.Server.Construction.Completions;
using Content.Server.Interaction;
using Content.Shared.Destructible;
using Content.Shared.Interaction;
@@ -8,7 +9,6 @@ using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
namespace Content.Server.Buckle.Systems
{
[UsedImplicitly]
@@ -23,7 +23,19 @@ namespace Content.Server.Buckle.Systems
SubscribeLocalEvent<StrapComponent, GetVerbsEvent<InteractionVerb>>(AddStrapVerbs);
SubscribeLocalEvent<StrapComponent, ContainerGettingInsertedAttemptEvent>(OnInsertAttempt);
SubscribeLocalEvent<StrapComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<StrapComponent, DestructionEventArgs>(OnDestroy);
SubscribeLocalEvent<StrapComponent, DestructionEventArgs>((_,c,_) => RemoveAll(c));
SubscribeLocalEvent<StrapComponent, BreakageEventArgs>((_, c, _) => RemoveAll(c));
SubscribeLocalEvent<StrapComponent, ConstructionBeforeDeleteEvent>((_, c, _) => RemoveAll(c));
SubscribeLocalEvent<StrapComponent, ComponentShutdown>(OnShutdown);
}
private void OnShutdown(EntityUid uid, StrapComponent component, ComponentShutdown args)
{
if (LifeStage(uid) > EntityLifeStage.MapInitialized)
return;
// Component is being removed, but entity is not shutting down.
component.RemoveAll();
}
private void OnInsertAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args)
@@ -123,7 +135,7 @@ namespace Content.Server.Buckle.Systems
}
}
private void OnDestroy(EntityUid uid, StrapComponent component, DestructionEventArgs args)
public void RemoveAll(StrapComponent component)
{
component.RemoveAll();
}

View File

@@ -1,15 +1,29 @@
using Content.Shared.Construction;
using Content.Shared.Construction;
using JetBrains.Annotations;
namespace Content.Server.Construction.Completions
{
public sealed class ConstructionBeforeDeleteEvent : CancellableEntityEventArgs
{
public EntityUid? User;
public ConstructionBeforeDeleteEvent(EntityUid? user)
{
User = user;
}
}
[UsedImplicitly]
[DataDefinition]
public sealed class DeleteEntity : IGraphAction
{
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
entityManager.DeleteEntity(uid);
var ev = new ConstructionBeforeDeleteEvent(userUid);
entityManager.EventBus.RaiseLocalEvent(uid, ev);
if (!ev.Cancelled)
entityManager.DeleteEntity(uid);
}
}
}