Esempio n. 1
0
        public RuleType Convert(string name, NodeBase rootCondition, List <NodeBase> actionList)
        {
            RuleType rule = new RuleType();

            rule.AddName(new Altova.Types.SchemaString(name));

            //this first node is the condition. Called traverse twice to create the two expressions
            LogicalExpression expression = CreateLogical(rootCondition);

            rule.AddCondition(expression);

            foreach (NodeBase node in actionList)
            {
                if ((node.m_NodeType == NodeType.SETVARIABLE) || (node.m_NodeType == NodeType.CALLSCRIPT))
                {
                    XMLRules.ActionType action = MakeAction(node);
                    if (action != null)
                    {
                        rule.AddAction(action);
                    }
                    else
                    {
                        Debug.LogError("Error saving an action node");
                    }
                }
            }

            rule.AddPriority(new Altova.Types.SchemaLong(100L));

            return(rule);
        }
Esempio n. 2
0
        List <NodeBase> ConvertAction(Rule rule)
        {
            int             actionCount = rule.m_Rule.GetActionCount();
            List <NodeBase> nodeList    = new List <NodeBase>();
            List <NodeBase> rootNodes   = new List <NodeBase>();

            for (int i = 0; i < actionCount; i++)
            {
                XMLRules.ActionType xmlAction = rule.m_Rule.GetActionAt(i);
                NodeBase            action    = CreateActionNode(xmlAction);
                rootNodes.Add(action);
                BuildNodeList(action, ref nodeList);
            }

            int totalLeafNodes = 0;

            foreach (NodeBase node in rootNodes)
            {
                totalLeafNodes += CountLeafNodes(node);
            }

            float startx = (totalLeafNodes / 2) * 200;

            foreach (NodeBase node in rootNodes)
            {
                int leafNodes = CountLeafNodes(node);
                node.m_Window.y = 100;
                LayoutTree(node, startx - (leafNodes / 2) * 100, 100);
                startx += (leafNodes + 1) * 100;
            }

            return(nodeList);
        }
