mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-14 12:51:10 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
using Content.Server.Disposal.Unit;
|
|
using Content.Shared.Disposal.Components;
|
|
|
|
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
|
|
|
|
public sealed partial class DisposalInsertOperator : HTNOperator
|
|
{
|
|
[Dependency] private IEntityManager _entManager = default!;
|
|
private DisposalUnitSystem _disposalSystem = default!;
|
|
|
|
/// <summary>
|
|
/// Target entity to flush
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public string TargetKey = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Target disposal bin entity
|
|
/// </summary>
|
|
[DataField(required: true)]
|
|
public string DisposalTargetKey = string.Empty;
|
|
|
|
public override void Initialize(IEntitySystemManager sysManager)
|
|
{
|
|
base.Initialize(sysManager);
|
|
_disposalSystem = sysManager.GetEntitySystem<DisposalUnitSystem>();
|
|
}
|
|
|
|
public override void TaskShutdown(NPCBlackboard blackboard, HTNOperatorStatus status)
|
|
{
|
|
base.TaskShutdown(blackboard, status);
|
|
blackboard.Remove<EntityUid>(TargetKey);
|
|
blackboard.Remove<EntityUid>(DisposalTargetKey);
|
|
}
|
|
|
|
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
|
|
{
|
|
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
|
|
|
|
if (!blackboard.TryGetValue<EntityUid>(TargetKey, out var target, _entManager) || _entManager.Deleted(target))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
if (!blackboard.TryGetValue<EntityUid>(DisposalTargetKey, out var disposalUnitTarget, _entManager) || _entManager.Deleted(target))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
if (!_entManager.TryGetComponent<DisposalUnitComponent>(disposalUnitTarget, out var disposalComp))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
if (!_disposalSystem.TryInsert(disposalUnitTarget, target, owner, disposalComp))
|
|
return HTNOperatorStatus.Failed;
|
|
|
|
return HTNOperatorStatus.Finished;
|
|
|
|
}
|
|
}
|