private TreeSharp.Composite DoSomething()
{
return new PrioritySelector(
new Decorator(ret => _me.IsAlive,
new Action(o => Lua.DoString("EatMe();"))));
}
public override void Pulse()
{
DoSomething();
}
Lol always with the EatMe()
Must be some buff food or something.
private object ctx;
private bool flag = true;
public override void OnButtonPress()
{
flag = true;
}
Composite _root;
private Composite Root
{
get
{
return _root ?? (_root = CreateABHelperBehavior());
}
}
private Composite CreateABHelperBehavior()
{
return new PrioritySelector(
new Action(ret => {
Logging.Write("It's working!!!!");
flag = false;
return RunStatus.Success;
})
);
}
public override void Initialize()
{
ctx = new object();
flag = true;
Root.Start(ctx);
}
public override void Pulse()
{
while(flag)
{
Root.Tick(ctx);
}
}
void PulseTree() {
// Assume root.Start(null) was called somewhere during init
while (flag)
{
try
{
root.Tick(null);
if (root.LastStatus != RunStatus.Running)
{
root.Stop(null);
root.Start(null);
}
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
Logging.Write(ex.ToString());
root.Stop(null);
root.Start(null);
}
}
}
So i actually need to Stop and then Start before each Tick?
using System;
using System.Threading;
using System.Windows.Forms;
using TreeSharp;
namespace strix
{
class TreeSharpRoot
{
private Composite _root;
public TreeSharpRoot(Composite newRoot)
{
_root = newRoot;
_root.Start(null);
}
public void PulseTree()
{
// Assume root.Start(null) was called somewhere during init
try
{
_root.Tick(null);
if(_root.LastStatus != RunStatus.Running)
{
_root.Stop(null);
_root.Start(null);
}
}
catch(ThreadAbortException)
{
throw;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
_root.Stop(null);
_root.Start(null);
}
}
}
}
static TreeSharpRoot btroot1 = new TreeSharpRoot( new ActionAlwaysSucceed( ) );
public override void Pulse()
{
btroot1.PulseTree();
}