Example #1
0
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="myNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        public override void ParseTasks(Bullet bullet)
        {
            //set the number of times to repeat this action
            var actionNode = Node as ActionNode;

            Debug.Assert(null != actionNode);
            RepeatNumMax = actionNode.RepeatNum(this, bullet);

            //is this an actionref task?
            if (ENodeName.actionRef == Node.Name)
            {
                //add a sub task under this one for the referenced action
                var myActionRefNode = Node as ActionRefNode;

                //create the action task
                var actionTask = new ActionTask(myActionRefNode.ReferencedActionNode, this);

                //parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(actionTask);
            }

            //call the base class
            base.ParseTasks(bullet);
        }
Example #2
0
        /// <summary>
        /// Removes the child task at the specified position in the child task list.
        /// </summary>
        /// <param name="index">Index of child <see cref="ITask"/> instance to remove.</param>
        public virtual void RemoveChild(int index)
        {
            if (index >= ChildTasks.Count)
            {
                return;
            }

            ChildTasks.RemoveAt(index);
        }
Example #3
0
        /// <summary>
        /// Adds the provided task as a child task.
        /// </summary>
        /// <param name="childTask"><see cref="ITask"/> to add as a child task.</param>
        public virtual void AddChild(ITask childTask)
        {
            if (childTask == null)
            {
                throw new ArgumentNullException("childTask");
            }

            ChildTasks.Add(childTask);
        }
        /// <summary>
        /// Launches the edit task window.
        /// </summary>
        public void EditTask()
        {
            TaskView      window         = new TaskView();
            TaskViewModel selectedTaskVM = ChildTasks.FirstOrDefault(t => t.IsSelected == true);

            using (var viewModel = new TaskViewModel(_taskData.GetTaskByTaskId(selectedTaskVM.TaskId), _taskData))
            {
                this.ShowWorkspaceAsDialog(window, viewModel);
            }
        }
        /// <summary>
        /// Launches the delete task window.
        /// </summary>
        public void DeleteTask()
        {
            TaskViewModel selectedTaskVM = ChildTasks.FirstOrDefault(t => t.IsSelected == true);

            if (selectedTaskVM != null && WPFMessageBox.Show(Properties.Resources.Delete_Confirm, Properties.Resources.Tasks_Delete_Confirm, WPFMessageBoxButtons.YesNo, WPFMessageBoxImage.Question) == WPFMessageBoxResult.Yes)
            {
                _taskData.DeleteTask(_taskData.GetTaskByTaskId(selectedTaskVM.TaskId));
                selectedTaskVM.Dispose();
            }
        }
        public void GetChildren(Tasks parentTask, List <Tasks> tasksFromRepo)
        {
            var q = tasksFromRepo.Where(w => w.ParentTaskGUID == parentTask.TaskGUID);

            foreach (var task in q)
            {
                ChildTasks.Add(task);
                GetChildren(task, tasksFromRepo);
            }
        }
Example #7
0
        /// <summary>
        /// Parse a specified node and bullet into this task.
        /// </summary>
        /// <param name="bullet">The bullet this action is controlling.</param>
        public override void ParseTasks(Bullet bullet)
        {
            // Set the number of times to repeat this action
            var actionNode = Node as ActionNode;

            Debug.Assert(null != actionNode);

            RepeatNumMax = actionNode.RepeatNum(this, bullet);

            // Check that there is a wait node if the RepeatNumMax is 0 (= infinite)
            if (RepeatNumMax == 0)
            {
                var waitNode = actionNode.ChildNodes.Find(
                    node => node.Name == NodeName.wait && node.GetValue(this) > 0f
                    ) as WaitNode;

                if (waitNode == null)
                {
                    if (actionNode.Name == NodeName.actionRef)
                    {
                        Console.WriteLine("Warning: A repeat node is used with an actionRef child, " +
                                          "please make sure that this actionRef contains a wait node " +
                                          "or it will block the program.");
                    }
                    else
                    {
                        throw new InvalidDataException("You have an infinite loop with no wait node, " +
                                                       "this is bad because it will block the program.");
                    }
                }
            }

            // Is this an actionRef task?
            if (Node.Name == NodeName.actionRef)
            {
                // Add a sub task under this one for the referenced action
                var actionRefNode = Node as ActionRefNode;

                // Create the action task
                if (actionRefNode != null)
                {
                    var actionTask = new ActionTask(actionRefNode.ReferencedActionNode, this);

                    // Parse the children of the action node into the task
                    actionTask.ParseTasks(bullet);

                    // Store the task
                    ChildTasks.Add(actionTask);
                }
            }

            // Call the base class
            base.ParseTasks(bullet);
        }
