Fix dead mobs sneezing and coughing (#12919)
* Fix dead mobs sneezing and coughing * SneezeCough update * Streamlined Event code, moved dead-check * cleanup * I can has merge? * Shared event for SharedMobStateSystem
This commit is contained in:
@@ -9,6 +9,7 @@ using Content.Server.Popups;
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Disease;
|
||||
using Content.Shared.Disease.Components;
|
||||
using Content.Shared.Disease.Events;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Interaction;
|
||||
@@ -17,6 +18,8 @@ using Content.Shared.Inventory;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
@@ -31,6 +34,7 @@ namespace Content.Server.Disease
|
||||
/// </summary>
|
||||
public sealed class DiseaseSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly AudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly ISerializationManager _serializationManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
@@ -264,7 +268,7 @@ namespace Content.Server.Disease
|
||||
{
|
||||
if (TryComp<DiseaseCarrierComponent>(uid, out var carrier))
|
||||
{
|
||||
SneezeCough(uid, _random.Pick(carrier.Diseases), string.Empty);
|
||||
SneezeCough(uid, _random.Pick(carrier.Diseases), string.Empty, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,24 +434,34 @@ namespace Content.Server.Disease
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Plays a sneeze/cough popup if applicable
|
||||
/// Raises an event for systems to cancel the snough if needed
|
||||
/// Plays a sneeze/cough sound and popup if applicable
|
||||
/// and then tries to infect anyone in range
|
||||
/// if the snougher is not wearing a mask.
|
||||
/// </summary>
|
||||
public void SneezeCough(EntityUid uid, DiseasePrototype? disease, string snoughMessage, bool airTransmit = true, TransformComponent? xform = null)
|
||||
public bool SneezeCough(EntityUid uid, DiseasePrototype? disease, string snoughMessage, SoundSpecifier? snoughSound, bool airTransmit = true, TransformComponent? xform = null)
|
||||
{
|
||||
if (!Resolve(uid, ref xform)) return;
|
||||
if (!Resolve(uid, ref xform)) return false;
|
||||
|
||||
if (_mobStateSystem.IsDead(uid)) return false;
|
||||
|
||||
var attemptSneezeCoughEvent = new AttemptSneezeCoughEvent(uid, snoughMessage, snoughSound);
|
||||
RaiseLocalEvent(uid, ref attemptSneezeCoughEvent);
|
||||
if (attemptSneezeCoughEvent.Cancelled) return false;
|
||||
|
||||
if (!string.IsNullOrEmpty(snoughMessage))
|
||||
_popupSystem.PopupEntity(Loc.GetString(snoughMessage, ("person", Identity.Entity(uid, EntityManager))), uid, Filter.Pvs(uid));
|
||||
|
||||
if (snoughSound != null)
|
||||
_audioSystem.PlayPvs(snoughSound, uid);
|
||||
|
||||
if (disease is not { Infectious: true } || !airTransmit)
|
||||
return;
|
||||
return true;
|
||||
|
||||
if (_inventorySystem.TryGetSlotEntity(uid, "mask", out var maskUid) &&
|
||||
EntityManager.TryGetComponent<IngestionBlockerComponent>(maskUid, out var blocker) &&
|
||||
blocker.Enabled)
|
||||
return;
|
||||
return true;
|
||||
|
||||
var carrierQuery = GetEntityQuery<DiseaseCarrierComponent>();
|
||||
|
||||
@@ -458,6 +472,7 @@ namespace Content.Server.Disease
|
||||
|
||||
TryInfect(carrier, disease, 0.3f);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using Content.Shared.Disease;
|
||||
using JetBrains.Annotations;
|
||||
using Content.Shared.Audio;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Disease
|
||||
{
|
||||
@@ -13,6 +11,7 @@ namespace Content.Server.Disease
|
||||
[UsedImplicitly]
|
||||
public sealed class DiseaseSnough : DiseaseEffect
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Message to play when snoughing
|
||||
/// </summary>
|
||||
@@ -24,6 +23,7 @@ namespace Content.Server.Disease
|
||||
/// <summary>
|
||||
[DataField("snoughSound")]
|
||||
public SoundSpecifier? SnoughSound;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to spread the disease through the air
|
||||
/// </summary>
|
||||
@@ -32,9 +32,7 @@ namespace Content.Server.Disease
|
||||
|
||||
public override void Effect(DiseaseEffectArgs args)
|
||||
{
|
||||
if (SnoughSound != null)
|
||||
SoundSystem.Play(SnoughSound.GetSound(), Filter.Pvs(args.DiseasedEntity), args.DiseasedEntity, AudioHelpers.WithVariation(0.2f));
|
||||
EntitySystem.Get<DiseaseSystem>().SneezeCough(args.DiseasedEntity, args.Disease, SnoughMessage, AirTransmit);
|
||||
EntitySystem.Get<DiseaseSystem>().SneezeCough(args.DiseasedEntity, args.Disease, SnoughMessage, SnoughSound, AirTransmit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using Content.Server.Disease;
|
||||
using Content.Shared.Audio;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Traits.Assorted;
|
||||
@@ -14,7 +10,6 @@ public sealed class UncontrollableSnoughSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly DiseaseSystem _diseaseSystem = default!;
|
||||
[Dependency] private readonly AudioSystem _audioSystem = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
@@ -43,10 +38,7 @@ public sealed class UncontrollableSnoughSystem : EntitySystem
|
||||
snough.NextIncidentTime +=
|
||||
_random.NextFloat(snough.TimeBetweenIncidents.X, snough.TimeBetweenIncidents.Y);
|
||||
|
||||
if (snough.SnoughSound != null)
|
||||
_audioSystem.PlayPvs(snough.SnoughSound, snough.Owner);
|
||||
|
||||
_diseaseSystem.SneezeCough(snough.Owner, null, snough.SnoughMessage, false);
|
||||
_diseaseSystem.SneezeCough(snough.Owner, null, snough.SnoughMessage, snough.SnoughSound, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
using System.Linq;
|
||||
using Robust.Shared.Random;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Disease;
|
||||
using Content.Server.Disease.Components;
|
||||
using Content.Server.Drone.Components;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Server.Disease;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Server.Inventory;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Server.Speech;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Disease.Events;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Content.Shared.Zombies;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Zombies
|
||||
{
|
||||
@@ -37,6 +40,7 @@ namespace Content.Server.Zombies
|
||||
SubscribeLocalEvent<ZombieComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<ZombieComponent, MobStateChangedEvent>(OnMobState);
|
||||
SubscribeLocalEvent<ActiveZombieComponent, DamageChangedEvent>(OnDamage);
|
||||
SubscribeLocalEvent<ActiveZombieComponent, AttemptSneezeCoughEvent>(OnSneeze);
|
||||
SubscribeLocalEvent<ActiveZombieComponent, TryingToSleepEvent>(OnSleepAttempt);
|
||||
|
||||
}
|
||||
@@ -60,6 +64,11 @@ namespace Content.Server.Zombies
|
||||
DoGroan(uid, component);
|
||||
}
|
||||
|
||||
private void OnSneeze(EntityUid uid, ActiveZombieComponent component, ref AttemptSneezeCoughEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private float GetZombieInfectionChance(EntityUid uid, ZombieComponent component)
|
||||
{
|
||||
var baseChance = component.MaxZombieInfectionChance;
|
||||
|
||||
10
Content.Shared/Disease/Events/AttemptSneezeCoughEvent.cs
Normal file
10
Content.Shared/Disease/Events/AttemptSneezeCoughEvent.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Shared.Disease.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Raised by an entity about to sneeze/cough.
|
||||
/// Set Cancelled to true on event handling to suppress the sneeze
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct AttemptSneezeCoughEvent(EntityUid uid, string SnoughMessage, SoundSpecifier? SnoughSound, bool Cancelled = false);
|
||||
@@ -5,6 +5,7 @@ using Content.Shared.Alert;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Disease.Events;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Emoting;
|
||||
using Content.Shared.FixedPoint;
|
||||
@@ -58,6 +59,7 @@ namespace Content.Shared.MobState.EntitySystems
|
||||
SubscribeLocalEvent<MobStateComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, StandAttemptEvent>(OnStandAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, AttemptSneezeCoughEvent>(OnSneezeAttempt);
|
||||
SubscribeLocalEvent<MobStateChangedEvent>(OnStateChanged);
|
||||
// Note that there's no check for Down attempts because if a mob's in crit or dead, they can be downed...
|
||||
}
|
||||
@@ -68,6 +70,12 @@ namespace Content.Shared.MobState.EntitySystems
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnSneezeAttempt(EntityUid uid, MobStateComponent component, ref AttemptSneezeCoughEvent args)
|
||||
{
|
||||
if(IsDead(uid, component))
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnGettingStripped(EntityUid uid, MobStateComponent component, BeforeGettingStrippedEvent args)
|
||||
{
|
||||
// Incapacitated or dead targets get stripped two or three times as fast. Makes stripping corpses less tedious.
|
||||
|
||||
Reference in New Issue
Block a user