From 1e6cc0d3d6bf4c24b74c8acec1736bc4bcb7ad79 Mon Sep 17 00:00:00 2001 From: vanx <61917534+Vaaankas@users.noreply.github.com> Date: Thu, 6 Mar 2025 10:58:46 +0300 Subject: [PATCH] [Fix] Embed Items Now Drop On Destruction/Deconstruction (#278) * embed children * locale * fix * Update Resources/Locale/ru-RU/weapons/throwing/throwing.ftl Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> * // WWDP MY BELOVED --------- Co-authored-by: vanx Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com> --- .../Destructible/DestructibleSystem.cs | 41 +++++++++++++++++++ .../Projectiles/SharedProjectileSystem.cs | 9 ++-- .../en-US/weapons/throwing/throwing.ftl | 4 +- .../ru-RU/weapons/throwing/throwing.ftl | 6 +++ 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 Resources/Locale/ru-RU/weapons/throwing/throwing.ftl diff --git a/Content.Server/Destructible/DestructibleSystem.cs b/Content.Server/Destructible/DestructibleSystem.cs index 16c54fd3b0..1d42aa16b9 100644 --- a/Content.Server/Destructible/DestructibleSystem.cs +++ b/Content.Server/Destructible/DestructibleSystem.cs @@ -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 { @@ -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(Execute); + SubscribeLocalEvent(OnDestroyed); // WWDP + SubscribeLocalEvent(OnDeconstruct); // WWDP } /// @@ -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(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. /// diff --git a/Content.Shared/Projectiles/SharedProjectileSystem.cs b/Content.Shared/Projectiles/SharedProjectileSystem.cs index faa600fbf2..7577ae6fe5 100644 --- a/Content.Shared/Projectiles/SharedProjectileSystem.cs +++ b/Content.Shared/Projectiles/SharedProjectileSystem.cs @@ -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; @@ -50,7 +51,7 @@ public override void Initialize() SubscribeLocalEvent(PreventCollision); SubscribeLocalEvent(OnEmbedProjectileHit); SubscribeLocalEvent(OnEmbedThrowDoHit); - SubscribeLocalEvent(OnEmbedActivate, before: new[] {typeof(ActivatableUISystem)}); // WD EDIT + SubscribeLocalEvent(OnEmbedActivate, before: new[] {typeof(ActivatableUISystem), typeof(ItemToggleSystem), }); // WD EDIT SubscribeLocalEvent(OnEmbedRemove); SubscribeLocalEvent(OnExamined); SubscribeLocalEvent(OnPreventCollision); // WD EDIT @@ -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) { @@ -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) diff --git a/Resources/Locale/en-US/weapons/throwing/throwing.ftl b/Resources/Locale/en-US/weapons/throwing/throwing.ftl index c7d2a8f663..3700299c07 100644 --- a/Resources/Locale/en-US/weapons/throwing/throwing.ftl +++ b/Resources/Locale/en-US/weapons/throwing/throwing.ftl @@ -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]. diff --git a/Resources/Locale/ru-RU/weapons/throwing/throwing.ftl b/Resources/Locale/ru-RU/weapons/throwing/throwing.ftl new file mode 100644 index 0000000000..b24ace70e8 --- /dev/null +++ b/Resources/Locale/ru-RU/weapons/throwing/throwing.ftl @@ -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].