/// <summary>
 /// Notifies all listeners of a task's status getting updated
 /// </summary>
 /// <param name="task">task of which the status changed</param>
 /// <param name="previousState">the previous <see cref="BTTaskStatus"/></param>
 public void NotifyStatusUpdated(TaskId task, BTTaskStatus previousState)
 {
     for (var i = 0; i < this.listeners.Count; i++)
     {
         this.listeners[i].StatusUpdated(task, previousState);
     }
 }
Exemple #2
0
        /// <summary>
        /// This method contains the update logic of this task. The implementation delegates the <see cref="Execute"/> method
        /// </summary>
        public override void Run()
        {
            BTTaskStatus status = this.Execute();

            switch (status)
            {
            case BTTaskStatus.Succeeded:
            {
                this.Success();
                break;
            }

            case BTTaskStatus.Failed:
            {
                this.Fail();
                break;
            }

            case BTTaskStatus.Running:
            {
                this.Running();
                break;
            }

            default:
            {
                throw new IllegalStateException($"Invalid status '{status}' returned by the execute method");
            }
            }
        }
Exemple #3
0
        /// <summary>
        /// Terminates this task and all its running children. This method MUST be called only if this task is running
        /// </summary>
        public virtual void Cancel()
        {
            this.CancelRunningChildren(0);
            BTTaskStatus previous = this.Status;

            this.Status = BTTaskStatus.Canceled;
            if (this.Stream.HasListeners)
            {
                this.Stream.NotifyStatusUpdated(this.Id, previous);
            }

            this.End();
        }
Exemple #4
0
        /// <summary>
        /// This method will be called in <see cref="Run"/> to inform control that this task needs to run again
        /// </summary>
        public virtual void Running()
        {
            BTTaskStatus previous = this.Status;

            this.Status = BTTaskStatus.Running;
            if (this.Stream.HasListeners)
            {
                this.Stream.NotifyStatusUpdated(this.Id, previous);
            }

            if (this.Control == TaskId.Invalid)
            {
                return;
            }

            Task <T> control = this.Stream.Get(this.Control);

            control.ChildRunning(this.Id, this.Id);
        }
Exemple #5
0
        /// <summary>
        /// This method will be called in <see cref="Run"/> to inform control that this task has finished running with a failure result
        /// </summary>
        public virtual void Fail()
        {
            BTTaskStatus previous = this.Status;

            this.Status = BTTaskStatus.Failed;
            if (this.Stream.HasListeners)
            {
                this.Stream.NotifyStatusUpdated(this.Id, previous);
            }

            this.End();

            if (this.Control == TaskId.Invalid)
            {
                return;
            }

            Task <T> control = this.Stream.Get(this.Control);

            control.ChildFail(this.Id);
        }