Files
tbd-station-14/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Specific/MedibotInjectOperator.cs
godisdeadLOL aea4e3cdbd Sentient medibot now can inject (#32110)
medibot player injection

Co-authored-by: YourUsername <you@example.com>
2025-01-29 13:34:01 +03:00

66 lines
2.5 KiB
C#

using Content.Server.Chat.Systems;
using Content.Shared.NPC.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.Emag.Components;
using Content.Shared.Interaction;
using Content.Shared.Mobs.Components;
using Content.Shared.Popups;
using Content.Shared.Silicons.Bots;
using Robust.Shared.Audio.Systems;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
public sealed partial class MedibotInjectOperator : HTNOperator
{
[Dependency] private readonly IEntityManager _entMan = default!;
private ChatSystem _chat = default!;
private MedibotSystem _medibot = default!;
private SharedAudioSystem _audio = default!;
private SharedInteractionSystem _interaction = default!;
private SharedPopupSystem _popup = default!;
private SharedSolutionContainerSystem _solutionContainer = default!;
/// <summary>
/// Target entity to inject.
/// </summary>
[DataField("targetKey", required: true)]
public string TargetKey = string.Empty;
public override void Initialize(IEntitySystemManager sysManager)
{
base.Initialize(sysManager);
_chat = sysManager.GetEntitySystem<ChatSystem>();
_medibot = sysManager.GetEntitySystem<MedibotSystem>();
_audio = sysManager.GetEntitySystem<SharedAudioSystem>();
_interaction = sysManager.GetEntitySystem<SharedInteractionSystem>();
_popup = sysManager.GetEntitySystem<SharedPopupSystem>();
_solutionContainer = sysManager.GetEntitySystem<SharedSolutionContainerSystem>();
}
public override void TaskShutdown(NPCBlackboard blackboard, HTNOperatorStatus status)
{
base.TaskShutdown(blackboard, status);
blackboard.Remove<EntityUid>(TargetKey);
}
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
{
// TODO: Wat
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
if (!blackboard.TryGetValue<EntityUid>(TargetKey, out var target, _entMan) || _entMan.Deleted(target))
return HTNOperatorStatus.Failed;
if (!_entMan.TryGetComponent<MedibotComponent>(owner, out var botComp))
return HTNOperatorStatus.Failed;
if (!_medibot.CheckInjectable((owner, botComp), target) || !_medibot.TryInject((owner, botComp), target))
return HTNOperatorStatus.Failed;
_chat.TrySendInGameICMessage(owner, Loc.GetString("medibot-finish-inject"), InGameICChatType.Speak, hideChat: true, hideLog: true);
return HTNOperatorStatus.Finished;
}
}