BotItems component used by AI bots to trigger item use. It checks inventory validity, debounces with a UseInterval, builds a BotItemContext based on current inputs and nearby car state, asks the held item if the bot should use it, and sets data.UseItem and next use time when appropriate.
namespace Machines.Items;
/// <summary>
/// Logic for bots using items
/// </summary>
public sealed class BotItems
{
/// <summary>
/// Min gap between item uses (debounce).
/// </summary>
private const float UseInterval = 0.5f;
private float _nextUseTime;
public void Apply( ref Player.CarInputData data, CarInventory inv, bool hasFrontCar, float frontDistance )
{
if ( inv is null || !inv.IsValid() || !inv.HasItem || Time.Now < _nextUseTime )
return;
var ctx = new BotItemContext
{
Throttle = data.Throttle,
HasFrontCar = hasFrontCar,
FrontDistance = frontDistance
};
if ( !inv.Held.ShouldBotUse( ctx ) )
return;
data.UseItem = true;
_nextUseTime = Time.Now + UseInterval;
}
}