private static void Monster_Data(DesignerItem monster, int aiID) { var ipy = Python.CreateRuntime(); dynamic test = ipy.UseFile("Code\\monster_data.py"); IronPython.Runtime.PythonDictionary data = test.data; IronPython.Runtime.PythonDictionary unit = null; IronPython.Runtime.PythonTuple tuple = null; List <int> aiIDList = new List <int>(); aiIDList.Add(aiID); int monsterID = -1; for (int i = 0; i < monster.outputValue.Count; ++i) { MyTextBox tempTextBox = monster.outputValue[i]; if (tempTextBox.Property.Equals("ID")) { try { monsterID = Convert.ToInt32(tempTextBox.propertyValue); } catch (Exception e) { var ex = new Exception("缺少怪物ID"); throw ex; } } } if (data.ContainsKey(monsterID)) { unit = data[monsterID] as IronPython.Runtime.PythonDictionary; if (unit["monsterAI"] != null) { tuple = unit["monsterAI"] as IronPython.Runtime.PythonTuple; for (int i = 0; i < tuple.Count; ++i) { int exitAIID = Convert.ToInt32(tuple[i]); if (!aiIDList.Contains(exitAIID)) { aiIDList.Add(exitAIID); } } } } else { unit = new IronPython.Runtime.PythonDictionary(); } unit["monsterAI"] = new IronPython.Runtime.PythonTuple(aiIDList); for (int i = 0; i < monster.outputValue.Count; ++i) { MyTextBox tempTextBox = monster.outputValue[i]; if (!tempTextBox.Property.Equals(tempTextBox.propertyValue) && tempTextBox.propertyValue != null && !tempTextBox.Property.Equals("ID")) { unit[tempTextBox.Property] = tempTextBox.propertyValue; } } data[monsterID] = unit; exportCode(data, "monster_data.py"); }
// 指定したマップのマスから、スクリーン座標を取得する public IronPython.Runtime.PythonTuple GetScreenPositionByMapPos(int map_x, int map_y, double offset_x, double offset_y, double offset_z) { //var p = new Point(0, 0); float dx = 0, dy = 0, dz = 0; GameMain.GetInstance().g3d_map.Get3DPos(map_x, map_y, ref dx, ref dy, ref dz); dx += (float)offset_x; dy += (float)offset_y; dz += (float)offset_z; var dv = DX.VGet(dx, dy, dz); var v = DX.ConvWorldPosToScreenPos(dv); //p.X = (int)v.x; //p.Y = (int)v.y; var res = new IronPython.Runtime.PythonTuple(new[] { (int)v.x, (int)v.y }); return(res); }
private void SelectDictionary(string type) { Regex regex0 = new Regex(@"^condition\d$"); Regex regex1 = new Regex(@"^condition\dArgs$"); Regex regex2 = new Regex(@"^condition\dTgt\d$"); Regex regex3 = new Regex(@"^action\d$"); Regex regex4 = new Regex(@"^action\dArgs$"); Regex regex5 = new Regex(@"^action\dTgt\d$"); Regex regex6 = new Regex(@"^tgtMethodName\d$"); Regex regex7 = new Regex(@"^tgtMethodArgs\d$"); if (regex0.IsMatch(type)) { addStringDictionary(type, 9, conditionDictionary); } else if (regex1.IsMatch(type)) { addListDictionary(type, 9, conditionParamDictionary); } else if (regex2.IsMatch(type)) { addLinkerDictionary(type, 9, 13, conditionTargetLinker); } else if (regex3.IsMatch(type)) { addStringDictionary(type, 6, actionDictionary); } else if (regex4.IsMatch(type)) { addListDictionary(type, 6, actionParamDictionary); } else if (regex5.IsMatch(type)) { addLinkerDictionary(type, 6, 10, actionTargetLinker); } else if (regex6.IsMatch(type)) { addStringDictionary(type, 13, targetDictionary); } else if (regex7.IsMatch(type)) { addListDictionary(type, 13, targetParamDictionary); } else if (type.Equals("conditionExp")) { int gap = 0; if (aiAction[type] is IronPython.Runtime.PythonTuple) { IronPython.Runtime.PythonTuple conditionExp = aiAction[type] as IronPython.Runtime.PythonTuple; for (int i = 0; i < conditionExp.Count; ++i) { if (conditionExp[i] is IronPython.Runtime.List) { Dictionary <int, string> tempList = new Dictionary <int, string>(); IronPython.Runtime.List conditionExpList = conditionExp[i] as IronPython.Runtime.List; for (int j = 0; j < conditionExpList.Count; ++j) { orExp[i + j] = Convert.ToString(conditionExpList[j]); gap++; } } else { gap = gap == 0 ? 0 : (gap - 1); andExp[i + gap] = Convert.ToString(conditionExp[i]); } } } else { string exp = Convert.ToString(aiAction[type]); andExp[0] = exp; } } }
public Dictionary <string, Dictionary <int, List <int> > > searchParse(string inputData, string searchType) { Dictionary <string, Dictionary <int, List <int> > > monster = null; var ipy = Python.CreateRuntime(); dynamic test = ipy.UseFile("Code\\monster_data.py"); IronPython.Runtime.PythonDictionary data = test.data; switch (searchType) { case "Monster_ID": List <int> aiDataID = new List <int>(); if (Regex.IsMatch(inputData, @"^\d+$")) { int key = int.Parse(inputData); if (data.ContainsKey(key)) { monsterParam["ID"] = key.ToString(); IronPython.Runtime.PythonDictionary aiDictionary = data[key] as IronPython.Runtime.PythonDictionary; if (aiDictionary.ContainsKey("name")) { string name = Convert.ToString(aiDictionary["name"]); monsterParam["name"] = name; } if (aiDictionary.ContainsKey("tag")) { string tag = Convert.ToString(aiDictionary["tag"]); monsterParam["tag"] = tag; } if (aiDictionary.ContainsKey("monsterAI")) { DrawComponent.monsterParam = monsterParam; IronPython.Runtime.PythonTuple monsterTuple = aiDictionary["monsterAI"] as IronPython.Runtime.PythonTuple; for (int i = 0; i < monsterTuple.Count; ++i) { int id = Convert.ToInt32(monsterTuple[i]); aiDataID.Add(id); } monster = searchAIByID(aiDataID); } else { MessageBox.Show("此怪物不包含AI"); } } else { MessageBox.Show("不包含此ID"); } } else { MessageBox.Show("输入的格式不正确"); } break; case "Monster_Name": break; case "Monster_Tag": break; } return(monster); }
public static void PythonStructure(int newID, List <DesignerItem> triggerList, List <DesignerItem> conditionList, List <DesignerItem> actionList, List <DesignerItem> targetList, Dictionary <int, string> andOrder, Dictionary <int, string> orOrder) { var ipy = Python.CreateRuntime(); dynamic test = ipy.UseFile("Code\\monster_ai_data.py"); IronPython.Runtime.PythonDictionary data = test.data; IronPython.Runtime.PythonDictionary unit = new IronPython.Runtime.PythonDictionary(); /////trigger///// IronPython.Runtime.List Trigger = new IronPython.Runtime.List(); Trigger.Add(triggerList[2].IDName); for (int i = 0; i < triggerList[2].outputValue.Count; ++i) { MyTextBox tempTextBox = triggerList[2].outputValue[i]; //if (tempTextBox.type == "Range" || tempTextBox.type == "Vec3") //{ // List<int> paramList = parseString(tempTextBox.propertyValue); // IronPython.Runtime.PythonTuple paramTuple = new IronPython.Runtime.PythonTuple(paramList); // Trigger.Add(paramTuple); //} //else { Trigger.Add(tempTextBox.propertyValue); } Trigger.Add(tempTextBox.propertyValue); } unit["trigger"] = Trigger; /////trigger///// ////AIParam//// MyTextBox idTextBox = triggerList[1].outputValue[0] as MyTextBox; int aiID = Convert.ToInt32(idTextBox.propertyValue); Monster_Data(triggerList[0], aiID); for (int i = 1; i < triggerList[1].outputValue.Count; ++i) { MyTextBox tempTextBox = triggerList[1].outputValue[i]; string convertString = triggerList[1].outputValue[i].propertyValue; //////////////////////////handle temporarily/////////////////////////////// if (Regex.IsMatch(convertString, @"^\d+$") || Regex.IsMatch(convertString, @"^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$")) { unit[tempTextBox.Property] = convertString; } } ////AIParam//// ////condition//// for (int i = 0; i < conditionList.Count; ++i) { unit["condition" + i] = conditionList[i].IDName; IronPython.Runtime.List conditionParam = new IronPython.Runtime.List(); for (int j = 0; j < conditionList[i].outputValue.Count; ++j) { MyTextBox tempTextBox = conditionList[i].outputValue[j]; conditionParam.Add(tempTextBox.propertyValue); } if (conditionParam.Count > 0) { unit["condition" + i + "Args"] = conditionParam; } ComboBox tempCombo = conditionList[i].myCombo; string selectedIndex = null; if (tempCombo.SelectedItem != null) { selectedIndex = ((ComboData)tempCombo.SelectedItem).Value; } if (selectedIndex != null) { unit["condition" + i + "Tgt0"] = selectedIndex; } } ////condition//// ////action//// for (int i = 0; i < actionList.Count; ++i) { unit["action" + i] = actionList[i].IDName; IronPython.Runtime.List actionParam = new IronPython.Runtime.List(); for (int j = 0; j < actionList[i].outputValue.Count; ++j) { MyTextBox tempTextBox = actionList[i].outputValue[j]; actionParam.Add(tempTextBox.propertyValue); } if (actionParam.Count > 0) { unit["action" + i + "Args"] = actionParam; } ComboBox tempCombo = actionList[i].myCombo; string selectedIndex = null; if (tempCombo.SelectedItem != null) { selectedIndex = ((ComboData)tempCombo.SelectedItem).Value; } if (selectedIndex != null) { unit["action" + i + "Tgt0"] = selectedIndex; } } ////action//// ////exp//// if (andOrder.Count > 0 && andOrder.Count <= 1 && orOrder.Count == 0) { unit["conditionExp"] = andOrder[1] == "True" ? true : false; } else { IronPython.Runtime.List orList = new IronPython.Runtime.List(); var dicSort = from objDic in orOrder orderby objDic.Key ascending select objDic; foreach (KeyValuePair <int, string> kvp in dicSort) { bool judge = kvp.Value == "True" ? true : false; orList.Add(judge); } IronPython.Runtime.List andList = new IronPython.Runtime.List(); int andLength = andOrder.Count; var newdicSort = from objDic in andOrder orderby objDic.Key ascending select objDic; int lastValue = 0; foreach (KeyValuePair <int, string> kvp in newdicSort) { if ((kvp.Key - lastValue) > 1) { andList.Add(orList); bool judge = kvp.Value == "True" ? true : false; andList.Add(judge); lastValue = kvp.Key; } else { bool judge = kvp.Value == "True" ? true : false; andList.Add(judge); lastValue = kvp.Key; } } if (andList.Count == andLength && orList.Count > 0) { andList.Add(orList); } IronPython.Runtime.PythonTuple expTuple = new IronPython.Runtime.PythonTuple(andList); unit["conditionExp"] = expTuple; } ////exp//// ////target//// if (targetList != null) { for (int i = 0; i < targetList.Count; ++i) { unit["tgtMethodName" + i] = targetList[i].IDName; IronPython.Runtime.List targetParam = new IronPython.Runtime.List(); for (int j = 0; j < targetList[i].outputValue.Count; ++j) { MyTextBox tempTextBox = targetList[i].outputValue[j]; targetParam.Add(tempTextBox.propertyValue); } if (targetParam.Count > 0) { unit["tgtMethodArgs" + i] = targetParam; } } } ////target//// data[newID] = unit; exportCode(data, "monster_ai_data.py"); }
public void Foo(IronPython.Runtime.PythonTuple tuple) { Console.WriteLine("Foo:Tuple says hello"); object[] objects = tuple.ToArray(); }