private bool Run(string s, TreeSharp.Composite bt) { int nLoops = 0; bt.Start(this); do { bt.Tick(this); nLoops++; } while (bt.IsRunning); bt.Stop(this); if (nLoops > 1) { slog("Run('{0}'): performed {1} iterations", s, nLoops); } return(false); }
protected override TreeSharp.Composite CreateBehavior() { if (_behavior == null) { _behavior = new TreeSharp.PrioritySelector( new TreeSharp.Action(ret => { bool isDialogComplete = _completionToken.IsComplete; bool isProgressing = UtilIsProgressRequirementsMet(QuestId, QuestRequirementInLog, QuestRequirementComplete); // We're complete... wrap it up if (isDialogComplete || !isProgressing) { // If we're no longer progressing, we don't want to wait for the user response to close up shop... // Thus, we use UNKNOWN when not progressing. This will also keep us from blocking and waiting for // PopdownResponse to be populated by the UserDialogForm we're trying to close. UserDialogExitProcessing(isDialogComplete ? _completionToken.PopdownResponse : PopdownReason.PopdownCompletionCriteriaMet); _isBehaviorDone = true; return(TreeSharp.RunStatus.Success); } // If 'auto defend' is on and we're in combat, we skip this node to allow combat to take place // somewhere in our parent's subtree if (_completionToken.IsAutoDefend && StyxWoW.Me.IsActuallyInCombat) { return(TreeSharp.RunStatus.Failure); } // 'auto defend is off'... // RunStatus.Running returns us to this node. This allows the user to control everything manually-- // including combat return(TreeSharp.RunStatus.Running); }) ); } return(_behavior); }
/// <summary> /// Initializes scripts /// </summary> public override bool init() { EventObjects.eventInit(this, true); //Load the associated scripts _scripts = Scripts.instanceScripts(this, _scriptType); //If the bot implementes a BT, load it and use it. _BehaviorTrees = new List <TreeSharp.Composite>(); if (exists(BT_EVENT_KEY)) { //Grab all handlers (could be more then one BT). foreach (var mthHandler in events[BT_EVENT_KEY].methods) { TreeSharp.Composite x = mthHandler.handler(mthHandler.that, null) as TreeSharp.Composite; x.Start(null); _BehaviorTrees.Add(x); } } return(true); }