Cleanbot tweaks (#15821)
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.NPC.Pathfinding;
|
||||
using Content.Shared.Fluids.Components;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Fluid;
|
||||
|
||||
/// <summary>
|
||||
/// Picks a nearby evaporatable puddle.
|
||||
/// </summary>
|
||||
public sealed class PickPuddleOperator : HTNOperator
|
||||
{
|
||||
// This is similar to PickAccessibleComponent however I have an idea on generic utility queries
|
||||
// that can also be re-used for melee that needs further fleshing out.
|
||||
|
||||
[Dependency] private readonly IComponentFactory _factory = default!;
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
private PathfindingSystem _pathfinding = default!;
|
||||
private EntityLookupSystem _lookup = default!;
|
||||
|
||||
[DataField("rangeKey", required: true)]
|
||||
public string RangeKey = string.Empty;
|
||||
|
||||
[DataField("target")] public string Target = "Target";
|
||||
|
||||
[DataField("targetKey", required: true)]
|
||||
public string TargetKey = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Where the pathfinding result will be stored (if applicable). This gets removed after execution.
|
||||
/// </summary>
|
||||
[DataField("pathfindKey")]
|
||||
public string PathfindKey = NPCBlackboard.PathfindKey;
|
||||
|
||||
public override void Initialize(IEntitySystemManager sysManager)
|
||||
{
|
||||
base.Initialize(sysManager);
|
||||
_lookup = sysManager.GetEntitySystem<EntityLookupSystem>();
|
||||
_pathfinding = sysManager.GetEntitySystem<PathfindingSystem>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[Obsolete("Obsolete")]
|
||||
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
|
||||
CancellationToken cancelToken)
|
||||
{
|
||||
var range = blackboard.GetValueOrDefault<float>(RangeKey, _entManager);
|
||||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
||||
|
||||
if (!blackboard.TryGetValue<EntityCoordinates>(NPCBlackboard.OwnerCoordinates, out var coordinates, _entManager))
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
var targets = new List<EntityUid>();
|
||||
var puddleSystem = _entManager.System<PuddleSystem>();
|
||||
var solSystem = _entManager.System<SolutionContainerSystem>();
|
||||
|
||||
foreach (var comp in _lookup.GetComponentsInRange<PuddleComponent>(coordinates, range))
|
||||
{
|
||||
if (comp.Owner == owner ||
|
||||
!solSystem.TryGetSolution(comp.Owner, comp.SolutionName, out var puddleSolution) ||
|
||||
puddleSystem.CanFullyEvaporate(puddleSolution))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
targets.Add((comp.Owner));
|
||||
}
|
||||
|
||||
if (targets.Count == 0)
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
foreach (var target in targets)
|
||||
{
|
||||
var path = await _pathfinding.GetPath(
|
||||
owner,
|
||||
target,
|
||||
1f,
|
||||
cancelToken,
|
||||
flags: _pathfinding.GetFlags(blackboard));
|
||||
|
||||
if (path.Result != PathResult.Path)
|
||||
{
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
var xform = _entManager.GetComponent<TransformComponent>(target);
|
||||
|
||||
return (true, new Dictionary<string, object>()
|
||||
{
|
||||
{ Target, target },
|
||||
{ TargetKey, xform.Coordinates },
|
||||
{ PathfindKey, path}
|
||||
});
|
||||
}
|
||||
|
||||
return (false, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Content.Server.Interaction;
|
||||
using Content.Shared.Timing;
|
||||
|
||||
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
|
||||
|
||||
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<InteractionSystem>().UserInteraction(owner, targetXform.Coordinates, moveTarget);
|
||||
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ public sealed class PickAccessibleComponentOperator : HTNOperator
|
||||
[DataField("targetKey", required: true)]
|
||||
public string TargetKey = string.Empty;
|
||||
|
||||
[DataField("target")]
|
||||
public string TargetEntity = "Target";
|
||||
|
||||
[DataField("component", required: true)]
|
||||
public string Component = string.Empty;
|
||||
|
||||
@@ -58,7 +61,7 @@ public sealed class PickAccessibleComponentOperator : HTNOperator
|
||||
|
||||
var compType = registration.Type;
|
||||
var query = _entManager.GetEntityQuery(compType);
|
||||
var targets = new List<Component>();
|
||||
var targets = new List<EntityUid>();
|
||||
|
||||
// TODO: Need to get ones that are accessible.
|
||||
// TODO: Look at unreal HTN to see repeatable ones maybe?
|
||||
@@ -68,7 +71,7 @@ public sealed class PickAccessibleComponentOperator : HTNOperator
|
||||
if (entity == owner || !query.TryGetComponent(entity, out var comp))
|
||||
continue;
|
||||
|
||||
targets.Add(comp);
|
||||
targets.Add(entity);
|
||||
}
|
||||
|
||||
if (targets.Count == 0)
|
||||
@@ -76,16 +79,12 @@ public sealed class PickAccessibleComponentOperator : HTNOperator
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
blackboard.TryGetValue<float>(RangeKey, out var maxRange, _entManager);
|
||||
|
||||
if (maxRange == 0f)
|
||||
maxRange = 7f;
|
||||
|
||||
while (targets.Count > 0)
|
||||
foreach (var target in targets)
|
||||
{
|
||||
var path = await _pathfinding.GetRandomPath(
|
||||
var path = await _pathfinding.GetPath(
|
||||
owner,
|
||||
maxRange,
|
||||
target,
|
||||
1f,
|
||||
cancelToken,
|
||||
flags: _pathfinding.GetFlags(blackboard));
|
||||
|
||||
@@ -94,12 +93,13 @@ public sealed class PickAccessibleComponentOperator : HTNOperator
|
||||
return (false, null);
|
||||
}
|
||||
|
||||
var target = path.Path.Last().Coordinates;
|
||||
var xform = _entManager.GetComponent<TransformComponent>(target);
|
||||
|
||||
return (true, new Dictionary<string, object>()
|
||||
{
|
||||
{ TargetKey, target },
|
||||
{ PathfindKey, path}
|
||||
{ TargetEntity, target },
|
||||
{ TargetKey, xform.Coordinates },
|
||||
{ PathfindKey, path }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user