Method Idle
- Namespace
- GrindFest
- Assembly
- GrindFest.dll
Idle(string, float, bool, bool, bool, Predicate<ItemBehaviour>)
A simple bot that handles basic combat, looting, and survival in a specified area. Call this method repeatedly to make your hero automatically fight and survive.
public static void Idle(string area = null, float healthPotionThreshold = 0.4, bool autoEquip = true, bool autoAttack = true, bool autoLoot = true, Predicate<ItemBehaviour> lootFilter = null)
Parameters
areastringThe area where the bot should operate. On level 1 defaults to "Stony Plains".
healthPotionThresholdfloatHealth percentage (0.0 to 1.0) at which to start drinking potions. Set to 0 or negative to disable potions.
autoEquipboolWhether the bot should automatically equip better gear.
autoAttackboolWhether the bot should automatically attack enemies.
autoLootboolWhether the bot should automatically loot items.
lootFilterPredicate<ItemBehaviour>Filter which items to pick up. Default picks up better weapons, health potions and gold.
Remarks
See the following tutorials for more information:
This bot will:
- Navigate to the specified area if not already there
- Use health potions in two scenarios:
- When below the specified health percentage threshold during combat
- When health is not full and no enemies are around
- Attack nearest enemies when health is good
- Pick up nearby items when no enemies around
- Run around exploring when nothing else to do
// Just call Hero.Idle() to use the basic bot
Hero.Idle();Hero.Idle("Crimson Meadows");Hero.Idle(healthPotionThreshold: 0.3f);Hero.Idle(healthPotionThreshold: 0, autoEquip: false);// A lootFilter is a function that looks at each item and decides if we should pick it up
// It returns true if we should pick up the item, or false if we should ignore it
// Pick up everything:
Hero.Idle(lootFilter: item => true);
Copying the source code of this method to your own script is a good starting point for creating your own bot.
string area = null;
float healthPotionThreshold = 0.4f;
bool autoEquip = true;
bool autoAttack = true;
bool autoLoot = true;
Predicate<ItemBehaviour> lootFilter = null;
if (healthPotionThreshold > 0)
{
// Hero.Health management - drink potions if health is low, only if we have potions
if (Hero.HasHealthPotion())
{
// if there are no enemies around and health is not full, drink potions
if (Hero.Health < Hero.MaxHealth && Hero.FindNearestEnemy(maxDistance: 5) == null)
{
Hero.DrinkHealthPotion();
Hero.RunAwayFromNearestEnemy();
return; // Drinking potions to full health is a priority
}
// drink potions if below threshold or continue drinking until full
if (Hero.Health < Hero.MaxHealth * healthPotionThreshold)
{
Hero.DrinkHealthPotion();
Hero.RunAwayFromNearestEnemy();
return; // Drinking potions is a priority
}
}
}
if (autoEquip)
{
Hero.OptimizeEquipment();
}
if (autoAttack)
{
// Combat - attack enemies if health is good
if (Hero.AttackNearestEnemy(10))
{
return; // Currently fighting an enemy
}
}
// Don't loot if inventory is almost full
if (autoLoot && Hero.Character.Inventory.Container.TotalItemsWeight < Hero.Character.CarryingCapacity * 0.9f)
{
// Use default loot filter if none provided
if (lootFilter == null)
{
lootFilter = item =>
{
// Always pick up gold
if (item.Gold != null)
return true;
// Always pick up health potions
if (Hero.IsHealthPotion(item))
return true;
// Pick up better weapons
if (item.Weapon != null)
{
if (Hero.Equipment.Weapon == null)
return true;
if (Hero.Equipment.Weapon.Durability?.DurabilityPercentage < 0.2)
if (item.Weapon.DamagePerSecond > Hero.Equipment.Weapon.DamagePerSecond * 0.8)
return true;
if (item.Weapon.DamagePerSecond > Hero.Equipment.Weapon.DamagePerSecond)
return true;
}
// Pick up better armor
if (item.Armor != null)
{
if (Hero.Equipment[item.Equipable.Slot] == null)
return true;
if (Hero.Equipment[item.Equipable.Slot].Item.Durability?.DurabilityPercentage < 0.2)
if (item.Armor.Armor > Hero.Equipment[item.Equipable.Slot].Item.Armor?.Armor * 0.8)
return true;
if (item.Armor.Armor > Hero.Equipment[item.Equipable.Slot].Item.Armor?.Armor)
return true;
}
// Don't pick up other items by default
return false;
};
}
// Looting - pick up nearby items when not fighting
var item = Hero.FindNearestItemOnGround(lootFilter, 10);
if (item != null)
{
// go to and pick up the item, return false until the item is picked up
var itemAmount = item.Amount;
var itemName = item.name;
Hero.PickUp(item, () => Hero.Log($"Found {(itemAmount > 1 ? $"<color=#FFAA00>{itemAmount}</color>" + " " : "")}<color=#{item.GetColor().ToHexStringRGB()}>{itemName}</color>!"));
//if (Hero.PickUp(item)) // go to and pick up the item, return false until the item is picked up
{
// Hero.Log($"Found {(item.Amount > 1 ? $"<color=#FFAA00>{item.Amount}</color>" + " " : "")}<color=#{item.GetColor().ToHexStringRGB()}>{item.name}</color>!"); // make the hero say what they found and how many, taking into account stackable items like gold coins
// return;
}
return; // Currently moving to item
}
}
if (area == null)
{
area = Hero.Level < 5 ? "Stony Plains" :
Hero.Level < 8 ? "Crimson Meadows" :
Hero.Level < 11 ? "Rotten Burrows" :
"Ashen Pastures";
}
// Ensure hero is in the area
if (Hero.CurrentArea?.Root.Name != area)
{
Hero.GoToArea(area);
return;
}
// Exploration - run around when nothing else to do
Hero.RunAroundInArea();