Deathgasp + last words / succumbing / fake deathgasp as crit actions (#18993)

This commit is contained in:
Kara
2023-08-11 22:56:34 -07:00
committed by GitHub
parent eff36d2fe9
commit 7b51cebfea
20 changed files with 459 additions and 35 deletions

View File

@@ -0,0 +1,98 @@
using Content.Server.Administration;
using Content.Server.Chat.Systems;
using Content.Server.GameTicking;
using Content.Server.Mind.Components;
using Content.Shared.Actions;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Robust.Server.Console;
using Robust.Server.GameObjects;
using System;
namespace Content.Server.Mobs;
/// <summary>
/// Handles performing crit-specific actions.
/// </summary>
public sealed class CritMobActionsSystem : EntitySystem
{
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly DeathgaspSystem _deathgasp = default!;
[Dependency] private readonly IServerConsoleHost _host = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly QuickDialogSystem _quickDialog = default!;
private const int MaxLastWordsLength = 30;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MobStateActionsComponent, CritSuccumbEvent>(OnSuccumb);
SubscribeLocalEvent<MobStateActionsComponent, CritFakeDeathEvent>(OnFakeDeath);
SubscribeLocalEvent<MobStateActionsComponent, CritLastWordsEvent>(OnLastWords);
}
private void OnSuccumb(EntityUid uid, MobStateActionsComponent component, CritSuccumbEvent args)
{
if (!TryComp<ActorComponent>(uid, out var actor) || !_mobState.IsCritical(uid))
return;
_host.ExecuteCommand(actor.PlayerSession, "ghost");
args.Handled = true;
}
private void OnFakeDeath(EntityUid uid, MobStateActionsComponent component, CritFakeDeathEvent args)
{
if (!_mobState.IsCritical(uid))
return;
args.Handled = _deathgasp.Deathgasp(uid);
}
private void OnLastWords(EntityUid uid, MobStateActionsComponent component, CritLastWordsEvent args)
{
if (!TryComp<ActorComponent>(uid, out var actor))
return;
_quickDialog.OpenDialog(actor.PlayerSession, Loc.GetString("action-name-crit-last-words"), "",
(string lastWords) =>
{
if (actor.PlayerSession.AttachedEntity != uid
|| !_mobState.IsCritical(uid))
return;
if (lastWords.Length > MaxLastWordsLength)
{
lastWords = lastWords.Substring(0, MaxLastWordsLength);
}
lastWords += "...";
_chat.TrySendInGameICMessage(uid, lastWords, InGameICChatType.Whisper, ChatTransmitRange.Normal, ignoreActionBlocker: true);
_host.ExecuteCommand(actor.PlayerSession, "ghost");
});
args.Handled = true;
}
}
/// <summary>
/// Only applies to mobs in crit capable of ghosting/succumbing
/// </summary>
public sealed class CritSuccumbEvent : InstantActionEvent
{
}
/// <summary>
/// Only applies/has functionality to mobs in crit that have <see cref="DeathgaspComponent"/>
/// </summary>
public sealed class CritFakeDeathEvent : InstantActionEvent
{
}
/// <summary>
/// Only applies to mobs capable of speaking, as a last resort in crit
/// </summary>
public sealed class CritLastWordsEvent : InstantActionEvent
{
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chat.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Mobs;
/// <summary>
/// Mobs with this component will emote a deathgasp when they die.
/// </summary>
/// <see cref="DeathgaspSystem"/>
[RegisterComponent]
public sealed class DeathgaspComponent : Component
{
/// <summary>
/// The emote prototype to use.
/// </summary>
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EmotePrototype>))]
public string Prototype = "DefaultDeathgasp";
}

View File

@@ -0,0 +1,40 @@
using Content.Server.Chat.Systems;
using Content.Shared.Mobs;
using Robust.Shared.Prototypes;
namespace Content.Server.Mobs;
/// <see cref="DeathgaspComponent"/>
public sealed class DeathgaspSystem: EntitySystem
{
[Dependency] private readonly ChatSystem _chat = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DeathgaspComponent, MobStateChangedEvent>(OnMobStateChanged);
}
private void OnMobStateChanged(EntityUid uid, DeathgaspComponent component, MobStateChangedEvent args)
{
// don't deathgasp if they arent going straight from crit to dead
if (args.NewMobState != MobState.Dead || args.OldMobState != MobState.Critical)
return;
Deathgasp(uid, component);
}
/// <summary>
/// Causes an entity to perform their deathgasp emote, if they have one.
/// </summary>
public bool Deathgasp(EntityUid uid, DeathgaspComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return false;
_chat.TryEmoteWithChat(uid, component.Prototype, ignoreActionBlocker: true);
return true;
}
}