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;
|
2020-06-18 22:52:44 +10:00
|
|
|
|
|
|
|
|
namespace Content.Server.AI.Utility.Considerations.Hands
|
|
|
|
|
{
|
|
|
|
|
public class FreeHandCon : Consideration
|
|
|
|
|
{
|
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();
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
if (owner == null || !owner.TryGetComponent(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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|