示例#1
0
        protected ProcessResult ProcessChildren(TriggerObject trigObject)
        {
            ProcessResult lastResult = ProcessResult.None;
            PauseNode     newPause   = null;

            if (trigObject.PausedNodeChain != null)
            {
                if (trigObject.PausedNodeChain.Peek() != this)
                {
                    return(ProcessResult.None);
                }

                trigObject.PausedNodeChain.Dequeue();
            }

            trigObject.CurrentNodeExecutionChain.Add(this);

            foreach (UberNode child in Children)
            {
                if (trigObject.PausedNodeChain != null)
                {
                    if (trigObject.PausedNodeChain.Peek() != child)
                    {
                        continue;
                    }
                    if (!(child is ConditionalNode)) // Conditional node handles it's own processChildren
                    {
                        trigObject.PausedNodeChain.Dequeue();
                    }

                    if (trigObject.PausedNodeChain.Count == 0)
                    {
                        // if we got here, we found the node that we need to start execution on
                        trigObject.PausedNodeChain = null;
                    }
                }

                if (newPause != null) // just passed a pause node, time to stop execution
                {
                    trigObject.CurrentNodeExecutionChain.Add(child);
                    trigObject.PausedNodeChain = new Queue <UberNode>();
                    foreach (UberNode node in trigObject.CurrentNodeExecutionChain)
                    {
                        trigObject.PausedNodeChain.Enqueue(node);
                    }
                    trigObject.CurrentNodeExecutionChain = new List <UberNode>();
                    PausedUberScript paused = new PausedUberScript(trigObject, (trigObject != null && trigObject.TrigName != TriggerName.NoTrigger), newPause.PauseMS);
                    return(ProcessResult.Return);
                }
                if (child is PauseNode)
                {
                    newPause = child as PauseNode;
                    continue;
                }
                if (child is BreakNode)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return(ProcessResult.Break);
                }
                if (child is ContinueNode)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return(ProcessResult.Continue);
                }
                if (trigObject.Script.ProceedToNextStage)
                {
                    // only execute the proper sequence node
                    if (child is SequenceNode)
                    {
                        SequenceNode sequenceNode = child as SequenceNode;
                        if (trigObject.Script.Stage < sequenceNode.Stage)
                        {
                            // found the next stage
                            trigObject.Script.Stage = sequenceNode.Stage;
                            trigObject.Script.ProceedToNextStage = false;
                            lastResult = child.Process(lastResult, trigObject);
                            trigObject.CurrentNodeExecutionChain.Remove(this);
                            return(lastResult);
                        }
                    }
                    continue;
                }
                else
                {
                    if (child is TriggerNode)
                    {
                        continue;                                                            // triggernodes execute only in response to events
                    }
                    else if (child is ConditionalNode && trigObject.PausedNodeChain == null) // if PausedNodeChain not null and it reached here, then it is the right node, don't depend on past conditionals--execute it
                    {
                        ConditionalNode conditionalNode = child as ConditionalNode;
                        if (conditionalNode.IfType == ConditionalNode.ConditionalType.Elif || conditionalNode.IfType == ConditionalNode.ConditionalType.Else)
                        {
                            if (lastResult == ProcessResult.FailedIf)
                            {
                                lastResult = child.Process(lastResult, trigObject);
                                if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride)
                                {
                                    trigObject.CurrentNodeExecutionChain.Remove(this);
                                    return(lastResult);
                                }
                            }
                            continue;
                        }
                    }
                }

                lastResult = child.Process(lastResult, trigObject);
                if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return(lastResult);
                }
            }
            if (trigObject.Script.ProceedToNextStage)
            {
                lastResult = ProcessResult.EndOfSequence;
                trigObject.Script.ProceedToNextStage = false;
            }
            trigObject.CurrentNodeExecutionChain.Remove(this);
            if (lastResult == ProcessResult.FailedIf || lastResult == ProcessResult.SucceedIf && !(this is ConditionalNode))
            {
                lastResult = ProcessResult.None; // don't percolate the result up
            }
            return(lastResult);
        }
