2020-06-18 22:52:44 +10:00
|
|
|
using Content.Server.AI.WorldState;
|
|
|
|
|
using Content.Server.AI.WorldState.States;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Utility.Considerations.Hands
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class FreeHandCon : Consideration
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
2020-07-08 09:37:35 +10:00
|
|
|
protected override float GetScore(Blackboard context)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
var owner = context.GetState<SelfState>().GetValue();
|
|
|
|
|
|
2022-02-21 14:41:50 +11:00
|
|
|
if (!owner.IsValid() || !IoCManager.Resolve<IEntityManager>().TryGetComponent(owner, out HandsComponent? handsComponent))
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var handCount = 0;
|
|
|
|
|
var freeCount = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var hand in handsComponent.ActivePriorityEnumerable())
|
|
|
|
|
{
|
|
|
|
|
handCount++;
|
2020-07-25 15:11:16 +02:00
|
|
|
if (handsComponent.GetItem(hand) == null)
|
2020-06-18 22:52:44 +10:00
|
|
|
{
|
|
|
|
|
freeCount += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (float) freeCount / handCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|