Shooting NPCs and more (#18042)
* Add pirate shooting * Shooting working * Basics working * Refactor time * More conversion * Update primitives * Update yml * weh * Building again * Draft * weh * b * Start shutdown * Starting to take form * Code side done * is it worky * Fix prototypes * stuff * Shitty working * Juke events working * Even more cleanup * RTX * Fix interaction combat mode and compquery * GetAmmoCount relays * Fix rotation speed * Juke fixes * fixes * weh * The collision avoidance never ends * Fixes * Pause support * framework * lazy * Fix idling * Fix drip * goobed * Fix takeover shutdown bug * Merge fixes * shitter * Fix carpos
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions;
|
||||
|
||||
public sealed class AltInteractOperator : HTNOperator
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
[DataField("targetKey")]
|
||||
public string Key = "Target";
|
||||
|
||||
/// <summary>
|
||||
/// If this alt-interaction started a do_after where does the key get stored.
|
||||
/// </summary>
|
||||
[DataField("idleKey")]
|
||||
public string IdleKey = "IdleTime";
|
||||
|
||||
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken)
|
||||
{
|
||||
return new(true, new Dictionary<string, object>()
|
||||
{
|
||||
{ IdleKey, 1f }
|
||||
});
|
||||
}
|
||||
|
||||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
||||
{
|
||||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
||||
var target = blackboard.GetValue<EntityUid>(Key);
|
||||
var intSystem = _entManager.System<SharedInteractionSystem>();
|
||||
var count = 0;
|
||||
|
||||
if (_entManager.TryGetComponent<DoAfterComponent>(owner, out var doAfter))
|
||||
{
|
||||
count = doAfter.DoAfters.Count;
|
||||
}
|
||||
|
||||
var result = intSystem.AltInteract(owner, target);
|
||||
|
||||
// Interaction started a doafter so set the idle time to it.
|
||||
if (result && doAfter != null && count != doAfter.DoAfters.Count)
|
||||
{
|
||||
var wait = doAfter.DoAfters.First().Value.Args.Delay;
|
||||
blackboard.SetValue(IdleKey, (float) wait.TotalSeconds + 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
blackboard.SetValue(IdleKey, 1f);
|
||||
}
|
||||
|
||||
return result ? HTNOperatorStatus.Finished : HTNOperatorStatus.Failed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Shared.Hands.Components;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions;
|
||||
|
||||
/// <summary>
|
||||
/// Drops the active hand entity underneath us.
|
||||
/// </summary>
|
||||
public sealed class DropOperator : HTNOperator
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
||||
{
|
||||
if (!blackboard.TryGetValue(NPCBlackboard.ActiveHand, out Hand? activeHand, _entManager))
|
||||
{
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
|
||||
var owner = blackboard.GetValueOrDefault<EntityUid>(NPCBlackboard.Owner, _entManager);
|
||||
// TODO: Need some sort of interaction cooldown probably.
|
||||
var handsSystem = _entManager.System<HandsSystem>();
|
||||
|
||||
if (handsSystem.TryDrop(owner))
|
||||
{
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
|
||||
return HTNOperatorStatus.Failed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Content.Server.Hands.Systems;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions;
|
||||
|
||||
public sealed class EquipOperator : HTNOperator
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
[DataField("target")]
|
||||
public string Target = "Target";
|
||||
|
||||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
||||
{
|
||||
if (!blackboard.TryGetValue<EntityUid>(Target, out var target, _entManager))
|
||||
{
|
||||
return HTNOperatorStatus.Failed;
|
||||
}
|
||||
|
||||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
||||
var handsSystem = _entManager.System<HandsSystem>();
|
||||
|
||||
// TODO: As elsewhere need some generic interaction cooldown system
|
||||
if (handsSystem.TryPickup(owner, target))
|
||||
{
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
|
||||
return HTNOperatorStatus.Failed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Content.Server.Interaction;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Timing;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions;
|
||||
|
||||
public sealed class InteractWithOperator : HTNOperator
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Key that contains the target entity.
|
||||
/// </summary>
|
||||
[DataField("targetKey", required: true)]
|
||||
public string TargetKey = default!;
|
||||
|
||||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
||||
{
|
||||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
||||
|
||||
if (_entManager.System<UseDelaySystem>().ActiveDelay(owner) ||
|
||||
!blackboard.TryGetValue<EntityUid>(TargetKey, out var moveTarget, _entManager) ||
|
||||
!_entManager.TryGetComponent<TransformComponent>(moveTarget, out var targetXform))
|
||||
{
|
||||
return HTNOperatorStatus.Continuing;
|
||||
}
|
||||
|
||||
_entManager.System<SharedCombatModeSystem>().SetInCombatMode(owner, false);
|
||||
_entManager.System<InteractionSystem>().UserInteraction(owner, targetXform.Coordinates, moveTarget);
|
||||
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Shared.Hands.Components;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Interactions;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Swaps to any free hand.
|
||||
/// </summary>
|
||||
public sealed class SwapToFreeHandOperator : HTNOperator
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard, CancellationToken cancelToken)
|
||||
{
|
||||
if (!blackboard.TryGetValue<List<string>>(NPCBlackboard.FreeHands, out var hands, _entManager) ||
|
||||
!_entManager.TryGetComponent<HandsComponent>(blackboard.GetValue<EntityUid>(NPCBlackboard.Owner), out var handsComp))
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
foreach (var hand in hands)
|
||||
{
|
||||
return (true, new Dictionary<string, object>()
|
||||
{
|
||||
{
|
||||
NPCBlackboard.ActiveHand, handsComp.Hands[hand]
|
||||
},
|
||||
{
|
||||
NPCBlackboard.ActiveHandFree, true
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
||||
{
|
||||
// TODO: Need interaction cooldown
|
||||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
||||
var handSystem = _entManager.System<HandsSystem>();
|
||||
|
||||
if (!handSystem.TrySelectEmptyHand(owner))
|
||||
{
|
||||
return HTNOperatorStatus.Failed;
|
||||
}
|
||||
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user