Action container rejig (#20260)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2023-09-23 04:49:39 -04:00
committed by GitHub
parent c80c90ed65
commit 684b334806
50 changed files with 889 additions and 740 deletions

View File

@@ -1,6 +1,5 @@
using Content.Shared.Actions;
using Content.Shared.Mobs.Components;
using Robust.Shared.Network;
namespace Content.Shared.Mobs.Systems;
@@ -9,7 +8,6 @@ namespace Content.Shared.Mobs.Systems;
/// </summary>
public sealed class MobStateActionsSystem : EntitySystem
{
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
/// <inheritdoc/>
@@ -20,33 +18,25 @@ public sealed class MobStateActionsSystem : EntitySystem
private void OnMobStateChanged(EntityUid uid, MobStateActionsComponent component, MobStateChangedEvent args)
{
if (_net.IsClient)
return;
if (!TryComp<ActionsComponent>(uid, out var action))
return;
foreach (var (state, acts) in component.Actions)
foreach (var act in component.GrantedActions)
{
if (state != args.NewMobState && state != args.OldMobState)
continue;
foreach (var item in acts)
{
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, item, action);
}
else if (state == args.NewMobState)
{
_actions.AddAction(uid, Spawn(item), null, action);
}
}
Del(act);
}
component.GrantedActions.Clear();
if (!component.Actions.TryGetValue(args.NewMobState, out var toGrant))
return;
foreach (var id in toGrant)
{
EntityUid? act = null;
if (_actions.AddAction(uid, ref act, id, uid, action))
component.GrantedActions.Add(act.Value);
}
Dirty(uid, component);
}
}