public override IEnumerable <BehaviorTree.RunStatus> Execute(ITreeRoot context) { float lastTime = context.Time; while (true) { if (lastTime + (TickTime) >= context.Time) { yield return(BehaviorTree.RunStatus.Running); } lastTime = context.Time; DecoratedChild.Start(context); while (DecoratedChild.Tick(context) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(context); if (DecoratedChild.LastStatus.HasValue) { if (DecoratedChild.LastStatus.Value == RunStatus.Success) { yield return(BehaviorTree.RunStatus.Success); yield break; } } } }
public override IEnumerable <RunStatus> Execute() { DecoratedChild.Start(); // While the child subtree is running, report that as our status RunStatus result; while ((result = DecoratedChild.Tick()) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(); // Return the opposite result that we received if (result == RunStatus.Failure) { yield return(RunStatus.Success); yield break; } yield return(RunStatus.Failure); yield break; }
public override IEnumerable <RunStatus> Execute(object context) { if (!CanRun(context)) { yield return(RunStatus.Success); yield break; } DecoratedChild.Start(context); while (DecoratedChild.Tick(context) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(context); if (DecoratedChild.LastStatus == RunStatus.Failure) { yield return(GetContinuationStatus()); yield break; } // Note: if the condition was met, and we succeeded in running the children, we HAVE to tell our parent // that we've ran successfully, or we'll skip down to the next child, regardless of whether we ran, or not. yield return(RunStatus.Success); yield break; }
public override IEnumerable <RunStatus> Execute(ITreeRoot context) { if (DecoratedChild == null) { yield return(RunStatus.Failure); yield break; } DecoratedChild.Start(context); while (true) { DecoratedChild.Tick(context); if (DecoratedChild.LastStatus.HasValue && DecoratedChild.LastStatus.Value == RunStatus.Running) { yield return(RunStatus.Running); continue; } DecoratedChild.Stop(context); if (DecoratedChild.LastStatus.HasValue && DecoratedChild.LastStatus.Value == RunStatus.Failure) { yield return(RunStatus.Failure); yield break; } DecoratedChild.Start(context); yield return(RunStatus.Running); } }
public override IEnumerable <BehaviorTree.RunStatus> Execute(ITreeRoot context) { if (DecoratedChild == null) { yield return(RunStatus.Failure); yield break; } DecoratedChild.Start(context); while (DecoratedChild.Tick(context) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(context); var last = DecoratedChild.LastStatus.Value; if (last == RunStatus.Success) { yield return(RunStatus.Failure); } else { yield return(RunStatus.Success); } }
public override IEnumerable <RunStatus> Execute() { DecoratedChild.Start(); // While the child subtree is running, report that as our status as well while (DecoratedChild.Tick() == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(); yield return(this.forced); yield break; }
public override IEnumerable <RunStatus> Execute(object context) { while (DateTime.Now < _end) { if (Runner != null) { if (Runner(context)) { break; } } else { if (CanRun(context)) { break; } } yield return(RunStatus.Running); } if (DateTime.Now < _end) { yield return(RunStatus.Failure); yield break; } DecoratedChild.Start(context); while (DecoratedChild.Tick(context) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(context); if (DecoratedChild.LastStatus == RunStatus.Failure) { yield return(RunStatus.Failure); yield break; } yield return(RunStatus.Success); yield break; }
protected override IEnumerable <RunStatus> Execute(object context) { if (DateTime.Now < _end && _count >= Limit) { yield return(_limitStatus); yield break; } // check not present in Decorator, but adding here if (DecoratedChild == null) { yield return(RunStatus.Failure); yield break; } DecoratedChild.Start(context); RunStatus childStatus; while ((childStatus = DecoratedChild.Tick(context)) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(context); if (DecoratedChild.LastStatus == RunStatus.Failure) { yield return(RunStatus.Failure); yield break; } if (DateTime.Now > _end) { _count = 0; _end = DateTime.Now + TimeFrame; } _count++; yield return(RunStatus.Success); yield break; }
public override IEnumerable <BehaviorTree.RunStatus> Execute(ITreeRoot context) { float lastTime = context.Time; while (true) { if (lastTime + (TickTime / 1000f) <= context.Time) { lastTime = context.Time; DecoratedChild.Start(context); while (DecoratedChild.Tick(context) == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(context); } yield return(BehaviorTree.RunStatus.Running); } }
public override IEnumerable <RunStatus> Execute() { // Keep track of the running iterations int curIter = 0; while (true) { this.DecoratedChild.Start(); RunStatus result; while ((result = DecoratedChild.Tick()) == RunStatus.Running) { yield return(RunStatus.Running); } this.DecoratedChild.Stop(); // If the child failed, break and report the failure if (result == RunStatus.Failure) { yield return(RunStatus.Failure); yield break; } // Increase the iteration count and see if we're done curIter++; if ((Iterations > 0) && (curIter >= Iterations)) { yield return(RunStatus.Success); yield break; } // Take one tick to prevent infinite loops yield return(RunStatus.Running); } }
public override IEnumerable <RunStatus> Execute(object context) { bool endless = execCount == -1; int i = 0; while (true) { if (DecoratedChild.LastStatus == null || DecoratedChild.LastStatus != RunStatus.Running) { DecoratedChild.Stop(context); DecoratedChild.Start(context); } DecoratedChild.Tick(context); i++; if (!endless && i == execCount - 1) //break out if iterations are done { yield return(RunStatus.Success); yield break; } yield return(RunStatus.Running); } }
public override IEnumerable <RunStatus> Execute() { // Keep track of the running iterations int curIter = 0; while (true) { DecoratedChild.Start(); while (DecoratedChild.Tick() == RunStatus.Running) { yield return(RunStatus.Running); } DecoratedChild.Stop(); // If the child failed, break and report the failure if (DecoratedChild.LastStatus == RunStatus.Failure) { yield return(RunStatus.Failure); yield break; } // Increase the number of iterations we're on, and see if we're done curIter++; if ((Iterations > 0) && (curIter >= Iterations)) { yield return(RunStatus.Success); yield break; } // Otherwise, pause once, then restart yield return(RunStatus.Running); } }