Esempio n. 3
0
        NodeBase CreateActionNode(XMLRules.ActionType action)
        {
            NodeBase result = null;

            if (action.HasChangeState())
            {
                NodeBase rhsNode = CreateArithmeticNode(action.GetChangeState().GetExpression());

                result = new SetNode(m_Container);
                ((SetNode)result).m_VariableName = action.GetChangeState().GetVariable().GetName().Value;
                result.AddChild(rhsNode);
            }
            else if (action.HasCallScript())
            {
                result = new CallNode(m_Container);

                string scriptName = action.GetCallScript().GetScriptName().Value;

                List <ScriptDescriptor> actionList = ScriptManager.GetScriptsByType(typeof(BaseAction));

                foreach (ScriptDescriptor script in actionList)
                {
                    if (scriptName == script.m_Type.ToString())
                    {
                        BaseScript newScript = null;
                        BaseScript.Load(action.GetCallScript(), m_Container.m_Editor.m_TargetObject, out newScript);

                        ((CallNode)result).m_Script = (BaseAction)newScript;
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
        public XMLRules.ActionType MakeCallScriptAction(CallNode callNode)
        {
            XMLRules.ActionType action = new XMLRules.ActionType();

            ScriptReference scriptReference;

            BaseScript.Save(callNode.m_Script, out scriptReference);

            action.AddCallScript(scriptReference);

            return(action);
        }
Esempio n. 5
0
        public XMLRules.ActionType MakeStateChangeAction(string name, AiRuleEngine.VariableType type, ArithmeticExpression value)
        {
            XMLRules.ActionType  action     = new XMLRules.ActionType();
            AssignmentExpression assignment = new AssignmentExpression();

            assignment.AddVariable(MakeVariable(name, type).GetVariable());
            assignment.AddExpression(value);

            action.AddCertainty(new Altova.Types.SchemaDecimal(100));
            action.AddChangeState(assignment);

            return(action);
        }
Esempio n. 6
0
        void FindScriptReferences()
        {
            if (m_Rule.HasAction())
            {
                for (int i = 0; i < m_Rule.GetActionCount(); i++)
                {
                    XMLRules.ActionType action = m_Rule.GetActionAt(i);

                    if (action.HasCallScript())
                    {
                        BaseScript actionScript;

                        if (BaseScript.Load(action.GetCallScript(), m_Context.gameObject, out actionScript))
                        {
                            m_ScriptReferences.Add((BaseAction)actionScript);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public bool Validate()
        {
            bool validCondition = true;
            bool validAction    = true;

            if (m_Rule.HasCondition())
            {
                ValidateExpression(m_Rule.GetCondition(), out validCondition);
            }

            for (int i = 0; i < m_Rule.GetActionCount(); i++)
            {
                XMLRules.ActionType action = m_Rule.GetActionAt(i);
                if (action.HasChangeState())
                {
                    ValidateAssignmentExpression(action.GetChangeState(), out validAction);
                }
            }

            return(validCondition && validAction);
        }
Esempio n. 8
0
        public void Execute()
        {
            m_HasFired = true;

            for (int i = 0; i < m_Rule.GetActionCount(); i++)
            {
                XMLRules.ActionType action = m_Rule.GetActionAt(i);

                if (action.HasChangeState())
                {
                    EvaluateAssignmentExpression(action.GetChangeState());
                }
                else
                {
                    foreach (BaseAction script in m_ScriptReferences)
                    {
                        script.Execute();
                    }
                }
            }
        }
Esempio n. 9
0
        string GetActionString()
        {
            string retVal = "";

            for (int i = 0; i < m_Rule.GetActionCount(); i++)
            {
                XMLRules.ActionType action = m_Rule.GetActionAt(i);

                if (action.HasChangeState())
                {
                    retVal += GetAssignmentExpressionString(action.GetChangeState());
                    retVal += "\n";
                }
                else if (action.HasCallScript())
                {
                    retVal += "Call script: " + action.GetCallScript().GetScriptName();
                    retVal += "\n";
                }
            }

            return(retVal);
        }
Esempio n. 10
0
			public ChangeStateEnumerator(ActionType par) 
			{
				parent = par;
				nIndex = -1;
			}
Esempio n. 11
0
			public CallScriptEnumerator(ActionType par) 
			{
				parent = par;
				nIndex = -1;
			}
Esempio n. 12
0
			public CertaintyEnumerator(ActionType par) 
			{
				parent = par;
				nIndex = -1;
			}
Esempio n. 13
0
		public void ReplaceActionAt(ActionType newValue, int index)
		{
			ReplaceDomElementAt("", "Action", index, newValue);
		}
Esempio n. 14
0
		public void InsertActionAt(ActionType newValue, int index)
		{
			InsertDomElementAt("", "Action", index, newValue);
		}
Esempio n. 15
0
		public void AddAction(ActionType newValue)
		{
			AppendDomElement("", "Action", newValue);
		}
Esempio n. 16
0
		public XMLRules.ActionType MakeCallScriptAction(CallNode callNode)
        {
			XMLRules.ActionType action = new XMLRules.ActionType();
            
            ScriptReference scriptReference;

            BaseScript.Save(callNode.m_Script, out scriptReference);
            
            action.AddCallScript(scriptReference);

            return action;
        }
Esempio n. 17
0
		public XMLRules.ActionType MakeStateChangeAction(string name, AiRuleEngine.VariableType type, ArithmeticExpression value)
		{
			XMLRules.ActionType action = new XMLRules.ActionType();
			AssignmentExpression assignment = new AssignmentExpression();
			assignment.AddVariable(MakeVariable(name, type).GetVariable());
			assignment.AddExpression(value);
			
			action.AddCertainty(new Altova.Types.SchemaDecimal(100));
			action.AddChangeState(assignment);
			
			return action;
		}