Deathgasp + last words / succumbing / fake deathgasp as crit actions (#18993)
This commit is contained in:
27
Content.Shared/Mobs/Components/MobStateActionsComponent.cs
Normal file
27
Content.Shared/Mobs/Components/MobStateActionsComponent.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Content.Shared.Mobs.Systems;
|
||||
|
||||
namespace Content.Shared.Mobs.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Used for specifying actions that should be automatically added/removed on mob state transitions
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Mostly for crit-specific actions.
|
||||
/// </remarks>
|
||||
/// <see cref="MobStateActionsSystem"/>
|
||||
[RegisterComponent]
|
||||
public sealed class MobStateActionsComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies a list of actions that should be available if a mob is in a given state.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// actions:
|
||||
/// Critical:
|
||||
/// - CritSuccumb
|
||||
/// Alive:
|
||||
/// - AnimalLayEgg
|
||||
/// </example>
|
||||
[DataField("actions")]
|
||||
public Dictionary<MobState, List<string>> Actions = new();
|
||||
}
|
||||
54
Content.Shared/Mobs/Systems/MobStateActionsSystem.cs
Normal file
54
Content.Shared/Mobs/Systems/MobStateActionsSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Mobs.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// Adds and removes defined actions when a mob's <see cref="MobState"/> changes.
|
||||
/// </summary>
|
||||
public sealed class MobStateActionsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<MobStateActionsComponent, MobStateChangedEvent>(OnMobStateChanged);
|
||||
}
|
||||
|
||||
private void OnMobStateChanged(EntityUid uid, MobStateActionsComponent component, MobStateChangedEvent args)
|
||||
{
|
||||
if (!TryComp<ActionsComponent>(uid, out var action))
|
||||
return;
|
||||
|
||||
foreach (var (state, acts) in component.Actions)
|
||||
{
|
||||
if (state != args.NewMobState && state != args.OldMobState)
|
||||
continue;
|
||||
|
||||
foreach (var item in acts)
|
||||
{
|
||||
if (!_proto.TryIndex<InstantActionPrototype>(item, out var proto))
|
||||
continue;
|
||||
|
||||
var instance = new InstantAction(proto);
|
||||
if (state == args.OldMobState)
|
||||
{
|
||||
// Don't remove actions that would be getting readded anyway
|
||||
if (component.Actions.TryGetValue(args.NewMobState, out var value)
|
||||
&& value.Contains(item))
|
||||
continue;
|
||||
|
||||
_actions.RemoveAction(uid, instance, action);
|
||||
}
|
||||
else if (state == args.NewMobState)
|
||||
{
|
||||
_actions.AddAction(uid, instance, null, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user