Fix dead mobs falling asleep (#12917)
* Dead or zombie mobs can no longer sleep * Removed zombie fix * Moved dead-checks to OnEvent * Cleanup
This commit is contained in:
@@ -178,6 +178,10 @@ namespace Content.Server.Bed.Sleep
|
||||
if (!HasComp<MobStateComponent>(uid))
|
||||
return false;
|
||||
|
||||
var tryingToSleepEvent = new TryingToSleepEvent(uid);
|
||||
RaiseLocalEvent(uid, ref tryingToSleepEvent);
|
||||
if (tryingToSleepEvent.Cancelled) return false;
|
||||
|
||||
if (_prototypeManager.TryIndex<InstantActionPrototype>("Sleep", out var sleepAction))
|
||||
_actionsSystem.RemoveAction(uid, sleepAction);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ using Content.Server.Inventory;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Server.Speech;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Weapons.Melee.Events;
|
||||
using Content.Shared.Zombies;
|
||||
@@ -37,9 +37,15 @@ namespace Content.Server.Zombies
|
||||
SubscribeLocalEvent<ZombieComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<ZombieComponent, MobStateChangedEvent>(OnMobState);
|
||||
SubscribeLocalEvent<ActiveZombieComponent, DamageChangedEvent>(OnDamage);
|
||||
SubscribeLocalEvent<ActiveZombieComponent, TryingToSleepEvent>(OnSleepAttempt);
|
||||
|
||||
}
|
||||
|
||||
private void OnSleepAttempt(EntityUid uid, ActiveZombieComponent component, ref TryingToSleepEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnMobState(EntityUid uid, ZombieComponent component, MobStateChangedEvent args)
|
||||
{
|
||||
if (args.CurrentMobState == DamageState.Alive)
|
||||
|
||||
8
Content.Shared/Bed/Sleep/TryingToSleepEvent.cs
Normal file
8
Content.Shared/Bed/Sleep/TryingToSleepEvent.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Content.Shared.Bed.Sleep;
|
||||
|
||||
/// <summary>
|
||||
/// Raised by an entity about to fall asleep.
|
||||
/// Set Cancelled to true on event handling to interrupt
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct TryingToSleepEvent(EntityUid uid, bool Cancelled = false);
|
||||
@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Bed.Sleep;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DragDrop;
|
||||
@@ -56,10 +57,17 @@ namespace Content.Shared.MobState.EntitySystems
|
||||
SubscribeLocalEvent<MobStateComponent, DamageChangedEvent>(UpdateState);
|
||||
SubscribeLocalEvent<MobStateComponent, UpdateCanMoveEvent>(OnMoveAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, StandAttemptEvent>(OnStandAttempt);
|
||||
SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
|
||||
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...
|
||||
}
|
||||
|
||||
private void OnSleepAttempt(EntityUid uid, MobStateComponent component, ref TryingToSleepEvent 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