Example #8
0
        public static void SimpleTasks()
        {
            IRun tb = new TasksBasics();

            tb.Run();

            IRun ct = new ChildTasks();

            ct.Run();

            IRun tfs = new TaskFactorySample();

            tfs.Run();
        }
Example #9
0
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="childNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        protected override void ParseChildNode(BulletMLNode childNode, Bullet bullet)
        {
            Debug.Assert(null != childNode);
            Debug.Assert(null != bullet);

            switch (childNode.Name)
            {
            case ENodeName.bulletRef:
            {
                //Create a task for the bullet ref
                if (childNode is BulletRefNode refNode)
                {
                    BulletRefTask = new BulletMLTask(refNode.ReferencedBulletNode, this);
                }

                //populate the params of the bullet ref
                foreach (var node in childNode.ChildNodes)
                {
                    BulletRefTask.ParamList.Add(node.GetValue(this, bullet));
                }

                BulletRefTask.ParseTasks(bullet);
                ChildTasks.Add(BulletRefTask);
            }
            break;

            case ENodeName.bullet:
            {
                //Create a task for the bullet ref
                BulletRefTask = new BulletMLTask(childNode, this);
                BulletRefTask.ParseTasks(bullet);
                ChildTasks.Add(BulletRefTask);
            }
            break;

            default:
            {
                //run the node through the base class if we don't want it
                base.ParseChildNode(childNode, bullet);
            }
            break;
            }
        }
Example #10
0
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="myNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        public override void ParseChildNode(BulletMLNode childNode, Bullet bullet)
        {
            System.Diagnostics.Debug.Assert(null != childNode);
            System.Diagnostics.Debug.Assert(null != bullet);

            switch (childNode.Name)
            {
            case ENodeName.bulletRef:
            {
                //Create a task for the bullet ref
                BulletRefNode refNode = childNode as BulletRefNode;
                BulletRefTask = new BulletMLTask(refNode.ReferencedBulletNode, this);

                //populate the params of the bullet ref
                for (int i = 0; i < childNode.ChildNodes.Count; i++)
                {
                    BulletRefTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this));
                }

                BulletRefTask.ParseTasks(bullet);
                ChildTasks.Add(BulletRefTask);
            }
            break;

            case ENodeName.bullet:
            {
                //Create a task for the bullet ref
                BulletRefTask = new BulletMLTask(childNode, this);
                BulletRefTask.ParseTasks(bullet);
                ChildTasks.Add(BulletRefTask);
            }
            break;

            default:
            {
                //run the node through the base class if we don't want it
                base.ParseChildNode(childNode, bullet);
            }
            break;
            }
        }
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="myNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        public override void ParseTasks(Bullet bullet)
        {
            //is this an actionref task?
            if (ENodeName.actionRef == Node.Name)
            {
                //add a sub task under this one for the referenced action
                ActionRefNode myActionRefNode = Node as ActionRefNode;

                //create the action task
                ActionTask actionTask = new ActionTask(myActionRefNode.ReferencedActionNode, this);

                //parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(actionTask);
            }

            //call the base class
            base.ParseTasks(bullet);
        }
