Action container rejig (#20260)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user