예제 #1
0
        //打开脚本
        public bool OpenScript(bool openinthis)
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }
            Card c = dataform.GetCard();

            if (c.id <= 0 || c.IsType(CardType.TYPE_NORMAL) && !c.IsType(CardType.TYPE_PENDULUM))//卡片密码不能小于等于0, 非灵摆的通常怪兽无需脚本
            {
                return(false);
            }
            long id = c.id;

            if (c.alias != 0)
            {
                long dif = c.id - c.alias;
                if (dif > -10 && dif < 10)
                {
                    id = c.alias;
                }
            }
            string lua = dataform.GetPath().GetScript(id);

            if (!File.Exists(lua))
            {
                MyPath.CreateDirByFile(lua);
                if (MyMsg.Question(LMSG.IfCreateScript))//是否创建脚本
                {
                    using (FileStream fs = new FileStream(lua,
                                                          FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
                        sw.WriteLine("--" + c.name);
                        sw.WriteLine("function c" + id.ToString() + ".initial_effect(c)");
                        sw.WriteLine("\t");
                        sw.WriteLine("end");
                        sw.Close();
                        fs.Close();
                    }
                }
            }
            if (File.Exists(lua)) //如果存在,则打开文件
            {
                if (openinthis)   //是否用本程序打开
                {
                    MyConfig.OpenFileInThis(lua);
                }
                else
                {
                    System.Diagnostics.Process.Start(lua);
                }
                return(true);
            }
            return(false);
        }
예제 #2
0
        //打开脚本
        public bool OpenScript(bool openinthis)
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }
            Card c = dataform.GetCard();

            if (c.id <= 0)//卡片密码不能小于等于0
            {
                return(false);
            }
            string lua = dataform.GetPath().GetScript(c.id);

            if (!File.Exists(lua))
            {
                MyPath.CreateDirByFile(lua);
                if (MyMsg.Question(LMSG.IfCreateScript))//是否创建脚本
                {
                    using (FileStream fs = new FileStream(lua,
                                                          FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
                        sw.WriteLine("--" + c.name);
                        sw.WriteLine("function c" + c.id.ToString() + ".initial_effect(c)");
                        sw.WriteLine("\t");
                        sw.WriteLine("end");
                        sw.Close();
                        fs.Close();
                    }
                }
            }
            if (File.Exists(lua)) //如果存在,则打开文件
            {
                if (openinthis)   //是否用本程序打开
                {
                    MyConfig.OpenFileInThis(lua);
                }
                else
                {
                    System.Diagnostics.Process.Start(lua);
                }
                return(true);
            }
            return(false);
        }
예제 #3
0
        //打开脚本
        public bool OpenScript(bool openinthis, string addrequire)
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }
            Card   c  = dataform.GetCard();
            long   id = c.id;
            string lua;

            if (c.id > 0)
            {
                lua = dataform.GetPath().GetScript(id);
            }
            else if (addrequire.Length > 0)
            {
                lua = dataform.GetPath().GetModuleScript(addrequire);
            }
            else
            {
                return(false);
            }
            if (!File.Exists(lua))
            {
                MyPath.CreateDirByFile(lua);
                if (MyMsg.Question(LMSG.IfCreateScript))                //是否创建脚本
                {
                    using (FileStream fs = new FileStream(lua,
                                                          FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
                        if (string.IsNullOrEmpty(addrequire))
                        {
                            // OCG script
                            sw.WriteLine("--" + c.name);
                            sw.WriteLine("function c" + id.ToString() + ".initial_effect(c)");
                            sw.WriteLine("\t");
                            sw.WriteLine("end");
                        }
                        else
                        {
                            // DIY script
                            sw.WriteLine("--" + c.name);
                            sw.WriteLine("local m=" + id.ToString());
                            sw.WriteLine("local cm=_G[\"c\"..m]");
                            sw.WriteLine("xpcall(function() require(\"expansions/script/" + addrequire + "\") end,function() require(\"script/" + addrequire + "\") end)");
                            sw.WriteLine("function cm.initial_effect(c)");
                            sw.WriteLine("\t");
                            sw.WriteLine("end");
                        }

                        /*else
                         * { //module script
                         *  sw.WriteLine("--Module script \"" + addrequire + "\"");
                         * }*/
                        sw.Close();
                        fs.Close();
                    }
                }
            }
            if (File.Exists(lua))            //如果存在,则打开文件
            {
                if (openinthis)              //是否用本程序打开
                {
                    MyConfig.OpenFileInThis(lua);
                }
                else
                {
                    System.Diagnostics.Process.Start(lua);
                }
                return(true);
            }
            return(false);
        }
예제 #4
0
        //打开脚本
        public bool OpenScript(bool openinthis, string addrequire)
        {
            if (!dataform.CheckOpen())
            {
                return(false);
            }

            Card   c  = dataform.GetCard();
            long   id = c.id;
            string lua;

            if (c.id > 0)
            {
                lua = dataform.GetPath().GetScript(id);
                if (c.omega[0] > 0 && !File.Exists(lua))
                {
                    string tmp = MyPath.Combine(dataform.GetPath().gamepath, "../Scripts", "c" + id + ".lua");
                    if (File.Exists(tmp))
                    {
                        lua = tmp;
                    }
                    if (c.omega[0] > 0 && !string.IsNullOrEmpty(c.script) &&
                        !byte.TryParse(c.script, out _) && !File.Exists(lua) && openinthis)
                    {
                        DEXConfig.OpenFileInThis(c.script);
                        return(true);
                    }
                }
            }
            else if (addrequire.Length > 0)
            {
                lua = dataform.GetPath().GetModuleScript(addrequire);
            }
            else
            {
                return(false);
            }
            if (!File.Exists(lua))
            {
                if (c.omega[0] > 0 && !string.IsNullOrEmpty(c.script) && !byte.TryParse(c.script, out _) &&
                    !openinthis)
                {
                    MyPath.CreateDirByFile(lua);
                    using FileStream fs = new(lua,
                                              FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter sw = new(fs, new UTF8Encoding(false));
                    sw.Write(c.script);
                    sw.Close();
                    fs.Close();
                }
                if (MyMsg.Question(LMSG.IfCreateScript))//是否创建脚本
                {
                    MyPath.CreateDirByFile(lua);
                    using FileStream fs = new(lua,
                                              FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter sw = new(fs, new UTF8Encoding(false));
                    sw.WriteLine("--" + c.name);
                    sw.WriteLine("local s,id=GetID()");
                    if (!string.IsNullOrEmpty(addrequire))
                    {
                        sw.WriteLine("Duel.LoadScript(\"" + addrequire + ".lua\")"); // DIY script
                    }
                    sw.WriteLine("function s.initial_effect(c)");
                    sw.WriteLine("\t");
                    sw.WriteLine("end");
                    sw.Close();
                    fs.Close();
                }
            }
            if (File.Exists(lua)) //如果存在,则打开文件
            {
                if (openinthis)   //是否用本程序打开
                {
                    DEXConfig.OpenFileInThis(lua);
                }
                else
                {
                    _ = System.Diagnostics.Process.Start(lua);
                }

                return(true);
            }
            return(false);
        }