Action, Action Container, and Action Upgrade changes (#24005)

* Added TransferActionWithNewAttached and TransferAllActionsWithNewAttached and OnActionAdded event method to ActionContainerSystem. These are needed where the action needs to have a different attached entity for usage.  Fixed a bug with not being able to upgrade actions between levels.  Added a way to grant and remove a singular action.

* adds an action container component to mind on action added to fix tests

* Swaps trycomp for hascomp

* Maybe this will fix the thests

* Grants action container to performer as well

* Wait that makes no sense, removing that

* fixes mind action grant logic

* Changes ent check back to netent check

* Reverts unintended container changes
This commit is contained in:
keronshb
2024-01-15 01:37:38 -05:00
committed by GitHub
parent ff3fe2e79b
commit c8466055ef
5 changed files with 182 additions and 22 deletions

View File

@@ -30,6 +30,7 @@ public sealed class ActionContainerSystem : EntitySystem
SubscribeLocalEvent<ActionsContainerComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<ActionsContainerComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
SubscribeLocalEvent<ActionsContainerComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
SubscribeLocalEvent<ActionsContainerComponent, ActionAddedEvent>(OnActionAdded);
SubscribeLocalEvent<ActionsContainerComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<ActionsContainerComponent, MindRemovedMessage>(OnMindRemoved);
}
@@ -38,7 +39,6 @@ public sealed class ActionContainerSystem : EntitySystem
{
if(!_mind.TryGetMind(uid, out var mindId, out _))
return;
if (!TryComp<ActionsContainerComponent>(mindId, out var mindActionContainerComp))
return;
@@ -174,6 +174,61 @@ public sealed class ActionContainerSystem : EntitySystem
DebugTools.AssertEqual(oldContainer.Container.Count, 0);
}
/// <summary>
/// Transfers an actions from one container to another, while changing the attached entity.
/// </summary>
/// <remarks>
/// This will actually remove and then re-grant the action.
/// Useful where you need to transfer from one container to another but also change the attached entity (ie spellbook > mind > user)
/// </remarks>
public void TransferActionWithNewAttached(
EntityUid actionId,
EntityUid newContainer,
EntityUid newAttached,
BaseActionComponent? action = null,
ActionsContainerComponent? container = null)
{
if (!_actions.ResolveActionData(actionId, ref action))
return;
if (action.Container == newContainer)
return;
var attached = newAttached;
if (!AddAction(newContainer, actionId, action, container))
return;
DebugTools.AssertEqual(action.Container, newContainer);
_actions.AddActionDirect(newAttached, actionId, action: action);
DebugTools.AssertEqual(action.AttachedEntity, attached);
}
/// <summary>
/// Transfers all actions from one container to another, while changing the attached entity.
/// </summary>
/// <remarks>
/// This will actually remove and then re-grant the action.
/// Useful where you need to transfer from one container to another but also change the attached entity (ie spellbook > mind > user)
/// </remarks>
public void TransferAllActionsWithNewAttached(
EntityUid from,
EntityUid to,
EntityUid newAttached,
ActionsContainerComponent? oldContainer = null,
ActionsContainerComponent? newContainer = null)
{
if (!Resolve(from, ref oldContainer) || !Resolve(to, ref newContainer))
return;
foreach (var action in oldContainer.Container.ContainedEntities.ToArray())
{
TransferActionWithNewAttached(action, to, newAttached, container: newContainer);
}
DebugTools.AssertEqual(oldContainer.Container.Count, 0);
}
/// <summary>
/// Adds a pre-existing action to an action container. If the action is already in some container it will first remove it.
/// </summary>
@@ -281,6 +336,12 @@ public sealed class ActionContainerSystem : EntitySystem
RaiseLocalEvent(uid, ref ev);
data.Container = null;
}
private void OnActionAdded(EntityUid uid, ActionsContainerComponent component, ActionAddedEvent args)
{
if (TryComp<MindComponent>(uid, out var mindComp) && mindComp.OwnedEntity != null && HasComp<ActionsContainerComponent>(mindComp.OwnedEntity.Value))
_actions.GrantContainedAction(mindComp.OwnedEntity.Value, uid, args.Action);
}
}
/// <summary>