Example #12
0
        /// <summary>
        /// Retrieve the bullet or bulletRef nodes from a fire task.
        /// </summary>
        /// <param name="task">Task to check if has a child bullet or bulletRef node.</param>
        /// <param name="bullet">Associated bullet.</param>
        private void GetBulletNode(BulletMLTask task, Bullet bullet)
        {
            if (task == null)
            {
                return;
            }

            // Check if there is a bullet or a bulletRef node
            var bulletNode    = task.Node.GetChild(NodeName.bullet) as BulletNode;
            var bulletRefNode = task.Node.GetChild(NodeName.bulletRef) as BulletRefNode;

            if (bulletNode != null)
            {
                // Create a task for the bullet ref
                BulletTask = new BulletMLTask(bulletNode, this);
                BulletTask.ParseTasks(bullet);
                ChildTasks.Add(BulletTask);
            }
            else if (bulletRefNode != null)
            {
                // Create a task for the bullet ref
                BulletTask = new BulletMLTask(bulletRefNode.ReferencedBulletNode, this);

                // Populate the params of the bullet ref
                foreach (var node in bulletRefNode.ChildNodes)
                {
                    BulletTask.Params.Add(node.GetValue(this));
                }

                BulletTask.ParseTasks(bullet);
                ChildTasks.Add(BulletTask);
            }
            else
            {
                throw new InvalidDataException("A <fire> node must contain a <bullet> or a <bulletRef> node.");
            }
        }
 /// <summary>
 /// Selects a single child task randomly and executes it, returning the
 /// result of that child task.
 /// </summary>
 /// <returns>The result code of the randomly selected child task that
 /// was executed.</returns>
 public override TaskResultCode Execute()
 {
     return(ChildTasks.RandomElement().Execute());
 }
Example #14
0
        /// <summary>
        /// Shuffles the order of child tasks, then executes each child task
        /// in order until one succeeds or all fail.
        /// </summary>
        /// <returns>Success on the first successful execution of a child task, or
        /// failure if all fail.</returns>
        public override TaskResultCode Execute()
        {
            ChildTasks.Shuffle();

            return(base.Execute());
        }
Example #15
0
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="childNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        protected virtual void ParseChildNode(BulletMLNode childNode, Bullet bullet)
        {
            Debug.Assert(null != childNode);
            Debug.Assert(null != bullet);

            //construct the correct type of node
            switch (childNode.Name)
            {
            case ENodeName.repeat:
            {
                //convert the node to an repeatnode
                var myRepeatNode = childNode as RepeatNode;

                //create a placeholder bulletmltask for the repeat node
                var repeatTask = new RepeatTask(myRepeatNode, this);

                //parse the child nodes into the repeat task
                repeatTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(repeatTask);
            }
            break;

            case ENodeName.action:
            {
                //convert the node to an ActionNode
                var myActionNode = childNode as ActionNode;

                //create the action task
                var actionTask = new ActionTask(myActionNode, this);

                //parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(actionTask);
            }
            break;

            case ENodeName.actionRef:
            {
                //convert the node to an ActionNode
                var myActionNode = childNode as ActionRefNode;

                //create the action task
                var actionTask = new ActionTask(myActionNode, this);

                //add the params to the action task
                for (var i = 0; i < childNode.ChildNodes.Count; i++)
                {
                    actionTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet));
                }

                //parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(actionTask);
            }
            break;

            case ENodeName.changeSpeed:
            {
                ChildTasks.Add(new ChangeSpeedTask(childNode as ChangeSpeedNode, this));
            }
            break;

            case ENodeName.changeDirection:
            {
                ChildTasks.Add(new ChangeDirectionTask(childNode as ChangeDirectionNode, this));
            }
            break;

            case ENodeName.fire:
            {
                //convert the node to a fire node
                var myFireNode = childNode as FireNode;

                //create the fire task
                var fireTask = new FireTask(myFireNode, this);

                //parse the children of the fire node into the task
                fireTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(fireTask);
            }
            break;

            case ENodeName.fireRef:
            {
                //convert the node to a fireref node

                //create the fire task
                if (childNode is FireRefNode myFireNode)
                {
                    var fireTask = new FireTask(myFireNode.ReferencedFireNode, this);

                    //add the params to the fire task
                    for (var i = 0; i < childNode.ChildNodes.Count; i++)
                    {
                        fireTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet));
                    }

                    //parse the children of the action node into the task
                    fireTask.ParseTasks(bullet);

                    //store the task
                    ChildTasks.Add(fireTask);
                }
            }
            break;

            case ENodeName.wait:
            {
                ChildTasks.Add(new WaitTask(childNode as WaitNode, this));
            }
            break;

            case ENodeName.vanish:
            {
                ChildTasks.Add(new VanishTask(childNode as VanishNode, this));
            }
            break;

            case ENodeName.accel:
            {
                ChildTasks.Add(new AccelTask(childNode as AccelNode, this));
            }
            break;
            }
        }
 bool CanDeleteTask()
 {
     return(ChildTasks.Count(t => t.IsSelected == true) == 1);
 }
