コード例 #1
0
ファイル: GraphToRule.cs プロジェクト: lickey10/u_Behaviors
        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);
        }
コード例 #2
0
ファイル: RuleToGraph.cs プロジェクト: lickey10/u_Behaviors
        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);
        }
コード例 #3
0
ファイル: RuleToGraph.cs プロジェクト: lickey10/u_Behaviors
        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);
        }
コード例 #4
0
ファイル: RuleMaker.cs プロジェクト: lickey10/u_Behaviors
        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);
        }
コード例 #5
0
ファイル: RuleMaker.cs プロジェクト: lickey10/u_Behaviors
        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);
        }
コード例 #6
0
ファイル: Rule.cs プロジェクト: miyoku157/Cthulours
        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);
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: Rule.cs プロジェクト: miyoku157/Cthulours
        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);
        }
コード例 #8
0
ファイル: Rule.cs プロジェクト: miyoku157/Cthulours
        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();
                    }
                }
            }
        }
コード例 #9
0
ファイル: Rule.cs プロジェクト: miyoku157/Cthulours
        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);
        }
コード例 #10
0
			public ChangeStateEnumerator(ActionType par) 
			{
				parent = par;
				nIndex = -1;
			}
コード例 #11
0
			public CallScriptEnumerator(ActionType par) 
			{
				parent = par;
				nIndex = -1;
			}
コード例 #12
0
			public CertaintyEnumerator(ActionType par) 
			{
				parent = par;
				nIndex = -1;
			}
コード例 #13
0
		public void ReplaceActionAt(ActionType newValue, int index)
		{
			ReplaceDomElementAt("", "Action", index, newValue);
		}
コード例 #14
0
		public void InsertActionAt(ActionType newValue, int index)
		{
			InsertDomElementAt("", "Action", index, newValue);
		}
コード例 #15
0
		public void AddAction(ActionType newValue)
		{
			AppendDomElement("", "Action", newValue);
		}
コード例 #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;
        }
コード例 #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;
		}