improve sleeping mob state changes (#11083)

This commit is contained in:
Rane
2022-09-07 00:37:32 -04:00
committed by GitHub
parent d320ad950b
commit 1e62627ecb
3 changed files with 11 additions and 5 deletions

View File

@@ -57,7 +57,7 @@ namespace Content.Server.Bed.Sleep
var emitSound = EnsureComp<SpamEmitSoundComponent>(uid); var emitSound = EnsureComp<SpamEmitSoundComponent>(uid);
// TODO WTF is this, these should a data fields and not hard-coded. // TODO WTF is this, these should a data fields and not hard-coded.
emitSound.Sound = new SoundCollectionSpecifier("Snores", AudioParams.Default.WithVariation(0.2f)); emitSound.Sound = new SoundCollectionSpecifier("Snores", AudioParams.Default.WithVariation(0.2f));
emitSound.PlayChance = 0.33f; emitSound.PlayChance = 0.33f;
emitSound.RollInterval = 5f; emitSound.RollInterval = 5f;
@@ -107,14 +107,14 @@ namespace Content.Server.Bed.Sleep
/// </summary> /// </summary>
private void OnMobStateChanged(EntityUid uid, SleepingComponent component, MobStateChangedEvent args) private void OnMobStateChanged(EntityUid uid, SleepingComponent component, MobStateChangedEvent args)
{ {
if (_mobStateSystem.IsCritical(uid) && !HasComp<ForcedSleepingComponent>(uid)) if (args.CurrentMobState == DamageState.Dead)
{ {
RemComp<SpamEmitSoundComponent>(uid);
RemComp<SleepingComponent>(uid); RemComp<SleepingComponent>(uid);
return; return;
} }
if (TryComp<SpamEmitSoundComponent>(uid, out var spam))
if (_mobStateSystem.IsDead(uid)) spam.Enabled = (args.CurrentMobState == DamageState.Alive) ? true : false;
RemComp<SleepingComponent>(uid);
} }
private void AddWakeVerb(EntityUid uid, SleepingComponent component, GetVerbsEvent<AlternativeVerb> args) private void AddWakeVerb(EntityUid uid, SleepingComponent component, GetVerbsEvent<AlternativeVerb> args)

View File

@@ -18,5 +18,8 @@ namespace Content.Server.Sound.Components
// Always Pvs. // Always Pvs.
[DataField("popUp")] [DataField("popUp")]
public string? PopUp; public string? PopUp;
[DataField("enabled")]
public bool Enabled = true;
} }
} }

View File

@@ -36,6 +36,9 @@ namespace Content.Server.Sound
base.Update(frameTime); base.Update(frameTime);
foreach (var soundSpammer in EntityQuery<SpamEmitSoundComponent>()) foreach (var soundSpammer in EntityQuery<SpamEmitSoundComponent>())
{ {
if (!soundSpammer.Enabled)
continue;
soundSpammer.Accumulator += frameTime; soundSpammer.Accumulator += frameTime;
if (soundSpammer.Accumulator < soundSpammer.RollInterval) if (soundSpammer.Accumulator < soundSpammer.RollInterval)
{ {