Example #17
0
 public override void RemoveAllReferences()
 {
     CheckPoints.Clear();
     ChildTasks.Clear();
     Resources.Clear();
 }
Example #18
0
        /// <summary>
        /// Parse a specified node and bullet into this task.
        /// </summary>
        /// <param name="childNode">The node for this task.</param>
        /// <param name="bullet">The bullet this task is controlling.</param>
        private void ParseChildNode(BulletMLNode childNode, Bullet bullet)
        {
            Debug.Assert(null != childNode);
            Debug.Assert(null != bullet);

            // Construct the correct type of node
            switch (childNode.Name)
            {
            case NodeName.repeat:
            {
                // Convert the node to an repeatnode
                var repeatNode = childNode as RepeatNode;

                // Create a placeholder BulletMLTask for the repeat node
                var repeatTask = new RepeatTask(repeatNode, this);

                // Parse the child nodes into the repeat task
                repeatTask.ParseTasks(bullet);

                // Store the task
                ChildTasks.Add(repeatTask);
            }
            break;

            case NodeName.action:
            {
                // Convert the node to an ActionNode
                var actionNode = childNode as ActionNode;

                // Create the action task
                var actionTask = new ActionTask(actionNode, this);

                // Parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                // Store the task
                ChildTasks.Add(actionTask);
            }
            break;

            case NodeName.actionRef:
            {
                // Convert the node to an ActionNode
                var actionRefNode = childNode as ActionRefNode;

                // Create the action task
                var actionTask = new ActionTask(actionRefNode, this);

                // Add the params to the action task
                for (int i = 0; i < childNode.ChildNodes.Count; i++)
                {
                    actionTask.Params.Add(childNode.ChildNodes[i].GetValue(this));
                }

                // Parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                // Store the task
                ChildTasks.Add(actionTask);
            }
            break;

            case NodeName.fire:
            {
                // Convert the node to a fire node
                var fireNode = childNode as FireNode;

                // Create the fire task
                var fireTask = new FireTask(fireNode, this);

                // Parse the children of the fire node into the task
                fireTask.ParseTasks(bullet);
                // Store the task
                ChildTasks.Add(fireTask);
            }
            break;

            case NodeName.fireRef:
            {
                // Convert the node to a fireRef node
                var fireRefNode = childNode as FireRefNode;

                // Create the fire task
                if (fireRefNode != null)
                {
                    var fireTask = new FireTask(fireRefNode.ReferencedFireNode, this);

                    // Add the params to the fire task
                    for (int i = 0; i < childNode.ChildNodes.Count; i++)
                    {
                        fireTask.Params.Add(childNode.ChildNodes[i].GetValue(this));
                    }

                    // Parse the children of the action node into the task
                    fireTask.ParseTasks(bullet);

                    // Store the task
                    ChildTasks.Add(fireTask);
                }
            }
            break;

            case NodeName.changeSpeed:
            {
                ChildTasks.Add(new ChangeSpeedTask(childNode as ChangeSpeedNode, this));
            }
            break;

            case NodeName.changeDirection:
            {
                ChildTasks.Add(new ChangeDirectionTask(childNode as ChangeDirectionNode, this));
            }
            break;

            case NodeName.wait:
            {
                ChildTasks.Add(new WaitTask(childNode as WaitNode, this));
            }
            break;

            case NodeName.vanish:
            {
                ChildTasks.Add(new VanishTask(childNode as VanishNode, this));
            }
            break;

            case NodeName.accel:
            {
                ChildTasks.Add(new AccelTask(childNode as AccelNode, this));
            }
            break;

            case NodeName.color:
            {
                ChildTasks.Add(new ColorTask(childNode as ColorNode, this));
            }
            break;

            case NodeName.changeColor:
            {
                ChildTasks.Add(new ChangeColorTask(childNode as ChangeColorNode, this));
            }
            break;

            case NodeName.changeScale:
            {
                ChildTasks.Add(new ChangeScaleTask(childNode as ChangeScaleNode, this));
            }
            break;
            }
        }
