public static TriggerResult CheckTrigger(IBehaviorExecutionContext context) { var result = new TriggerResult {Active = false}; if (context != null && !ExecutionComplete) { // SET_TRIGGER_HERE } return result; }
public static TriggerResult operator &(TriggerResult t1, TriggerResult t2) { var ret = new TriggerResult() {HumanId = -1}; if (t1 != null && t2 != null) { ret.Active = t1.Active & t2.Active; ret.HumanInLoop = t1.HumanInLoop & t2.HumanInLoop; if (ret.HumanInLoop) { ret.HumanId = t1.HumanInLoop ? t1.HumanId : t2.HumanInLoop ? t2.HumanId : -1; } } return ret; }
public static TriggerResult operator |(TriggerResult t1, TriggerResult t2) { var ret = new TriggerResult(); if (t1 != null && t2 != null) { ret.Active = t1.Active | t2.Active; ret.HumanInLoop = t1.HumanInLoop | t2.HumanInLoop; ret.HumanId = t1.HumanInLoop ? t1.HumanId : t2.HumanInLoop ? t2.HumanId : -1; } return ret; }
public bool ExecuteInit(IBehaviorExecutionContext context, TriggerResult trigger) { if (!InitActionsComplete) { // INIT_BLOCK // INIT_BLOCK_HERE InitActionsComplete = true; } return InitActionsComplete; }
public bool Execute(IBehaviorExecutionContext context, TriggerResult trigger) { try { ExecuteInit(context, trigger); ExecuteCyclic(context, trigger); ExecuteExit(context, trigger); System.Console.WriteLine(@"Lifetime: {3} Init : {0}, Cyclic: {1}, Exit: {2}", InitActionsComplete, CyclicActionsComplete, ExitActionsComplete, ExecutionLifetime); } catch (BehaviorCanceledException ex) { Console.WriteLine(@"Execution canceled : {0}, {1} ,{2}", GetUid(), ex.Message, ex.StackTrace); } return ExecutionComplete; }
public bool ExecuteExit(IBehaviorExecutionContext context, TriggerResult trigger) { if (!ExitActionsComplete && CyclicActionsComplete) { // EXIT_BLOCK // EXIT_BLOCK_HERE ExitActionsComplete = true; } return ExitActionsComplete; }
public bool ExecuteCyclic(IBehaviorExecutionContext context, TriggerResult trigger) { if (!CyclicActionsComplete && InitActionsComplete) { // CYCLIC_BLOCK // CYCLIC_BLOCK_HERE if (ExecutionLifetime == BehaviorExecutionLifetime.once) { CyclicActionsComplete = true; } else if (ExecutionLifetime == BehaviorExecutionLifetime.until) { var complete = ExecutionUntil(context); CyclicActionsComplete = !complete; } } return CyclicActionsComplete; }