Medibot Fix (#18063)

This commit is contained in:
Arendian
2023-07-15 21:59:45 +02:00
committed by GitHub
parent b3a1b97919
commit 040cfe3aae
5 changed files with 31 additions and 25 deletions

View File

@@ -53,8 +53,6 @@ public sealed class MedibotInjectOperator : HTNOperator
if (!_entMan.TryGetComponent<MedibotComponent>(owner, out var botComp))
return HTNOperatorStatus.Failed;
// To avoid spam, the rest of this needs fixing.
_entMan.EnsureComponent<NPCRecentlyInjectedComponent>(target);
if (!_entMan.TryGetComponent<DamageableComponent>(target, out var damage))
return HTNOperatorStatus.Failed;
@@ -65,18 +63,14 @@ public sealed class MedibotInjectOperator : HTNOperator
if (!_interaction.InRangeUnobstructed(owner, target))
return HTNOperatorStatus.Failed;
// if emagged, always treat below-crit as injured (give funny juice to healthy people)
var total = damage.TotalDamage;
if (_entMan.HasComponent<EmaggedComponent>(owner) && total < MedibotComponent.EmergencyMedDamageThreshold)
{
total = MedibotComponent.EmergencyMedDamageThreshold;
}
if (total == 0)
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);
@@ -84,8 +78,9 @@ public sealed class MedibotInjectOperator : HTNOperator
return HTNOperatorStatus.Finished;
}
if (total >= MedibotComponent.StandardMedDamageThreshold)
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);

View File

@@ -6,6 +6,8 @@ using Content.Server.NPC.Pathfinding;
using Content.Shared.Damage;
using Content.Shared.Interaction;
using Content.Shared.Mobs.Components;
using Content.Shared.Silicons.Bots;
using Content.Shared.Emag.Components;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Specific;
@@ -54,21 +56,27 @@ public sealed class PickNearbyInjectableOperator : HTNOperator
if (mobState.HasComponent(entity) &&
injectQuery.HasComponent(entity) &&
damageQuery.TryGetComponent(entity, out var damage) &&
damage.TotalDamage > 0 &&
!recentlyInjected.HasComponent(entity))
{
var path = await _pathfinding.GetPath(owner, entity, SharedInteractionSystem.InteractionRange, cancelToken);
if (path.Result == PathResult.NoPath)
continue;
return (true, new Dictionary<string, object>()
//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))
{
{TargetKey, entity},
{TargetMoveKey, _entManager.GetComponent<TransformComponent>(entity).Coordinates},
{NPCBlackboard.PathfindKey, path},
});
}
//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},
});
}
}
return (false, null);