Example #19
0
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="myNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        public virtual void Parse(BulletMLNode myNode, Bullet bullet)
        {
            Debug.Assert(null != myNode);
            Debug.Assert(null != bullet);

            foreach (BulletMLNode childNode in myNode.ChildNodes)
            {
                //construct the correct type of node
                switch (childNode.Name)
                {
                case ENodeName.repeat:
                {
                    Parse(childNode, bullet);
                }
                break;

                case ENodeName.action:
                {
                    int repeatNum = 1;

                    //find how many times to repeat this action
                    BulletMLNode RepeatNode = childNode.FindParentNode(ENodeName.repeat);
                    if (null != RepeatNode)
                    {
                        repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this);
                    }

                    BulletMLAction task = new BulletMLAction(repeatNum, myNode, this);
                    ChildTasks.Add(task);
                    task.Parse(childNode, bullet);
                }
                break;

                case ENodeName.actionRef:
                {
                    //find the referenced node
                    BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.action);

                    //find how many times to repeat the referenced action
                    int          repeatNum  = 1;
                    BulletMLNode RepeatNode = myNode.FindParentNode(ENodeName.repeat);
                    if (null != RepeatNode)
                    {
                        repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this);
                    }

                    BulletMLAction task = new BulletMLAction(repeatNum, refNode, this);
                    ChildTasks.Add(task);

                    for (int i = 0; i < childNode.ChildNodes.Count; i++)
                    {
                        task.ParamList.Add(childNode.ChildNodes[i].GetValue(this));
                    }

                    task.Parse(refNode, bullet);
                }
                break;

                case ENodeName.changeSpeed:
                {
                    ChildTasks.Add(new BulletMLChangeSpeed(childNode, this));
                }
                break;

                case ENodeName.changeDirection:
                {
                    ChildTasks.Add(new BulletMLChangeDirection(childNode, this));
                }
                break;

                case ENodeName.fire:
                {
                    ChildTasks.Add(new BulletMLFire(childNode, this));
                }
                break;

                case ENodeName.fireRef:
                {
                    //find the node that was referenced
                    BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.fire);
                    BulletMLFire fire    = new BulletMLFire(refNode, this);
                    ChildTasks.Add(fire);

                    for (int i = 0; i < childNode.ChildNodes.Count; i++)
                    {
                        fire.ParamList.Add(childNode.ChildNodes[i].GetValue(this));
                    }
                }
                break;

                case ENodeName.wait:
                {
                    ChildTasks.Add(new BulletMLWait(childNode, this));
                }
                break;

                case ENodeName.speed:
                {
                    //speed nodes are special, just pull the value out and set up the bullet
                    bullet.GetFireData().speedInit = true;
                    bullet.Velocity = childNode.GetValue(this);
                }
                break;

                case ENodeName.direction:
                {
                    ChildTasks.Add(new BulletMLSetDirection(childNode, this));
                }
                break;

                case ENodeName.vanish:
                {
                    ChildTasks.Add(new BulletMLVanish(childNode, this));
                }
                break;

                case ENodeName.accel:
                {
                    ChildTasks.Add(new BulletMLAccel(childNode, this));
                }
                break;
                }
            }

            //After all the nodes are read in, initialize the node
            Init();
        }
Example #20
0
 /// <summary>
 /// Removes all child tasks.
 /// </summary>
 public virtual void ClearChildren()
 {
     ChildTasks.Clear();
 }