HandsSystem Refactor (#38438)
* checkpoint * pt 2 * pt... i forgot * pt 4 * patch * More test fixes * optimization!!! * the REAL hand system * fix RetractableItemActionSystem.cs oversight * the review * test * remove test usage of body prototype * Update Content.IntegrationTests/Tests/Interaction/InteractionTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * hellcode * hellcode 2 * Minor cleanup * test * Chasing the last of the bugs * changes --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.NPC.HTN.Preconditions;
|
||||
@@ -18,14 +18,18 @@ public sealed partial class ActiveHandComponentPrecondition : HTNPrecondition
|
||||
|
||||
public override bool IsMet(NPCBlackboard blackboard)
|
||||
{
|
||||
if (!blackboard.TryGetValue<Hand>(NPCBlackboard.ActiveHand, out var hand, _entManager) || hand.HeldEntity == null)
|
||||
if (!blackboard.TryGetValue<EntityUid>(NPCBlackboard.Owner, out var owner, _entManager) ||
|
||||
!blackboard.TryGetValue<string>(NPCBlackboard.ActiveHand, out var hand, _entManager))
|
||||
{
|
||||
return Invert;
|
||||
}
|
||||
|
||||
if (!_entManager.System<HandsSystem>().TryGetHeldItem(owner, hand, out var entity))
|
||||
return Invert;
|
||||
|
||||
foreach (var comp in Components)
|
||||
{
|
||||
var hasComp = _entManager.HasComponent(hand.HeldEntity, comp.Value.Component.GetType());
|
||||
var hasComp = _entManager.HasComponent(entity, comp.Value.Component.GetType());
|
||||
|
||||
if (!hasComp ||
|
||||
Invert && hasComp)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Server.Hands.Systems;
|
||||
|
||||
namespace Content.Server.NPC.HTN.Preconditions;
|
||||
|
||||
@@ -11,11 +11,12 @@ public sealed partial class ActiveHandEntityPrecondition : HTNPrecondition
|
||||
|
||||
public override bool IsMet(NPCBlackboard blackboard)
|
||||
{
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out Hand? activeHand, _entManager))
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.Owner, out EntityUid owner, _entManager) ||
|
||||
!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out string? activeHand, _entManager))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return activeHand.HeldEntity != null;
|
||||
return !_entManager.System<HandsSystem>().HandIsEmpty(owner, activeHand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public sealed partial class DropOperator : HTNOperator
|
||||
|
||||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
||||
{
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out Hand? activeHand, _entManager))
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out string? activeHand, _entManager))
|
||||
{
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Inventory;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -152,6 +151,8 @@ public sealed partial class NPCBlackboard : IEnumerable<KeyValuePair<string, obj
|
||||
value = default;
|
||||
EntityUid owner;
|
||||
|
||||
var handSys = entManager.System<HandsSystem>();
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case Access:
|
||||
@@ -168,25 +169,24 @@ public sealed partial class NPCBlackboard : IEnumerable<KeyValuePair<string, obj
|
||||
case ActiveHand:
|
||||
{
|
||||
if (!TryGetValue(Owner, out owner, entManager) ||
|
||||
!entManager.TryGetComponent<HandsComponent>(owner, out var hands) ||
|
||||
hands.ActiveHand == null)
|
||||
handSys.GetActiveHand(owner) is not { } activeHand)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = hands.ActiveHand;
|
||||
value = activeHand;
|
||||
return true;
|
||||
}
|
||||
case ActiveHandFree:
|
||||
{
|
||||
if (!TryGetValue(Owner, out owner, entManager) ||
|
||||
!entManager.TryGetComponent<HandsComponent>(owner, out var hands) ||
|
||||
hands.ActiveHand == null)
|
||||
handSys.GetActiveHand(owner) is not { } activeHand)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = hands.ActiveHand.IsEmpty;
|
||||
value = handSys.HandIsEmpty((owner, hands), activeHand);
|
||||
return true;
|
||||
}
|
||||
case CanMove:
|
||||
@@ -204,16 +204,16 @@ public sealed partial class NPCBlackboard : IEnumerable<KeyValuePair<string, obj
|
||||
{
|
||||
if (!TryGetValue(Owner, out owner, entManager) ||
|
||||
!entManager.TryGetComponent<HandsComponent>(owner, out var hands) ||
|
||||
hands.ActiveHand == null)
|
||||
handSys.GetActiveHand(owner) is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var handos = new List<string>();
|
||||
|
||||
foreach (var (id, hand) in hands.Hands)
|
||||
foreach (var id in hands.Hands.Keys)
|
||||
{
|
||||
if (!hand.IsEmpty)
|
||||
if (!handSys.HandIsEmpty((owner, hands), id))
|
||||
continue;
|
||||
|
||||
handos.Add(id);
|
||||
@@ -226,16 +226,16 @@ public sealed partial class NPCBlackboard : IEnumerable<KeyValuePair<string, obj
|
||||
{
|
||||
if (!TryGetValue(Owner, out owner, entManager) ||
|
||||
!entManager.TryGetComponent<HandsComponent>(owner, out var hands) ||
|
||||
hands.ActiveHand == null)
|
||||
handSys.GetActiveHand(owner) is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var handos = new List<string>();
|
||||
|
||||
foreach (var (id, hand) in hands.Hands)
|
||||
foreach (var id in hands.Hands.Keys)
|
||||
{
|
||||
if (!hand.IsEmpty)
|
||||
if (!handSys.HandIsEmpty((owner, hands), id))
|
||||
continue;
|
||||
|
||||
handos.Add(id);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Server.NPC.Queries;
|
||||
using Content.Server.NPC.Queries.Considerations;
|
||||
using Content.Server.NPC.Queries.Curves;
|
||||
@@ -44,6 +45,7 @@ public sealed class NPCUtilitySystem : EntitySystem
|
||||
[Dependency] private readonly DrinkSystem _drink = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
[Dependency] private readonly FoodSystem _food = default!;
|
||||
[Dependency] private readonly HandsSystem _hands = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly NpcFactionSystem _npcFaction = default!;
|
||||
@@ -256,8 +258,9 @@ public sealed class NPCUtilitySystem : EntitySystem
|
||||
}
|
||||
case TargetAmmoMatchesCon:
|
||||
{
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out Hand? activeHand, EntityManager) ||
|
||||
!TryComp<BallisticAmmoProviderComponent>(activeHand.HeldEntity, out var heldGun))
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out string? activeHand, EntityManager) ||
|
||||
!_hands.TryGetHeldItem(owner, activeHand, out var heldEntity) ||
|
||||
!TryComp<BallisticAmmoProviderComponent>(heldEntity, out var heldGun))
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user