Another batch of DoAfter fixes (#14351)

This commit is contained in:
keronshb
2023-03-05 00:26:03 -05:00
committed by GitHub
parent 417569fe2e
commit eff088189d
11 changed files with 124 additions and 42 deletions

View File

@@ -103,6 +103,10 @@ public abstract class SharedDoAfterSystem : EntitySystem
foreach (var (_, comp) in EntityManager.EntityQuery<ActiveDoAfterComponent, DoAfterComponent>())
{
//Don't run the doafter if its comp or owner is deleted.
if (EntityManager.Deleted(comp.Owner) || comp.Deleted)
continue;
foreach (var doAfter in comp.DoAfters.Values.ToArray())
{
Run(comp.Owner, comp, doAfter);

View File

@@ -769,6 +769,7 @@ namespace Content.Shared.Interaction
return;
// all interactions should only happen when in range / unobstructed, so no range check is needed
//TODO: See why this is firing off multiple times
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
RaiseLocalEvent(target, interactUsingEvent, true);
DoContactInteraction(user, used, interactUsingEvent);

View File

@@ -42,6 +42,12 @@ public sealed class EncryptionKeyHolderComponent : Component
public Container KeyContainer = default!;
public const string KeyContainerName = "key_slots";
/// <summary>
/// Blocks multiple attempts to remove the key
/// </summary>
[DataField("removing")]
public bool Removing;
/// <summary>
/// Combined set of radio channels provided by all contained keys.
/// </summary>

View File

@@ -37,6 +37,28 @@ public sealed class EncryptionKeySystem : EntitySystem
SubscribeLocalEvent<EncryptionKeyHolderComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<EncryptionKeyHolderComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
SubscribeLocalEvent<EncryptionKeyHolderComponent, EntRemovedFromContainerMessage>(OnContainerModified);
SubscribeLocalEvent<EncryptionKeyHolderComponent, EncryptionRemovalFinishedEvent>(OnKeyRemoval);
SubscribeLocalEvent<EncryptionKeyHolderComponent, EncryptionRemovalCancelledEvent>(OnKeyCancelled);
}
private void OnKeyCancelled(EntityUid uid, EncryptionKeyHolderComponent component, EncryptionRemovalCancelledEvent args)
{
component.Removing = false;
}
private void OnKeyRemoval(EntityUid uid, EncryptionKeyHolderComponent component, EncryptionRemovalFinishedEvent args)
{
var contained = component.KeyContainer.ContainedEntities.ToArray();
_container.EmptyContainer(component.KeyContainer, entMan: EntityManager);
foreach (var ent in contained)
{
_hands.PickupOrDrop(args.User, ent);
}
// if tool use ever gets predicted this needs changing.
_popupSystem.PopupEntity(Loc.GetString("headset-encryption-keys-all-extracted"), uid, args.User);
_audio.PlayPvs(component.KeyExtractionSound, uid);
component.Removing = false;
}
public void UpdateChannels(EntityUid uid, EncryptionKeyHolderComponent component)
@@ -67,7 +89,7 @@ public sealed class EncryptionKeySystem : EntitySystem
private void OnInteractUsing(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
{
if (!TryComp<ContainerManagerComponent>(uid, out var storage))
if (!TryComp<ContainerManagerComponent>(uid, out var storage) || args.Handled || component.Removing)
return;
if (TryComp<EncryptionKeyComponent>(args.Used, out var key))
@@ -99,7 +121,7 @@ public sealed class EncryptionKeySystem : EntitySystem
if (!TryComp<ToolComponent>(args.Used, out var tool) || !tool.Qualities.Contains(component.KeysExtractionMethod))
return;
args.Handled = true;
if (component.KeyContainer.ContainedEntities.Count == 0)
@@ -109,21 +131,13 @@ public sealed class EncryptionKeySystem : EntitySystem
return;
}
var toolEvData = new ToolEventData(null);
//This is honestly the poor mans fix because the InteractUsingEvent fires off 12 times
component.Removing = true;
if(!_toolSystem.UseTool(args.Used, args.User, uid, 0f, new[] { component.KeysExtractionMethod }, toolEvData, toolComponent: tool))
var toolEvData = new ToolEventData(new EncryptionRemovalFinishedEvent(args.User), cancelledEv: new EncryptionRemovalCancelledEvent(), targetEntity: uid);
if(!_toolSystem.UseTool(args.Used, args.User, uid, 1f, new[] { component.KeysExtractionMethod }, toolEvData, toolComponent: tool))
return;
var contained = component.KeyContainer.ContainedEntities.ToArray();
_container.EmptyContainer(component.KeyContainer, entMan: EntityManager);
foreach (var ent in contained)
{
_hands.PickupOrDrop(args.User, ent);
}
// if tool use ever gets predicted this needs changing.
_popupSystem.PopupEntity(Loc.GetString("headset-encryption-keys-all-extracted"), uid, args.User);
_audio.PlayPvs(component.KeyExtractionSound, args.Target);
}
private void OnStartup(EntityUid uid, EncryptionKeyHolderComponent component, ComponentStartup args)
@@ -195,4 +209,19 @@ public sealed class EncryptionKeySystem : EntitySystem
examineEvent.PushMarkup(msg);
}
}
public sealed class EncryptionRemovalFinishedEvent : EntityEventArgs
{
public EntityUid User;
public EncryptionRemovalFinishedEvent(EntityUid user)
{
User = user;
}
}
public sealed class EncryptionRemovalCancelledEvent : EntityEventArgs
{
}
}