Files
tbd-station-14/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Melee/PickMeleeTargetOperator.cs
metalgearsloth 0286b88388 NPC refactor (#10122)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
2022-09-06 00:28:23 +10:00

34 lines
943 B
C#

using Robust.Shared.Map;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Melee;
/// <summary>
/// Selects a target for melee.
/// </summary>
public sealed class PickMeleeTargetOperator : NPCCombatOperator
{
protected override float GetRating(NPCBlackboard blackboard, EntityUid uid, EntityUid existingTarget, bool canMove, EntityQuery<TransformComponent> xformQuery)
{
var ourCoordinates = blackboard.GetValueOrDefault<EntityCoordinates>(NPCBlackboard.OwnerCoordinates);
if (!xformQuery.TryGetComponent(uid, out var targetXform))
return -1f;
var targetCoordinates = targetXform.Coordinates;
if (!ourCoordinates.TryDistance(EntManager, targetCoordinates, out var distance))
return -1f;
var rating = 0f;
if (existingTarget == uid)
{
rating += 3f;
}
rating += 1f / distance * 4f;
return rating;
}
}