Example #1
0
        private static string CreateData(IniStructure IniData, string comment)
        {       //Iterates through all categories and keys and appends all data to Data
            int CategoryCount = IniData.GetCategories().Length;

            int[]  KeyCountPerCategory = new int[CategoryCount];
            string Data = comment;

            string[] temp = new string[2];          // will contain key-value pair

            for (int i = 0; i < CategoryCount; i++) // Gets keycount per category
            {
                string CategoryName = IniData.GetCategories()[i];
                KeyCountPerCategory[i] = IniData.GetKeys(CategoryName).Length;
            }

            for (int catcounter = 0; catcounter < CategoryCount; catcounter++)
            {
                Data += "\r\n[" + IniData.GetCategoryName(catcounter) + "]\r\n";
                // writes [Category] to Data
                for (int keycounter = 0; keycounter < KeyCountPerCategory[catcounter]; keycounter++)
                {
                    temp[0] = IniData.GetKeyName(catcounter, keycounter);
                    temp[1] = IniData.GetValue(catcounter, keycounter);
                    Data   += temp[0] + "=" + temp[1] + "\r\n";
                    // writes the key-value pair to Data
                }
            }
            return(Data);
        }
Example #2
0
        public string show(string oldVarIndex, string mapname, string ClientPath)
        {
            this.advTree1.Nodes.Clear();
            Node node_map = new Node();
            node_map.Text = mapname;
            node_map.Image = imageList1.Images[0];
            advTree1.Nodes.Add(node_map);

            string iniFileName = Path.Combine(ClientPath,
                @"data\source\maps\" + mapname + "\\" + mapname + ".Map.Logical");


            IniStructure m_inis = new IniStructure();
            m_inis = IniStructure.ReadIni(iniFileName);
            if (m_inis == null) 
            {
                MessageBox.Show("ÕÒ²»µ½" + iniFileName, "´íÎó",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
                return "";
            }   
            int nNpcNumber = Convert.ToInt32(m_inis.GetValue("MAIN", "NumNPC").ToString());

            for (int i = 0; i < nNpcNumber; i++)
            {
                string szName = m_inis.GetValue("NPC" + i.ToString(), "szName");
                string szNickName = m_inis.GetValue("NPC" + i.ToString(), "szNickName");
                string nTempleteID = m_inis.GetValue("NPC" + i.ToString(), "nTempleteID");
                string nX = m_inis.GetValue("NPC" + i.ToString(), "nX");
                string nY = m_inis.GetValue("NPC" + i.ToString(), "nY");
                string nZ = m_inis.GetValue("NPC" + i.ToString(), "nZ");

                if (szNickName != null && szNickName != "")
                {
                    Node node = new Node();
                    node.Text = szNickName;
                    node.Image = imageList1.Images[1];
                    node.Tag = szNickName;
                    node.Cells.Add(new Cell(szName == null ? "" : szName));
                    node.Cells.Add(new Cell(string.Format("{0},{1},{2}", nX, nY, nZ)));
                    node.Cells.Add(new Cell());
                    node_map.Nodes.Add(node);
                    if (node.Tag.ToString() == oldVarIndex)
                    {
                        advTree1.SelectedNode = node;
                    }
                }
            }

            if(this.ShowDialog() == DialogResult.OK)
            {
                return m_SelectedKey;
            }
            return oldVarIndex;
        }
Example #3
0
        /// <summary>
        /// Reads an ini file and returns the content as an IniStructure. Returns null if an error occurred.
        /// </summary>
        /// <param name="Filename">The filename to read</param>
        /// <returns></returns>
        public static IniStructure ReadIni(string Filename)
        {
            string Data = ReadFile(Filename);

            if (Data == null)
            {
                return(null);
            }

            IniStructure data = InterpretIni(Data);

            return(data);
        }
Example #4
0
        public static IniStructure InterpretIni(string Data)
        {
            IniStructure IniData = new IniStructure();

            string[] Lines = RemoveAndVerifyIni(DivideToLines(Data));
            // Divides the Data in lines, removes comments and empty lines
            // and verifies if the ini is not corrupted
            // Returns null if it is.
            if (Lines == null)
            {
                return(null);
            }

            if (IsLineACategoryDef(Lines[0]) != LineType.Category)
            {
                return(null);
                // Ini is faulty - does not begin with a categorydef
            }
            string CurrentCategory = "";

            foreach (string line in Lines)
            {
                switch (IsLineACategoryDef(line))
                {
                case LineType.Category:          // the line is a correct category definition
                    string NewCat = line.Substring(1, line.Length - 2);
                    IniData.AddCategory(NewCat); // adds the category to the IniData
                    CurrentCategory = NewCat;
                    break;

                case LineType.NotACategory:     // the line is not a category definition
                    string[] keyvalue = GetDataFromLine(line);
                    IniData.AddValue(CurrentCategory, keyvalue[0], keyvalue[1]);
                    // Adds the key-value to the current category
                    break;

                case LineType.Faulty:     // the line is faulty
                    return(null);
                }
            }
            return(IniData);
        }
Example #5
0
        public static IniStructure InterpretIni(string Data)
        {
            IniStructure IniData = new IniStructure();
            string[] Lines = RemoveAndVerifyIni(DivideToLines(Data));
            // Divides the Data in lines, removes comments and empty lines
            // and verifies if the ini is not corrupted
            // Returns null if it is.
            if (Lines == null)
                return null;

            if (IsLineACategoryDef(Lines[0]) != LineType.Category)
            {
                return null;
                // Ini is faulty - does not begin with a categorydef
            }
            string CurrentCategory = "";
            foreach (string line in Lines)
            {
                switch (IsLineACategoryDef(line))
                {
                    case LineType.Category:	// the line is a correct category definition
                        string NewCat = line.Substring(1, line.Length - 2);
                        IniData.AddCategory(NewCat); // adds the category to the IniData
                        CurrentCategory = NewCat;
                        break;
                    case LineType.NotACategory: // the line is not a category definition
                        string[] keyvalue = GetDataFromLine(line);
                        IniData.AddValue(CurrentCategory, keyvalue[0], keyvalue[1]);
                        // Adds the key-value to the current category
                        break;
                    case LineType.Faulty: // the line is faulty
                        return null;
                }
            }
            return IniData;
        }
Example #6
0
        private static string CreateData(IniStructure IniData, string comment)
        {	//Iterates through all categories and keys and appends all data to Data
            int CategoryCount = IniData.GetCategories().Length;
            int[] KeyCountPerCategory = new int[CategoryCount];
            string Data = comment;
            string[] temp = new string[2]; // will contain key-value pair

            for (int i = 0; i < CategoryCount; i++) // Gets keycount per category
            {
                string CategoryName = IniData.GetCategories()[i];
                KeyCountPerCategory[i] = IniData.GetKeys(CategoryName).Length;
            }

            for (int catcounter = 0; catcounter < CategoryCount; catcounter++)
            {
                Data += "\r\n[" + IniData.GetCategoryName(catcounter) + "]\r\n";
                // writes [Category] to Data
                for (int keycounter = 0; keycounter < KeyCountPerCategory[catcounter]; keycounter++)
                {
                    temp[0] = IniData.GetKeyName(catcounter, keycounter);
                    temp[1] = IniData.GetValue(catcounter, keycounter);
                    Data += temp[0] + "=" + temp[1] + "\r\n";
                    // writes the key-value pair to Data
                }
            }
            return Data;
        }
Example #7
0
 private static string CreateData(IniStructure IniData)
 {
     return CreateData(IniData, "");
 }
Example #8
0
 /// <summary>
 /// Writes an IniStructure to a file without a comment.
 /// </summary>
 /// <param name="IniData">The contents to write</param>
 /// <param name="Filename">The complete path and name of the file</param>
 /// <returns></returns>
 public static bool WriteIni(IniStructure IniData, string Filename)
 {
     string DataToWrite = CreateData(IniData);
     return WriteFile(Filename, DataToWrite);
 }
Example #9
0
 /// <summary>
 /// Writes an IniStructure to a file with a comment.
 /// </summary>
 /// <param name="IniData">The contents to write</param>
 /// <param name="Filename">The complete path and name of the file</param>
 /// <param name="comment">Comment to add</param>
 /// <returns></returns>
 public static bool WriteIni(IniStructure IniData, string Filename, string comment)
 {
     string DataToWrite = CreateData(IniData, BuildComment(comment));
     return WriteFile(Filename, DataToWrite);
 }
Example #10
0
        /// <summary>
        /// 读取连接字符串
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="sectionName">分段名</param>
        /// <param name="keyName">键名</param>
        /// <returns>连接字符串</returns>
        private static string GetConnectString(string fileName, string sectionName, string keyName)
        {            
            string content = FileFolderHelper.FileToString(fileName);
            SymmetricMethod symmetricMethod = new SymmetricMethod();
            content = symmetricMethod.Decrypto(content);

            IniStructure iniStructure = new IniStructure();
            iniStructure = IniStructure.ReadIniWithContent(content);
            connectString = iniStructure.GetValue(sectionName, keyName);

            return connectString;
        }
Example #11
0
File: Main.cs Project: viticm/pap2
        /// <summary>
        /// 挂脚本
        /// </summary>
        /// <param name="constExp">表达式对象</param>
        /// <returns>是否挂接成功</returns>
        public bool SetScript(ConstExp constExp)
        {
            string FileName = "";
            StringBuilder Content = new StringBuilder();
            string Sql = "";
            Content.AppendLine("--" + constExp.ToString());
            Content.AppendLine("Include('scripts/flowlib/api.lua')");
            Content.AppendLine("Include('scripts/flowlib/event_dispatch.lua')");
            Content.AppendLine("using('EventDispatch')");

            switch (constExp.ReturnType.DBID)
            {
                case 13:    //道具模板
                    #region 道具生成

                    //生成文件
                    FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\item\" + constExp.DBValue.Replace(",", "_") + ".lua");
                    Content.Append(string.Format(@"
function OnUse(player, item)
	local sta, err = pcall(function() EventDispatch.AOnUse('{0}', player, item) end)
	if err then
		print('err: ' .. err)
	end
	return false, false
end
", constExp.DBValue));
                    //写数据库
                    if (!constExp.DBValue.Contains(","))
                        return false;
                    string r1 = constExp.DBValue.Split(new char[] { ',' })[0];
                    string r2 = constExp.DBValue.Split(new char[] { ',' })[1];
                    string sql = "";
                    switch(r1)
                    {
                        case "5":
                            {
                                sql = "Other";
                                break;
                            }
                        case "6":
                            {
                                sql = "item_Custom_Weapon";
                                break;
                            }
                        case "7":
                            {
                                sql = "item_Custom_Armor";                                
                                break;
                            }
                        case "8":
                            {
                                sql = "Custom_Trinket";                                
                                break;
                            }
                    }

                    if (!exportTableList.Contains(sql))
                    {
                        exportTableList.Add(sql);
                    }                    

                    sql = string.Format("update [{0}] set scriptname='scripts\\flowlib\\catcher\\item\\{1}.lua' where id='{2}'", sql, constExp.DBValue.Replace(",", "_"), r2);
                    Sql = sql;
                    #endregion
                    break;
                case 20:    //NPC模板
                    #region NPC模板
                    //生成文件
                    FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\npc\" + constExp.DBValue + ".lua");
                    Content.Append(string.Format(@"
function OnDialogue(npc, player)
    local gotevent = false
    local sta, err = pcall(function() gotevent = EventDispatch.AOnDialogue('{0}', npc, player) end)
    if err then
	    print('err: ' .. err)
    end
    if not gotevent then
	  	player.OpenWindow(TARGET.NPC, npc.dwID,
                  npc.GetAutoDialogString(player.dwID)
                  )
    end
end;

function OnDeath(npc, killer)
    local sta, err = pcall(function() EventDispatch.AOnDeath('{0}', npc) end)     --任何情况下的死亡
    if err then
        print('err: ' .. err)
    end
    if not killer then
        sta, err = pcall(function() EventDispatch.AOnNaturalDeath('{0}', npc) end)   --自然死亡
        if err then
            print('err: ' .. err)
        end
    elseif IsPlayer(killer) then
        sta, err = pcall(function() EventDispatch.AOnDeathByPlayer('{0}', npc, killer) end)  --被player杀死的
        if err then
            print('err: ' .. err)
        end   
    else
        sta, err = pcall(function() EventDispatch.AOnDeathByNpc('{0}', npc, killer) end)     --被NPC杀死的
        if err then
            print('err: ' .. err)
        end        
    end    
end;
", constExp.DBValue));

                    //写数据库
                    Sql = string.Format("update NpcTemplate set scriptname='scripts\\flowlib\\catcher\\npc\\{0}.lua' where id='{0}'", constExp.DBValue);
                    
                    //检查实体覆盖模板的问题
                    string strResult = "";

                    if (this.m_inis == null)
                    {
                        string mapname = this.m_mapname;
                        string iniFileName = Path.Combine(this.m_rootdir,
                            @"data\source\maps\" + mapname + "\\" + mapname + ".Map.Logical");
                        if (!File.Exists(iniFileName)) break;
                        this.m_inis = new IniStructure();
                        this.m_inis = IniStructure.ReadIni(iniFileName);
                    }
                    
                    if (m_inis == null) break;
                    int nNpcNumber = Convert.ToInt32(m_inis.GetValue("MAIN", "NumNPC").ToString());

                    for (int i = 0; i < nNpcNumber; i++)
                    {
                        string szName = m_inis.GetValue("NPC" + i.ToString(), "szName");
                        string dwScriptID = m_inis.GetValue("NPC" + i.ToString(), "dwScriptID");
                        string nTempleteID = m_inis.GetValue("NPC" + i.ToString(), "nTempleteID");
                        string nX = m_inis.GetValue("NPC" + i.ToString(), "nX");
                        string nY = m_inis.GetValue("NPC" + i.ToString(), "nY");
                        string nZ = m_inis.GetValue("NPC" + i.ToString(), "nZ");
                        if (nTempleteID == constExp.DBValue && dwScriptID != "00000000")
                        {
                            strResult += string.Format("{4} 的 {0}({1},{2},{3}) 在场景编辑器已经挂接了脚本,自动挂接是通过写模板实现的,所以流程图对于这个实体将无效。", szName, nX, nY, nZ, this.m_mapname) + "\r\n";
                        }
                    }
                    if(strResult != "")
                    {
                        MessageBox.Show(strResult, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    if (!exportTableList.Contains("NpcTemplate"))
                    {
                        exportTableList.Add("NpcTemplate");
                    }     

                    #endregion
                    break;
                case 21:    //任务模板
                    #region 任务模板
                    //生成文件
                    FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\quest\" + constExp.DBValue + ".lua");
                    Content.Append(string.Format(@"
function OnAcceptQuest(player)
	local sta, err = pcall(function() EventDispatch.AOnAcceptQuest('{0}', player, '{0}') end)
	if err then
		print('err: ' .. err)
	end
end;

function OnFinishQuest(player)
	local sta, err = pcall(function() EventDispatch.AOnFinishQuest('{0}', player, '{0}') end)
	if err then
		print('err: ' .. err)
	end
end;

function OnCancelQuest(player)
	local sta, err = pcall(function() EventDispatch.AOnCancelQuest('{0}', player, '{0}') end)
	if err then
		print('err: ' .. err)
	end
end;
", constExp.DBValue));
                    //写数据库
                    Sql = string.Format("update tbl_quests set scriptname='scripts\\flowlib\\catcher\\quest\\{0}.lua' where questid='{0}'", constExp.DBValue);

                    if (!exportTableList.Contains("tbl_quests"))
                    {
                        exportTableList.Add("tbl_quests");
                    }     

                    #endregion
                    break;
                case 35:    //Doodad模板
                    #region Doodad模板
                    //生成文件
                    FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\doodad\" + constExp.DBValue + ".lua");
                    Content.Append(string.Format(@"
function OnOpen(doodad, player)
    local gotevent = false
    local sta, err = pcall(function() gotevent = EventDispatch.AOnOpen('{0}', doodad, player) end)
    if err then
	    print('err: ' .. err)
    end
    if not gotevent then
	  	--做默认的事情
    end
	return false
end;

function OnBreak(doodad, player)
    local gotevent = false
    local sta, err = pcall(function() gotevent = EventDispatch.AOnBreak('{0}', doodad, player) end)
    if err then
	    print('err: ' .. err)
    end
end;

function OnPick(doodad, player)
    local gotevent = false
    local sta, err = pcall(function() gotevent = EventDispatch.AOnPick('{0}', doodad, player) end)
    if err then
	    print('err: ' .. err)
    end
end;

", constExp.DBValue));
                    //写数据库
                    Sql = string.Format("update tbl_doodad set script='scripts\\flowlib\\catcher\\doodad\\{0}.lua' where id='{0}'", constExp.DBValue);
                    
                    //实体覆盖模板
                    strResult = "";
                    if (this.m_inis == null)
                    {
                        string mapname = this.m_mapname;
                        string iniFileName = Path.Combine(this.m_rootdir,
                            @"data\source\maps\" + mapname + "\\" + mapname + ".Map.Logical");
                        if (!File.Exists(iniFileName)) break;
                        this.m_inis = new IniStructure();
                        this.m_inis = IniStructure.ReadIni(iniFileName);
                    }
                    if (m_inis == null) break;
                    nNpcNumber = Convert.ToInt32(m_inis.GetValue("MAIN", "NumDoodad").ToString());

                    for (int i = 0; i < nNpcNumber; i++)
                    {
                        string szName = m_inis.GetValue("Doodad" + i.ToString(), "szName");
                        string dwScriptID = m_inis.GetValue("Doodad" + i.ToString(), "dwScriptID");
                        string nTempleteID = m_inis.GetValue("Doodad" + i.ToString(), "nTempleteID");
                        string nX = m_inis.GetValue("Doodad" + i.ToString(), "nX");
                        string nY = m_inis.GetValue("Doodad" + i.ToString(), "nY");
                        string nZ = m_inis.GetValue("Doodad" + i.ToString(), "nZ");
                        if (nTempleteID == constExp.DBValue && dwScriptID != "00000000")
                        {
                            strResult += string.Format("{4} 的 {0}({1},{2},{3}) 在场景编辑器已经挂接了脚本,自动挂接是通过写模板实现的,所以流程图对于这个实体将无效。", szName, nX, nY, nZ, this.m_mapname) + "\r\n";
                        }
                    }
                    if (strResult != "")
                    {
                        MessageBox.Show(strResult, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    if (!exportTableList.Contains("tbl_doodad"))
                    {
                        exportTableList.Add("tbl_doodad");
                    }

                    #endregion
                    break;
                case 36:    //Trap模板
                    #region Trap模板
                    string[] list = constExp.DBValue.Split(new char[] { ',' });
                    //生成文件
                    FileName = Path.Combine(this.m_rootdir, @"scripts\flowlib\catcher\trap\" + list[0] + ".map." + list[1] + ".lua");
                    Content.Append(string.Format(@"
function OnEnterTrap(player, cell)
	local sta, err = pcall(function() EventDispatch.AOnEnterTrap('{0}', player, cell, '{0}') end)
	if err then
		print('err: ' .. err)
	end
end;

function OnLeaveTrap(player, oldCell)
	local sta, err = pcall(function() EventDispatch.AOnLeaveTrap('{0}', player, oldCell, '{0}') end)
	if err then
		print('err: ' .. err)
	end
end;

", constExp.DBValue));
                    #endregion
                    break;
                case 39:    //地图模板
                    SetSceneScript();
                    return true;
                default:
                    throw new Exception("目前不支持[" + constExp.ToString() + "]类型的捕获器挂接");
            }
            if (saveFile != null)
            {
                saveFile(FileName, Content.ToString());            //导出lua文件
            }

            /*
            if (executeSQLCommand != null && Sql != "")
            {
                executeSQLCommand(Sql);
            }
            */ 

            return true;
        }
Example #12
0
        // add by kuangsihao
        public static IniStructure ReadIniWithContent(string content)
        {
            IniStructure data = InterpretIni(content);

            return(data);
        }
Example #13
0
 private static string CreateData(IniStructure IniData)
 {
     return(CreateData(IniData, ""));
 }
Example #14
0
        /// <summary>
        /// Writes an IniStructure to a file without a comment.
        /// </summary>
        /// <param name="IniData">The contents to write</param>
        /// <param name="Filename">The complete path and name of the file</param>
        /// <returns></returns>
        public static bool WriteIni(IniStructure IniData, string Filename)
        {
            string DataToWrite = CreateData(IniData);

            return(WriteFile(Filename, DataToWrite));
        }
Example #15
0
        /// <summary>
        /// Writes an IniStructure to a file with a comment.
        /// </summary>
        /// <param name="IniData">The contents to write</param>
        /// <param name="Filename">The complete path and name of the file</param>
        /// <param name="comment">Comment to add</param>
        /// <returns></returns>
        public static bool WriteIni(IniStructure IniData, string Filename, string comment)
        {
            string DataToWrite = CreateData(IniData, BuildComment(comment));

            return(WriteFile(Filename, DataToWrite));
        }