Fix embedded projectile deletion not being tracked by container (#36123)

* Remove deleted projectiles from the container tracking them

* Gotta dirty the container

* Remove the container component when all embedded projectiles are gone

* Add test

* No clientside deletion of networked entities

* Move cleanup logic before deletion
This commit is contained in:
Tayrtahn
2025-03-28 04:43:13 -04:00
committed by GitHub
parent 92a3fd99ca
commit b9517fcbe8
2 changed files with 98 additions and 6 deletions

View File

@@ -39,6 +39,7 @@ public abstract partial class SharedProjectileSystem : EntitySystem
SubscribeLocalEvent<EmbeddableProjectileComponent, ThrowDoHitEvent>(OnEmbedThrowDoHit);
SubscribeLocalEvent<EmbeddableProjectileComponent, ActivateInWorldEvent>(OnEmbedActivate);
SubscribeLocalEvent<EmbeddableProjectileComponent, RemoveEmbeddedProjectileEvent>(OnEmbedRemove);
SubscribeLocalEvent<EmbeddableProjectileComponent, ComponentShutdown>(OnEmbeddableCompShutdown);
SubscribeLocalEvent<EmbeddedContainerComponent, EntityTerminatingEvent>(OnEmbeddableTermination);
}
@@ -75,6 +76,11 @@ public abstract partial class SharedProjectileSystem : EntitySystem
_hands.TryPickupAnyHand(args.User, embeddable);
}
private void OnEmbeddableCompShutdown(Entity<EmbeddableProjectileComponent> embeddable, ref ComponentShutdown arg)
{
EmbedDetach(embeddable, embeddable.Comp);
}
private void OnEmbedThrowDoHit(Entity<EmbeddableProjectileComponent> embeddable, ref ThrowDoHitEvent args)
{
if (!embeddable.Comp.EmbedOnThrow)
@@ -130,16 +136,21 @@ public abstract partial class SharedProjectileSystem : EntitySystem
if (!Resolve(uid, ref component))
return;
if (component.DeleteOnRemove)
{
QueueDel(uid);
return;
}
if (component.EmbeddedIntoUid is not null)
{
if (TryComp<EmbeddedContainerComponent>(component.EmbeddedIntoUid.Value, out var embeddedContainer))
{
embeddedContainer.EmbeddedObjects.Remove(uid);
Dirty(component.EmbeddedIntoUid.Value, embeddedContainer);
if (embeddedContainer.EmbeddedObjects.Count == 0)
RemCompDeferred<EmbeddedContainerComponent>(component.EmbeddedIntoUid.Value);
}
}
if (component.DeleteOnRemove && _net.IsServer)
{
QueueDel(uid);
return;
}
var xform = Transform(uid);