mastahg
Administrator
- Joined
- Feb 27, 2011
- Messages
- 5,355
Just a quick example.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Buddy.Coroutines;
using ff14bot.AClasses;
using ff14bot.Behavior;
using ff14bot.Enums;
using ff14bot.Helpers;
using ff14bot.Managers;
using TreeSharp;
namespace BetterCoroutineExample
{
public class BetterCoroutineExample : BotPlugin
{
internal async Task<bool> DoSomething()
{
foreach (var bagslot in InventoryManager.EquippedItems)
{
if (bagslot.BagId == InventoryBagId.Armory_MainHand)
continue;
if (bagslot.SpiritBond >= 100)
{
await CommonTasks.ConvertToMateria(bagslot);
}
}
//Don't block the logic below us in the tree.
return false;
}
public override void Dispose()
{
}
public override void Pulse()
{
}
public override string Author
{
get { return "Mastahg"; }
}
public override Version Version
{
get { return new Version(0, 0, 1); }
}
public override string Name
{
get { return "Better Coroutine example"; }
}
private Composite _coroutine;
public void OnInitialize()
{
//OnInitialize only gets called once, so create the object here so that it can be properly removed later.
_coroutine = new ActionRunCoroutine(r => DoSomething());
}
public override void OnShutdown()
{
}
public override void OnDisabled()
{
//Remove our event handler and remove our coroutine from the logic tree
TreeHooks.Instance.OnHooksCleared -= OnHooksCleared;
TreeHooks.Instance.RemoveHook("TreeStart", _coroutine);
}
public override void OnEnabled()
{
//Add our hook to the logic tree here and setup event handler for when the treehooks are cleared
//We want to add our hook here incase the user enables the plugin once the bot is already running.
TreeHooks.Instance.AddHook("TreeStart", _coroutine);
TreeHooks.Instance.OnHooksCleared += OnHooksCleared;
}
private void OnHooksCleared(object sender, EventArgs args)
{
TreeHooks.Instance.AddHook("TreeStart", _coroutine);
}
}
}