Skip to content

Commit

Permalink
[Fix] Embed Items Now Drop On Destruction/Deconstruction (#278)
Browse files Browse the repository at this point in the history
* embed children

* locale

* fix

* Update Resources/Locale/ru-RU/weapons/throwing/throwing.ftl

Co-authored-by: Spatison <[email protected]>

* // WWDP MY BELOVED

---------

Co-authored-by: vanx <discord@vanxxxx>
Co-authored-by: Spatison <[email protected]>
  • Loading branch information
3 people authored Mar 6, 2025
1 parent 3b5817f commit 1e6cc0d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
41 changes: 41 additions & 0 deletions Content.Server/Destructible/DestructibleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Linq;
using System.Numerics;
using Content.Server.Construction.Completions;
using Content.Shared.Projectiles;
using Content.Shared.Throwing;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;


namespace Content.Server.Destructible
{
Expand All @@ -42,11 +50,18 @@ public sealed class DestructibleSystem : SharedDestructibleSystem
[Dependency] public readonly IPrototypeManager PrototypeManager = default!;
[Dependency] public readonly IComponentFactory ComponentFactory = default!;
[Dependency] public readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!; // WWDP
[Dependency] private readonly SharedTransformSystem _transform = default!; // WWDP
[Dependency] private readonly ThrowingSystem _throwing = default!; // WWDP
[Dependency] private readonly SharedProjectileSystem _projectile = default!; // WWDP
[Dependency] private readonly IRobustRandom _random = default!; // WWDP

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DestructibleComponent, DamageChangedEvent>(Execute);
SubscribeLocalEvent<DestructibleComponent, DestructionEventArgs>(OnDestroyed); // WWDP
SubscribeLocalEvent<DestructibleComponent, ConstructionBeforeDeleteEvent>(OnDeconstruct); // WWDP
}

/// <summary>
Expand Down Expand Up @@ -90,6 +105,32 @@ public void Execute(EntityUid uid, DestructibleComponent component, DamageChange
}
}

// WWDP - handle embed children on destruction
public void OnDestroyed(EntityUid uid, DestructibleComponent component, DestructionEventArgs args)
{
RemoveEmbedChildren(uid);
}

public void OnDeconstruct(EntityUid uid, DestructibleComponent component, ConstructionBeforeDeleteEvent args)
{
RemoveEmbedChildren(uid);
}

public void RemoveEmbedChildren(EntityUid uid)
{
var children = Transform(uid).ChildEnumerator;
while (children.MoveNext(out var child))
{
if (!TryComp<EmbeddableProjectileComponent>(child, out var embed))
continue;

_projectile.RemoveEmbed(child, embed);
_throwing.TryThrow(child, _random.NextVector2(), 1f, friction: 100f); // very short distance
}
}

// WWDP edit end

// FFS this shouldn't be this hard. Maybe this should just be a field of the destructible component. Its not
// like there is currently any entity that is NOT just destroyed upon reaching a total-damage value.
/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions Content.Shared/Projectiles/SharedProjectileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared._Shitmed.Targeting;
using Content.Shared.Item.ItemToggle;
using Content.Shared.Throwing;
using Content.Shared.UserInterface;
using Robust.Shared.Audio.Systems;
Expand Down Expand Up @@ -50,7 +51,7 @@ public override void Initialize()
SubscribeLocalEvent<ProjectileComponent, PreventCollideEvent>(PreventCollision);
SubscribeLocalEvent<EmbeddableProjectileComponent, ProjectileHitEvent>(OnEmbedProjectileHit);
SubscribeLocalEvent<EmbeddableProjectileComponent, ThrowDoHitEvent>(OnEmbedThrowDoHit);
SubscribeLocalEvent<EmbeddableProjectileComponent, ActivateInWorldEvent>(OnEmbedActivate, before: new[] {typeof(ActivatableUISystem)}); // WD EDIT
SubscribeLocalEvent<EmbeddableProjectileComponent, ActivateInWorldEvent>(OnEmbedActivate, before: new[] {typeof(ActivatableUISystem), typeof(ItemToggleSystem), }); // WD EDIT
SubscribeLocalEvent<EmbeddableProjectileComponent, RemoveEmbeddedProjectileEvent>(OnEmbedRemove);
SubscribeLocalEvent<EmbeddableProjectileComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<EmbeddableProjectileComponent, PreventCollideEvent>(OnPreventCollision); // WD EDIT
Expand Down Expand Up @@ -94,8 +95,8 @@ public void RemoveEmbed(EntityUid uid, EmbeddableProjectileComponent component,
RaiseLocalEvent(uid, ref ev);

// Whacky prediction issues.
if (_netManager.IsClient)
return;
//if (_netManager.IsClient) // WWDP disabled
// return;

if (component.DeleteOnRemove)
{
Expand Down Expand Up @@ -127,6 +128,8 @@ public void RemoveEmbed(EntityUid uid, EmbeddableProjectileComponent component,
// try place it in the user's hand
if (remover is {} removerUid)
_hands.TryPickupAnyHand(removerUid, uid);

Dirty(uid, component); // WWDP
}

private void OnEmbedThrowDoHit(EntityUid uid, EmbeddableProjectileComponent component, ThrowDoHitEvent args)
Expand Down
4 changes: 2 additions & 2 deletions Resources/Locale/en-US/weapons/throwing/throwing.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ throwing-falloff = The {$item} falls out of you!
throwing-embed-falloff = The {$item} falls out of you!
throwing-embed-remove-alert-owner = {$other} is removing the {$item} stuck on you!
throwing-examine-embedded = {CAPITALIZE(OBJECT($embedded))} {CONJUGATE-BE($embedded)} [color=teal]embedded[/color] in [bold]{THE($target)}[/bold].
throwing-examine-embedded-part = {CAPITALIZE(OBJECT($embedded))} {CONJUGATE-BE($embedded)} [color=teal]embedded[/color] in [bold]{THE($target)}[/bold]'s [color=red]{$targetPart}[/color].
throwing-examine-embedded = {CAPITALIZE(SUBJECT($embedded))} {CONJUGATE-BE($embedded)} [color=teal]embedded[/color] in [bold]{THE($target)}[/bold].
throwing-examine-embedded-part = {CAPITALIZE(SUBJECT($embedded))} {CONJUGATE-BE($embedded)} [color=teal]embedded[/color] in [bold]{THE($target)}[/bold]'s [color=red]{$targetPart}[/color].
6 changes: 6 additions & 0 deletions Resources/Locale/ru-RU/weapons/throwing/throwing.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
throwing-falloff = {$item} выпадает из вас!
throwing-embed-falloff = {$item} выпадает из вас!
throwing-embed-remove-alert-owner = {$other} достаёт {$item}, застрявший в вас!
throwing-examine-embedded = {CAPITALIZE(SUBJECT($embedded))} [color=teal]застрял[/color] в [bold]{$target}[/bold].
throwing-examine-embedded-part = {CAPITALIZE(SUBJECT($embedded))} [color=teal]застрял[/color] в [color=red]{$targetPart}[/color] [bold]{target}[/bold].

0 comments on commit 1e6cc0d

Please sign in to comment.