medibot fixes and refactoring (#21852)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -2,7 +2,9 @@ using Content.Server.Chat.Systems;
|
||||
using Content.Server.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;
|
||||
@@ -65,29 +67,23 @@ public sealed partial class MedibotInjectOperator : HTNOperator
|
||||
|
||||
var total = damage.TotalDamage;
|
||||
|
||||
if (total == 0)
|
||||
// always inject healthy patients when emagged
|
||||
if (total == 0 && !_entMan.HasComponent<EmaggedComponent>(owner))
|
||||
return HTNOperatorStatus.Failed;
|
||||
|
||||
if (total >= MedibotComponent.EmergencyMedDamageThreshold)
|
||||
{
|
||||
_entMan.EnsureComponent<NPCRecentlyInjectedComponent>(target);
|
||||
_solution.TryAddReagent(target, injectable, botComp.EmergencyMed, botComp.EmergencyMedAmount, out var accepted);
|
||||
_popup.PopupEntity(Loc.GetString("hypospray-component-feel-prick-message"), target, target);
|
||||
_audio.PlayPvs(botComp.InjectSound, target);
|
||||
_chat.TrySendInGameICMessage(owner, Loc.GetString("medibot-finish-inject"), InGameICChatType.Speak, ChatTransmitRange.GhostRangeLimit);
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
if (!_entMan.TryGetComponent<MobStateComponent>(target, out var mobState))
|
||||
return HTNOperatorStatus.Failed;
|
||||
|
||||
if (total >= MedibotComponent.StandardMedDamageThreshold && total <= MedibotComponent.StandardMedDamageThresholdStop)
|
||||
{
|
||||
_entMan.EnsureComponent<NPCRecentlyInjectedComponent>(target);
|
||||
_solution.TryAddReagent(target, injectable, botComp.StandardMed, botComp.StandardMedAmount, out var accepted);
|
||||
_popup.PopupEntity(Loc.GetString("hypospray-component-feel-prick-message"), target, target);
|
||||
_audio.PlayPvs(botComp.InjectSound, target);
|
||||
_chat.TrySendInGameICMessage(owner, Loc.GetString("medibot-finish-inject"), InGameICChatType.Speak, ChatTransmitRange.GhostRangeLimit);
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
var state = mobState.CurrentState;
|
||||
var treatment = botComp.Treatments[mobState.CurrentState];
|
||||
if (!treatment.IsValid(total))
|
||||
return HTNOperatorStatus.Failed;
|
||||
|
||||
return HTNOperatorStatus.Failed;
|
||||
_entMan.EnsureComponent<NPCRecentlyInjectedComponent>(target);
|
||||
_solution.TryAddReagent(target, injectable, treatment.Reagent, treatment.Quantity, out _);
|
||||
_popup.PopupEntity(Loc.GetString("hypospray-component-feel-prick-message"), target, target);
|
||||
_audio.PlayPvs(botComp.InjectSound, target);
|
||||
_chat.TrySendInGameICMessage(owner, Loc.GetString("medibot-finish-inject"), InGameICChatType.Speak, hideChat: true, hideLog: true);
|
||||
return HTNOperatorStatus.Finished;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public sealed partial class PickNearbyInjectableOperator : HTNOperator
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
private EntityLookupSystem _lookup = default!;
|
||||
private MedibotSystem _medibot = default!;
|
||||
private PathfindingSystem _pathfinding = default!;
|
||||
|
||||
[DataField("rangeKey")] public string RangeKey = NPCBlackboard.MedibotInjectRange;
|
||||
@@ -35,6 +36,7 @@ public sealed partial class PickNearbyInjectableOperator : HTNOperator
|
||||
{
|
||||
base.Initialize(sysManager);
|
||||
_lookup = sysManager.GetEntitySystem<EntityLookupSystem>();
|
||||
_medibot = sysManager.GetEntitySystem<MedibotSystem>();
|
||||
_pathfinding = sysManager.GetEntitySystem<PathfindingSystem>();
|
||||
}
|
||||
|
||||
@@ -46,37 +48,46 @@ public sealed partial class PickNearbyInjectableOperator : HTNOperator
|
||||
if (!blackboard.TryGetValue<float>(RangeKey, out var range, _entManager))
|
||||
return (false, null);
|
||||
|
||||
if (!_entManager.TryGetComponent<MedibotComponent>(owner, out var medibot))
|
||||
return (false, null);
|
||||
|
||||
var damageQuery = _entManager.GetEntityQuery<DamageableComponent>();
|
||||
var injectQuery = _entManager.GetEntityQuery<InjectableSolutionComponent>();
|
||||
var recentlyInjected = _entManager.GetEntityQuery<NPCRecentlyInjectedComponent>();
|
||||
var mobState = _entManager.GetEntityQuery<MobStateComponent>();
|
||||
var emaggedQuery = _entManager.GetEntityQuery<EmaggedComponent>();
|
||||
|
||||
foreach (var entity in _lookup.GetEntitiesInRange(owner, range))
|
||||
{
|
||||
if (mobState.HasComponent(entity) &&
|
||||
if (mobState.TryGetComponent(entity, out var state) &&
|
||||
injectQuery.HasComponent(entity) &&
|
||||
damageQuery.TryGetComponent(entity, out var damage) &&
|
||||
!recentlyInjected.HasComponent(entity))
|
||||
//Only go towards a target if the bot can actually help them or if the medibot is emagged
|
||||
if (damage.TotalDamage > MedibotComponent.StandardMedDamageThreshold &&
|
||||
damage.TotalDamage <= MedibotComponent.StandardMedDamageThresholdStop ||
|
||||
damage.TotalDamage > MedibotComponent.EmergencyMedDamageThreshold ||
|
||||
_entManager.HasComponent<EmaggedComponent>(owner))
|
||||
{
|
||||
// no treating dead bodies
|
||||
if (!_medibot.TryGetTreatment(medibot, state.CurrentState, out var treatment))
|
||||
continue;
|
||||
|
||||
// Only go towards a target if the bot can actually help them or if the medibot is emagged
|
||||
// note: this and the actual injecting don't check for specific damage types so for example,
|
||||
// radiation damage will trigger injection but the tricordrazine won't heal it.
|
||||
if (!emaggedQuery.HasComponent(entity) && !treatment.IsValid(damage.TotalDamage))
|
||||
continue;
|
||||
|
||||
//Needed to make sure it doesn't sometimes stop right outside it's interaction range
|
||||
var pathRange = SharedInteractionSystem.InteractionRange - 1f;
|
||||
var path = await _pathfinding.GetPath(owner, entity, pathRange, cancelToken);
|
||||
|
||||
if (path.Result == PathResult.NoPath)
|
||||
continue;
|
||||
|
||||
return (true, new Dictionary<string, object>()
|
||||
{
|
||||
//Needed to make sure it doesn't sometimes stop right outside it's interaction range
|
||||
var pathRange = SharedInteractionSystem.InteractionRange - 1f;
|
||||
var path = await _pathfinding.GetPath(owner, entity, pathRange, cancelToken);
|
||||
|
||||
if (path.Result == PathResult.NoPath)
|
||||
continue;
|
||||
|
||||
return (true, new Dictionary<string, object>()
|
||||
{
|
||||
{TargetKey, entity},
|
||||
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(entity).Coordinates},
|
||||
{NPCBlackboard.PathfindKey, path},
|
||||
});
|
||||
}
|
||||
{TargetKey, entity},
|
||||
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(entity).Coordinates},
|
||||
{NPCBlackboard.PathfindKey, path},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return (false, null);
|
||||
|
||||
Reference in New Issue
Block a user