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); }
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); }
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); }
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); }
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); }
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); } } } } }
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); }
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(); } } } }
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); }
public ChangeStateEnumerator(ActionType par) { parent = par; nIndex = -1; }
public CallScriptEnumerator(ActionType par) { parent = par; nIndex = -1; }
public CertaintyEnumerator(ActionType par) { parent = par; nIndex = -1; }
public void ReplaceActionAt(ActionType newValue, int index) { ReplaceDomElementAt("", "Action", index, newValue); }
public void InsertActionAt(ActionType newValue, int index) { InsertDomElementAt("", "Action", index, newValue); }
public void AddAction(ActionType newValue) { AppendDomElement("", "Action", newValue); }
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; }
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; }