Fix delete

This commit is contained in:
HappyRoach
2026-01-09 20:16:11 +03:00
parent de0a554e58
commit ca3d5d5fb7
4 changed files with 56 additions and 6 deletions

View File

@@ -0,0 +1,31 @@
using Content.Shared.Sharpening.Components;
using Content.Shared.Sharpening.Systems;
using Content.Shared.Sharpening.Events;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Audio;
namespace Content.Server.Sharpening.Systems;
public sealed class SharpeningSystem : SharedSharpeningSystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharpenerComponent, SharpeningFinishedEvent>(OnSharpeningFinished);
}
private void OnSharpeningFinished(Entity<SharpenerComponent> ent, ref SharpeningFinishedEvent args)
{
_audio.PlayPvs(ent.Comp.SharpeningSound, GetEntity(args.Sharpening), AudioParams.Default.WithMaxDistance(2f));
if (!ent.Comp.DeleteOnSharpening)
return;
if (ent.Comp.Prototype != string.Empty && TryComp(ent, out TransformComponent? xform))
Spawn(ent.Comp.Prototype, xform.Coordinates);
Del(ent);
}
}

View File

@@ -1,5 +1,6 @@
using Robust.Shared.GameStates;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
namespace Content.Shared.Sharpening.Components;
@@ -17,4 +18,7 @@ public sealed partial class SharpenerComponent : Component
[DataField("DeleteOnSharpening"), AutoNetworkedField]
public bool DeleteOnSharpening = false;
[DataField("SpawnOnDelete"), AutoNetworkedField]
public EntProtoId Prototype = string.Empty;
}

View File

@@ -0,0 +1,17 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Sharpening.Events;
[Serializable, NetSerializable]
public sealed class SharpeningFinishedEvent : EntityEventArgs
{
public NetEntity Sharpener;
public NetEntity Sharpening;
public SharpeningFinishedEvent(NetEntity sharpener, NetEntity sharpening)
{
Sharpener = sharpener;
Sharpening = sharpening;
}
}

View File

@@ -4,11 +4,11 @@ using Content.Shared.Interaction;
using Content.Shared.Weapons.Melee;
using Robust.Shared.Audio.Systems;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Sharpening.Events;
namespace Content.Shared.Sharpening.Systems;
public sealed partial class SharedSharpeningSystem : EntitySystem
public abstract class SharedSharpeningSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
@@ -53,10 +53,8 @@ public sealed partial class SharedSharpeningSystem : EntitySystem
ent.Comp.PreviousDamage = weapon.Damage;
weapon.Damage = ent.Comp.Damage;
_audio.PlayPredicted(sharpener.SharpeningSound, args.Target.Value, args.User);
if (sharpener.DeleteOnSharpening)
QueueDel(args.Target);
var ev = new SharpeningFinishedEvent(GetNetEntity(args.Target.Value), GetNetEntity(ent.Owner));
RaiseLocalEvent(args.Target.Value, ev);
args.Handled = true;
}