Fix cleanbots (#16922)
This commit is contained in:
@@ -1,106 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ using Content.Server.Interaction;
|
|||||||
using Content.Shared.Access.Systems;
|
using Content.Shared.Access.Systems;
|
||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Server.NPC;
|
namespace Content.Server.NPC;
|
||||||
@@ -60,6 +61,7 @@ public sealed class NPCBlackboard : IEnumerable<KeyValuePair<string, object>>
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Pure]
|
||||||
public bool ContainsKey(string key)
|
public bool ContainsKey(string key)
|
||||||
{
|
{
|
||||||
return _blackboard.ContainsKey(key);
|
return _blackboard.ContainsKey(key);
|
||||||
@@ -68,6 +70,7 @@ public sealed class NPCBlackboard : IEnumerable<KeyValuePair<string, object>>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the blackboard data for a particular key.
|
/// Get the blackboard data for a particular key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Pure]
|
||||||
public T GetValue<T>(string key)
|
public T GetValue<T>(string key)
|
||||||
{
|
{
|
||||||
return (T) _blackboard[key];
|
return (T) _blackboard[key];
|
||||||
@@ -76,6 +79,7 @@ public sealed class NPCBlackboard : IEnumerable<KeyValuePair<string, object>>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tries to get the blackboard data for a particular key. Returns default if not found
|
/// Tries to get the blackboard data for a particular key. Returns default if not found
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Pure]
|
||||||
public T? GetValueOrDefault<T>(string key, IEntityManager entManager)
|
public T? GetValueOrDefault<T>(string key, IEntityManager entManager)
|
||||||
{
|
{
|
||||||
if (_blackboard.TryGetValue(key, out var value))
|
if (_blackboard.TryGetValue(key, out var value))
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server.NPC.Queries.Queries;
|
|
||||||
|
|
||||||
public sealed class NearbyComponentsQuery : UtilityQuery
|
|
||||||
{
|
|
||||||
[DataField("components")]
|
|
||||||
public ComponentRegistry Component = default!;
|
|
||||||
}
|
|
||||||
6
Content.Server/NPC/Queries/Queries/PuddleFilter.cs
Normal file
6
Content.Server/NPC/Queries/Queries/PuddleFilter.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Content.Server.NPC.Queries.Queries;
|
||||||
|
|
||||||
|
public sealed class PuddleFilter : UtilityQueryFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Server.Chemistry.EntitySystems;
|
||||||
using Content.Server.Examine;
|
using Content.Server.Examine;
|
||||||
|
using Content.Server.Fluids.EntitySystems;
|
||||||
using Content.Server.NPC.Queries;
|
using Content.Server.NPC.Queries;
|
||||||
using Content.Server.NPC.Queries.Considerations;
|
using Content.Server.NPC.Queries.Considerations;
|
||||||
using Content.Server.NPC.Queries.Curves;
|
using Content.Server.NPC.Queries.Curves;
|
||||||
@@ -8,8 +10,10 @@ using Content.Server.Nutrition.Components;
|
|||||||
using Content.Server.Nutrition.EntitySystems;
|
using Content.Server.Nutrition.EntitySystems;
|
||||||
using Content.Server.Storage.Components;
|
using Content.Server.Storage.Components;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
|
using Content.Shared.Fluids.Components;
|
||||||
using Content.Shared.Mobs.Systems;
|
using Content.Shared.Mobs.Systems;
|
||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
|
using Robust.Shared.Collections;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.NPC.Systems;
|
namespace Content.Server.NPC.Systems;
|
||||||
@@ -23,9 +27,11 @@ public sealed class NPCUtilitySystem : EntitySystem
|
|||||||
[Dependency] private readonly ContainerSystem _container = default!;
|
[Dependency] private readonly ContainerSystem _container = default!;
|
||||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
[Dependency] private readonly FactionSystem _faction = default!;
|
[Dependency] private readonly FactionSystem _faction = default!;
|
||||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
|
||||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
||||||
[Dependency] private readonly FoodSystem _food = default!;
|
[Dependency] private readonly FoodSystem _food = default!;
|
||||||
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||||
|
[Dependency] private readonly PuddleSystem _puddle = default!;
|
||||||
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||||
|
[Dependency] private readonly SolutionContainerSystem _solutions = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs the UtilityQueryPrototype and returns the best-matching entities.
|
/// Runs the UtilityQueryPrototype and returns the best-matching entities.
|
||||||
@@ -269,10 +275,31 @@ public sealed class NPCUtilitySystem : EntitySystem
|
|||||||
|
|
||||||
private void Filter(NPCBlackboard blackboard, HashSet<EntityUid> entities, UtilityQueryFilter filter)
|
private void Filter(NPCBlackboard blackboard, HashSet<EntityUid> entities, UtilityQueryFilter filter)
|
||||||
{
|
{
|
||||||
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
|
||||||
|
|
||||||
switch (filter)
|
switch (filter)
|
||||||
{
|
{
|
||||||
|
case PuddleFilter:
|
||||||
|
{
|
||||||
|
var puddleQuery = GetEntityQuery<PuddleComponent>();
|
||||||
|
|
||||||
|
var toRemove = new ValueList<EntityUid>();
|
||||||
|
|
||||||
|
foreach (var ent in entities)
|
||||||
|
{
|
||||||
|
if (!puddleQuery.TryGetComponent(ent, out var puddleComp) ||
|
||||||
|
!_solutions.TryGetSolution(ent, puddleComp.SolutionName, out var sol) ||
|
||||||
|
_puddle.CanFullyEvaporate(sol))
|
||||||
|
{
|
||||||
|
toRemove.Add(ent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var ent in toRemove)
|
||||||
|
{
|
||||||
|
entities.Remove(ent);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,30 @@
|
|||||||
branches:
|
branches:
|
||||||
- tasks:
|
- tasks:
|
||||||
- id: PickPuddlePrimitive
|
- id: PickPuddlePrimitive
|
||||||
- id: MoveToAccessiblePrimitive
|
- id: MoveToCombatTargetPrimitive
|
||||||
- id: InteractWithPrimitive
|
- id: MopPrimitive
|
||||||
|
|
||||||
- type: htnPrimitive
|
- type: htnPrimitive
|
||||||
id: PickPuddlePrimitive
|
id: PickPuddlePrimitive
|
||||||
operator: !type:PickPuddleOperator
|
operator: !type:UtilityOperator
|
||||||
rangeKey: BufferRange
|
proto: NearbyPuddles
|
||||||
targetKey: MovementTarget
|
|
||||||
component: Puddle
|
|
||||||
|
|
||||||
- type: htnPrimitive
|
- type: htnPrimitive
|
||||||
id: SetIdleTimePrimitive
|
id: SetIdleTimePrimitive
|
||||||
operator: !type:SetFloatOperator
|
operator: !type:SetFloatOperator
|
||||||
targetKey: IdleTime
|
targetKey: IdleTime
|
||||||
amount: 3
|
amount: 3
|
||||||
|
|
||||||
|
- type: htnPrimitive
|
||||||
|
id: MopPrimitive
|
||||||
|
preconditions:
|
||||||
|
- !type:TargetInRangePrecondition
|
||||||
|
targetKey: CombatTarget
|
||||||
|
rangeKey: InteractRange
|
||||||
|
operator: !type:InteractWithOperator
|
||||||
|
targetKey: CombatTarget
|
||||||
|
services:
|
||||||
|
- !type:UtilityService
|
||||||
|
id: PuddleService
|
||||||
|
proto: NearbyPuddles
|
||||||
|
key: CombatTarget
|
||||||
|
|||||||
@@ -35,6 +35,22 @@
|
|||||||
- !type:TargetInLOSOrCurrentCon
|
- !type:TargetInLOSOrCurrentCon
|
||||||
curve: !type:BoolCurve
|
curve: !type:BoolCurve
|
||||||
|
|
||||||
|
- type: utilityQuery
|
||||||
|
id: NearbyPuddles
|
||||||
|
query:
|
||||||
|
- !type:ComponentQuery
|
||||||
|
components:
|
||||||
|
- type: Puddle
|
||||||
|
- !type:PuddleFilter
|
||||||
|
considerations:
|
||||||
|
- !type:TargetDistanceCon
|
||||||
|
curve: !type:PresetCurve
|
||||||
|
preset: TargetDistance
|
||||||
|
- !type:TargetAccessibleCon
|
||||||
|
curve: !type:BoolCurve
|
||||||
|
- !type:TargetInLOSOrCurrentCon
|
||||||
|
curve: !type:BoolCurve
|
||||||
|
|
||||||
- type: utilityQuery
|
- type: utilityQuery
|
||||||
id: NearbyRangedTargets
|
id: NearbyRangedTargets
|
||||||
query:
|
query:
|
||||||
|
|||||||
Reference in New Issue
Block a user