mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description IPCs were ported from a codebase that didn't necessarily follow all of our repo's coding standards. And while I had done my part to cleanup as much of the system as was practical within the bounds of a Maintainer Review, there were a lot of things that I felt were inappropriate to leave to review, and wished to go over with a fine lense. Thus, here is my Refactor of IPC code. Do not merge this without first testing that nothing was broken. Because I haven't tested it myself yet.
43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using Content.Server.Silicon.Death;
|
|
using Content.Shared.Sound.Components;
|
|
using Content.Server.Sound;
|
|
using Content.Shared.Mobs;
|
|
|
|
namespace Content.Server.Silicon;
|
|
|
|
public sealed class EmitSoundOnCritSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly EmitSoundSystem _emitSound = default!;
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<SiliconEmitSoundOnDrainedComponent, SiliconChargeDeathEvent>(OnDeath);
|
|
SubscribeLocalEvent<SiliconEmitSoundOnDrainedComponent, SiliconChargeAliveEvent>(OnAlive);
|
|
SubscribeLocalEvent<SiliconEmitSoundOnDrainedComponent, MobStateChangedEvent>(OnStateChange);
|
|
}
|
|
|
|
private void OnDeath(EntityUid uid, SiliconEmitSoundOnDrainedComponent component, SiliconChargeDeathEvent args)
|
|
{
|
|
var spamComp = EnsureComp<SpamEmitSoundComponent>(uid);
|
|
|
|
spamComp.MinInterval = component.MinInterval;
|
|
spamComp.MaxInterval = component.MaxInterval;
|
|
spamComp.PopUp = component.PopUp;
|
|
spamComp.Sound = component.Sound;
|
|
_emitSound.SetEnabled((uid, spamComp), true);
|
|
}
|
|
|
|
private void OnAlive(EntityUid uid, SiliconEmitSoundOnDrainedComponent component, SiliconChargeAliveEvent args)
|
|
{
|
|
RemComp<SpamEmitSoundComponent>(uid); // This component is bad and I don't feel like making a janky work around because of it.
|
|
// If you give something the SiliconEmitSoundOnDrainedComponent, know that it can't have the SpamEmitSoundComponent, and any other systems that play with it will just be broken.
|
|
}
|
|
|
|
public void OnStateChange(EntityUid uid, SiliconEmitSoundOnDrainedComponent component, MobStateChangedEvent args)
|
|
{
|
|
if (args.NewMobState != MobState.Dead)
|
|
return;
|
|
|
|
RemComp<SpamEmitSoundComponent>(uid);
|
|
}
|
|
}
|