示例#2
0
        protected ProcessResult ProcessChildren(TriggerObject trigObject)
        {
            ProcessResult lastResult = ProcessResult.None;
            PauseNode newPause = null;
            
            if (trigObject.PausedNodeChain != null)
            {
                 if (trigObject.PausedNodeChain.Peek() != this)
                     return ProcessResult.None;

                 trigObject.PausedNodeChain.Dequeue();
            }

            trigObject.CurrentNodeExecutionChain.Add(this);

            foreach (UberNode child in Children)
            {
                if (trigObject.PausedNodeChain != null)
                {
                    if (trigObject.PausedNodeChain.Peek() != child)
                        continue;
                    if (!(child is ConditionalNode)) // Conditional node handles it's own processChildren
                        trigObject.PausedNodeChain.Dequeue();
                    
                    if (trigObject.PausedNodeChain.Count == 0)
                    {
                        // if we got here, we found the node that we need to start execution on
                        trigObject.PausedNodeChain = null;
                    }
                }

                if (newPause != null) // just passed a pause node, time to stop execution
                {
                    trigObject.CurrentNodeExecutionChain.Add(child);
                    trigObject.PausedNodeChain = new Queue<UberNode>();
                    foreach (UberNode node in trigObject.CurrentNodeExecutionChain)
                    {
                        trigObject.PausedNodeChain.Enqueue(node);
                    }
                    trigObject.CurrentNodeExecutionChain = new List<UberNode>();
                    PausedUberScript paused = new PausedUberScript(trigObject, (trigObject != null && trigObject.TrigName != TriggerName.NoTrigger), newPause.PauseMS);
                    return ProcessResult.Return;
                }
                if (child is PauseNode)
                {
                    newPause = child as PauseNode;
                    continue;
                }
                if (child is BreakNode)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return ProcessResult.Break;
                }
                if (child is ContinueNode)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return ProcessResult.Continue;
                }
                if (trigObject.Script.ProceedToNextStage)
                {
                    // only execute the proper sequence node
                    if (child is SequenceNode)
                    {
                        SequenceNode sequenceNode = child as SequenceNode;
                        if (trigObject.Script.Stage < sequenceNode.Stage)
                        {
                            // found the next stage
                            trigObject.Script.Stage = sequenceNode.Stage;
                            trigObject.Script.ProceedToNextStage = false;
                            lastResult = child.Process(lastResult, trigObject);
                            trigObject.CurrentNodeExecutionChain.Remove(this);
                            return lastResult;
                        }
                    }
                    continue;
                }
                else
                {
                    if (child is TriggerNode) continue; // triggernodes execute only in response to events
                    else if (child is ConditionalNode && trigObject.PausedNodeChain == null) // if PausedNodeChain not null and it reached here, then it is the right node, don't depend on past conditionals--execute it
                    {
                        ConditionalNode conditionalNode = child as ConditionalNode;
                        if (conditionalNode.IfType == ConditionalNode.ConditionalType.Elif || conditionalNode.IfType == ConditionalNode.ConditionalType.Else)
                        {
                            if (lastResult == ProcessResult.FailedIf)
                            {
                                lastResult = child.Process(lastResult, trigObject);
                                if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride)
                                {
                                    trigObject.CurrentNodeExecutionChain.Remove(this);
                                    return lastResult;
                                }
                            }
                            continue;
                        }
                    }
                }
                
                lastResult = child.Process(lastResult, trigObject);
                if (lastResult == ProcessResult.Return || lastResult == ProcessResult.ReturnOverride || lastResult == ProcessResult.Break || lastResult == ProcessResult.Continue)
                {
                    trigObject.CurrentNodeExecutionChain.Remove(this);
                    return lastResult;
                }
            }
            if (trigObject.Script.ProceedToNextStage)
            {
                lastResult = ProcessResult.EndOfSequence;
                trigObject.Script.ProceedToNextStage = false;
            }
            trigObject.CurrentNodeExecutionChain.Remove(this);
            if (lastResult == ProcessResult.FailedIf || lastResult == ProcessResult.SucceedIf && !(this is ConditionalNode))
            {
                lastResult = ProcessResult.None; // don't percolate the result up
            }
            return lastResult;
        }