Example #1
0
 private void btnSelect_Click(object sender, EventArgs e)
 {
     this.radioConstSel.Checked = true;
     ConstExp cexp = this.comboBoxConst.SelectedItem as ConstExp;
     string dbvalue = "";
     if(cexp != null)
     {
         dbvalue = cexp.DBValue;
     }
     string strLua = this.m_exp.ReturnType.QueryScript;
     object[] oRet = LuaManager.GetLuaManager().OnValueEdit(strLua, this.m_exp.ReturnType.QueryScript, dbvalue);
     if(oRet.Length > 0 && ((bool)oRet[0]))
     {
         if(oRet.Length > 1)
         {
             ConstExp ce = new ConstExp(oRet[1].ToString(), this.m_exp.ReturnType);
             this.comboBoxConst.Items.Clear();
             this.comboBoxConst.Items.Add(ce);
             this.comboBoxConst.SelectedItem = ce;
             this.comboBoxConst.Enabled = true;
         }
     }
 }
Example #2
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 #3
0
 public override object Clone()
 {
     ConstExp exp = new ConstExp();
     exp.DBValue = this.DBValue;
     exp.ReturnType = this.ReturnType;
     exp.strText = this.strText;
     return exp;
 }
Example #4
0
 //扫描引用列表,根据常数类型返回常数列表
 public static ConstExp[] ScanConstantFromHistory(TypeDefine type)
 {
     Hashtable ht_history = CacheManager.GetCacheManager().Global_Args_Table;
     if (ht_history == null)
         return new ConstExp[] { };
     if(ht_history.ContainsKey(type.DBID))
     {
         Hashtable ht = ht_history[type.DBID] as Hashtable;
         ConstExp[] exps = new ConstExp[ht.Count];
         ht.Values.CopyTo(exps, 0);
         return exps;
     }
     else
     {
         return new ConstExp[] { };
     }
 }
Example #5
0
 //根据返回值取常数列表
 public static ConstExp[] GetConstExpByReturnType(TypeDefine type)
 {
     string[] value_list = DBManager.DataBaseManager.GetDataBaseManager().GetConstDBValuesByRetType(type.DBID);
     if (value_list == null) return null;
     ConstExp[] ret = new ConstExp[value_list.Length];
     for (int i = 0; i < ret.Length; i++)
     {
         ret[i] = new ConstExp(value_list[i], type);
     }
     return ret;
 }
Example #6
0
        private void btnExp_Click(object sender, EventArgs e)
        {
            ExpForm expform = new ExpForm(this.m_actexp, this.m_gameEvent, true, null, null);
            expform.StartPosition = FormStartPosition.CenterParent;
            if (expform.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (this.m_actexp.ReturnType != null && this.m_actexp.ReturnType.DBID != expform.RusultExp.ReturnType.DBID)
                {
                    //清空连接线
                    this.listBox1.Items.Clear();
                }
                this.m_actexp = expform.RusultExp;
                this.m_Vexp.ReturnType = this.m_actexp.ReturnType;      //可变类型的返回值和表达式一致
                this.textBoxX1.Text = this.m_actexp.ToString();
                this.m_bChanged = true;
            }
            else
            {
                return;
            }

            //自动添加分支
            if (this.m_actexp != null && this.m_actexp.ReturnType != null)
            {
                //尝试添加枚举的所有类型
                if (this.m_actexp.ReturnType.isEnum)
                {
                    ConstExp[] cexpArray = ExpManager.GetConstExpByReturnType(this.m_actexp.ReturnType);
                    if (cexpArray != null)
                    {
                        foreach (ConstExp cexp in cexpArray)
                        {
                            ActionExp expa = ExpManager.CreateNewActionExp(new GameAPIDefine(FixedValueProvider.COMPARE_API_ID));
                            expa.API.ArgValues[0] = m_Vexp;           //左值为可变类型
                            expa.API.ArgValues[1] = cexp;             //右值为常数值
                            expa.strText = m_Vexp.ToString() + "==" + cexp.ToString();
                            if (!listBox1.Items.Contains(expa))
                            {
                                this.listBox1.Items.Add(expa);
                                this.m_bChanged = true;
                            }
                        }
                    }
                }

                //尝试添加OpenWindow的选项
                if (this.m_actexp is ActionExp)
                {
                    ActionExp aexp = this.m_actexp as ActionExp;
                    if (aexp.API.DBID == FixedValueProvider.OPENWINDOW_ID)          //多选项窗口
                    {
                        Exp dialogExp = aexp.API.ArgValues[2];      //第三个参数
                        if (dialogExp is ConstExp)                  //如果格式文本输入的是常数才处理
                        {
                            string strDialog = (dialogExp as ConstExp).DBValue;
                            Regex reg = new Regex(@"(?!=<)\$[^>]*(?=>)");
                            foreach (Match mat in  reg.Matches(strDialog))
                            {
                                string strSelection = mat.Value.TrimStart(new char[] { '$', 'C', ' ' });
                                ActionExp expa = ExpManager.CreateNewActionExp(new GameAPIDefine(FixedValueProvider.COMPARE_API_ID));
                                expa.API.ArgValues[0] = m_Vexp;           //左值为可变类型
                                ConstExp cexp = new ConstExp(strSelection, new TypeDefine(FixedValueProvider.TYPE_STRING_ID));
                                m_Vexp.ReturnType = cexp.ReturnType;
                                expa.API.ArgValues[1] = cexp;             //右值为字符串
                                expa.strText = m_Vexp.ToString() + "==" + cexp.ToString();
                                if (!listBox1.Items.Contains(expa))
                                {
                                    this.listBox1.Items.Add(expa);
                                    this.m_bChanged = true;
                                }
                            }
                        }
                    }
                }
            }
        }