Skip to content

Commit

Permalink
Merge pull request #1207 from Darkmajia/throwing-fixes
Browse files Browse the repository at this point in the history
unembed projectiles on parent destruction/consumption
  • Loading branch information
hivehum authored Jan 2, 2025
2 parents f7ca007 + 5522d5e commit 79d89f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Content.Server/Destructible/DestructibleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Linq;
using Content.Shared.Projectiles;

namespace Content.Server.Destructible
{
Expand All @@ -40,6 +41,7 @@ public sealed class DestructibleSystem : SharedDestructibleSystem
[Dependency] public readonly SharedSolutionContainerSystem SolutionContainerSystem = default!;
[Dependency] public readonly PuddleSystem PuddleSystem = default!;
[Dependency] public readonly SharedContainerSystem ContainerSystem = default!;
[Dependency] public readonly SharedProjectileSystem ProjectileSystem = default!;
[Dependency] public readonly IPrototypeManager PrototypeManager = default!;
[Dependency] public readonly IComponentFactory ComponentFactory = default!;
[Dependency] public readonly IAdminLogManager _adminLogger = default!;
Expand Down Expand Up @@ -82,6 +84,14 @@ public void Execute(EntityUid uid, DestructibleComponent component, DamageChange
$"Unknown damage source caused {ToPrettyString(uid):subject} to trigger [{triggeredBehaviors}]");
}

// Unembed any embedded projectiles
var childEnumerator = Transform(uid).ChildEnumerator;
while (childEnumerator.MoveNext(out var child))
{
if (TryComp<EmbeddableProjectileComponent>(child, out var embeddable))
ProjectileSystem.RemoveEmbed(child, embeddable);
}

threshold.Execute(uid, this, EntityManager, args.Origin);
}

Expand Down
10 changes: 10 additions & 0 deletions Content.Server/Nutrition/EntitySystems/FoodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using Robust.Server.GameObjects;
using Content.Shared.Whitelist;
using Content.Shared.Destructible;
using Content.Shared.Projectiles;

namespace Content.Server.Nutrition.EntitySystems;

Expand All @@ -60,6 +61,7 @@ public sealed class FoodSystem : EntitySystem
[Dependency] private readonly StomachSystem _stomach = default!;
[Dependency] private readonly UtensilSystem _utensil = default!;
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] public readonly SharedProjectileSystem _projectile = default!;

public const float MaxFeedDistance = 1.0f;

Expand Down Expand Up @@ -336,6 +338,14 @@ public void DeleteAndSpawnTrash(FoodComponent component, EntityUid food, EntityU
if (ev.Cancelled)
return;

// Unembed any embedded projectiles
var childEnumerator = Transform(food).ChildEnumerator;
while (childEnumerator.MoveNext(out var child))
{
if (TryComp<EmbeddableProjectileComponent>(child, out var embeddable))
_projectile.RemoveEmbed(child, embeddable);
}

var dev = new DestructionEventArgs();
RaiseLocalEvent(food, dev);

Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Destructible/SharedDestructibleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Content.Shared.Destructible;
namespace Content.Shared.Destructible;

public abstract class SharedDestructibleSystem : EntitySystem
{
Expand Down

0 comments on commit 79d89f0

Please sign in to comment.