예제 #1
0
        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");
        }
예제 #2
0
 private void initParam(string[] paramName)
 {
     for (int i = 0; i < paramName.Length; ++i)
     {
         if (aiAction.ContainsKey(paramName[i]))
         {
             string param = Convert.ToString(aiAction[paramName[i]]);
             AIInitParams[paramName[i]] = param;
         }
     }
 }
예제 #3
0
        private static Dictionary <string, Dictionary <int, List <int> > > searchAIByID(List <int> IDList)
        {
            Dictionary <string, Dictionary <int, List <int> > > assemble = new Dictionary <string, Dictionary <int, List <int> > >();
            var     ipy  = Python.CreateRuntime();
            dynamic test = ipy.UseFile("Code\\monster_ai_data.py");

            IronPython.Runtime.PythonDictionary data = test.data;
            for (int i = 0; i < IDList.Count; ++i)
            {
                IronPython.Runtime.PythonDictionary aiAction = data[IDList[i]] as IronPython.Runtime.PythonDictionary;
                IronPython.Runtime.List             Trigger  = aiAction["trigger"] as IronPython.Runtime.List;
                string aiName = Convert.ToString(Trigger[0]);
                if (assemble.ContainsKey(aiName))
                {
                    if (!aiAction.ContainsKey("priority"))
                    {
                        if (assemble[aiName].ContainsKey(0))
                        {
                            assemble[aiName][0].Add(IDList[i]);
                        }
                        else
                        {
                            List <int> newIDList = new List <int>();
                            newIDList.Add(IDList[i]);
                            assemble[aiName][0] = newIDList;
                        }
                    }
                    else
                    {
                        int aiPriority = Convert.ToInt32(aiAction["priority"]);
                        if (assemble[aiName].ContainsKey(aiPriority))
                        {
                            assemble[aiName][aiPriority].Add(IDList[i]);
                        }
                        else
                        {
                            List <int> newIDList = new List <int>();
                            newIDList.Add(IDList[i]);
                            assemble[aiName][aiPriority] = newIDList;
                        }
                    }
                }
                else
                {
                    Dictionary <int, List <int> > tempAssemble = new Dictionary <int, List <int> >();
                    if (!aiAction.ContainsKey("priority"))
                    {
                        List <int> tempList = new List <int>();
                        tempList.Add(IDList[i]);
                        tempAssemble[0]  = tempList;
                        assemble[aiName] = tempAssemble;
                    }
                    else
                    {
                        int        aiPriority = Convert.ToInt32(aiAction["priority"]);
                        List <int> tempList   = new List <int>();
                        tempList.Add(IDList[i]);
                        tempAssemble[aiPriority] = tempList;
                        assemble[aiName]         = tempAssemble;
                    }
                }
            }
            return(assemble);
        }
예제 #4
0
        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);
        }