make monkey disposals less laggy (#43842)

* fix up moneky

* review
This commit is contained in:
Jessica M
2026-05-09 16:30:12 -07:00
committed by GitHub
parent 68e8048033
commit 22ae35a624
2 changed files with 24 additions and 32 deletions
@@ -5,7 +5,6 @@ using Content.Shared.Interaction;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Whitelist;
using Robust.Server.Containers;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
@@ -17,7 +16,6 @@ public sealed partial class PickEntityNearMobOperator : HTNOperator
[Dependency] private IEntityManager _entManager = default!;
private EntityLookupSystem _lookup = default!;
private PathfindingSystem _pathfinding = default!;
private ContainerSystem _container = default!;
private EntityWhitelistSystem _entityWhitelist = default!;
/// <summary>
@@ -73,7 +71,6 @@ public sealed partial class PickEntityNearMobOperator : HTNOperator
base.Initialize(sysManager);
_lookup = sysManager.GetEntitySystem<EntityLookupSystem>();
_pathfinding = sysManager.GetEntitySystem<PathfindingSystem>();
_container = sysManager.GetEntitySystem<ContainerSystem>();
_entityWhitelist = sysManager.GetEntitySystem<EntityWhitelistSystem>();
}
@@ -85,47 +82,42 @@ public sealed partial class PickEntityNearMobOperator : HTNOperator
if (!blackboard.TryGetValue<float>(RangeKey, out var range, _entManager))
return (false, null);
if (!blackboard.TryGetValue<float>(RangeKey, out var mobRange, _entManager))
if (!blackboard.TryGetValue<float>(MobRangeKey, out var mobRange, _entManager))
return (false, null);
var mobState = _entManager.GetEntityQuery<MobStateComponent>();
foreach (var entity in _lookup.GetEntitiesInRange(owner, range))
foreach (var mob in _lookup.GetEntitiesInRange(owner, mobRange, LookupFlags.Uncontained & ~LookupFlags.Sensors))
{
if (!_entityWhitelist.CheckBoth(entity, Blacklist, Whitelist))
if (mob == owner)
continue;
//checking if there is anyone NEAR the entity we found
foreach (var mob in _lookup.GetEntitiesInRange(entity, mobRange))
if (!mobState.TryGetComponent(mob, out var state))
continue;
if (MobState != null && state.CurrentState != MobState)
continue;
foreach (var entity in _lookup.GetEntitiesInRange(mob, range))
{
if (mob == owner)
if (!_entityWhitelist.CheckBoth(entity, Blacklist, Whitelist))
continue;
if (_container.IsEntityInContainer(mob))
continue;
var pathRange = SharedInteractionSystem.InteractionRange;
var path = await _pathfinding.GetPath(owner, mob, pathRange, cancelToken);
if (mobState.TryGetComponent(mob, out var state))
if (path.Result == PathResult.NoPath)
return (false, null);
return (true, new Dictionary<string, object>()
{
if (MobState != null && state.CurrentState != MobState)
continue;
var pathRange = SharedInteractionSystem.InteractionRange;
var path = await _pathfinding.GetPath(owner, mob, pathRange, cancelToken);
if (path.Result == PathResult.NoPath)
return (false, null);
return (true, new Dictionary<string, object>()
{
{TargetKey, mob},
{NearbyEntityTargetKey, entity},
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(mob).Coordinates},
{NPCBlackboard.PathfindKey, path},
});
}
{TargetKey, mob},
{NearbyEntityTargetKey, entity},
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(mob).Coordinates},
{NPCBlackboard.PathfindKey, path},
});
}
}
return (false, null);
}
}
+2 -2
View File
@@ -14,12 +14,12 @@
- tasks:
- !type:HTNPrimitiveTask
operator: !type:PickEntityNearMobOperator
rangeKey: VisionRadius
rangeKey: InteractRange
targetKey: FlushableTarget
nearbyEntityTargetKey: DisposalBinTarget
targetMoveKey: TargetCoordinates
mobState: Critical
mobRangeKey: InteractRange
mobRangeKey: VisionRadius
whitelist:
components:
- DisposalUnit