示例#1
0
        public void CCEval_Constant()
        {
            var exp = new ConstExp {
                Const = 3
            };
            var result = exp.Accept(eval);

            Assert.AreEqual(3, result);
        }
示例#2
0
        private void btnEvaluate_Click(object sender, EventArgs e)
        {
            int value;

            if (int.TryParse(textBox1.Text, out value))
            {
                Eval = value;
                Exp  = new ConstExp(value);
            }
        }
示例#3
0
        protected virtual Tuple <Type, Object> Visit(ConstExp exp)
        {
            if (exp.BaseToken.OpType == TokenType.Int)
            {
                return(new Tuple <Type, object>(typeof(int), int.Parse(exp.BaseToken.Source)));
            }

            if (exp.BaseToken.OpType == TokenType.Double)
            {
                return(new Tuple <Type, object>(typeof(double), double.Parse(exp.BaseToken.Source)));
            }

            if (exp.BaseToken.OpType == TokenType.ConstStr)
            {
                return(new Tuple <Type, object>(typeof(string), exp.BaseToken.Source));
            }
            throw new Exception();
        }
示例#4
0
        //根据表达式获取 常数列表
        public static ArrayList GetConstCollectionFromExp(Exp exp)
        {
            ArrayList al_ret = new ArrayList();

            if (exp is ActionExp)
            {
                ActionExp aexp = exp as ActionExp;
                if (aexp != null)
                {
                    foreach (Exp e in aexp.API.ArgValues)
                    {
                        ArrayList al = GetConstCollectionFromExp(e);
                        foreach (Exp expadd in al)
                        {
                            if (!al_ret.Contains(expadd))
                            {
                                al_ret.Add(expadd);
                            }
                        }
                    }
                }
            }
            else if (exp is ConstExp)
            {
                ConstExp cexp = exp as ConstExp;
                if (!al_ret.Contains(cexp))
                {
                    al_ret.Add(cexp);
                }
            }
            else if (exp is ObjectExp)
            {
            }
            else if (exp is VarExp)
            {
            }
            else
            {
            }

            return(al_ret);
        }
        protected override void Visit(ConstExp exp)
        {
            if (exp.BaseToken.OpType == TokenType.Int)
            {
                var tempVal = int.Parse(exp.BaseToken.Source);
                temp.Push(Expression.Constant(tempVal, typeof(int)));
            }

            if (exp.BaseToken.OpType == TokenType.Double)
            {
                var tempVal = double.Parse(exp.BaseToken.Source);
                temp.Push(Expression.Constant(tempVal, typeof(double)));
            }

            if (exp.BaseToken.OpType == TokenType.ConstStr)
            {
                var tempVal = exp.BaseToken.Source;
                temp.Push(Expression.Constant(tempVal, typeof(string)));
            }
            throw new Exception();
        }
示例#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;
                                }
                            }
                        }
                    }
                }
            }
        }
 public void CCEval_Constant()
 {
     var exp = new ConstExp { Const = 3 };
     var result = exp.Accept(eval);
     Assert.AreEqual(3, result);
 }
示例#8
0
文件: Model.cs 项目: yongyoung888/UL
 public void VisitExp(DB_Type type, DB_Member member, DB_StatementSyntax statement, ConstExp exp, Exp outer)
 {
     typeRef.Add(model.GetExpType(exp).GetRefType());
 }
示例#9
0
文件: Main.cs 项目: weimingtom/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);
        }
 protected virtual void Visit(ConstExp exp)
 {
 }
示例#11
0
        public static string ExpToString(Exp exp)
        {
            if (exp is ActionExp)
            {
                ActionExp aexp   = exp as ActionExp;
                string    strRet = string.Format("API.fun_{0}_{1}(", aexp.API.DBID, aexp.API.strName);
                if (aexp.API.isAsyn)
                {
                    strRet += "context, ";
                }
                foreach (Exp e in aexp.API.ArgValues)
                {
                    strRet += ExpToString(e) + ", ";
                }
                strRet  = strRet.TrimEnd(new char[] { ' ', ',' });
                strRet += ")";

                if (aexp.API.isAsyn)
                {
                    strRet = "(function() local argslist = SaveArgsToID(arg) local tmp = " + strRet + " arg = RestoreArgsFromID(argslist) return tmp end)()";
                }
                return(strRet);
            }
            else if (exp is ConstExp)
            {
                ConstExp cexp = exp as ConstExp;

                /*int[] strIDList = new int[] {
                 *  04, 27, 13 ,28, 32, 33, 36, 37, 39, 40, 41, 45, 47, 48, 49, 50,
                 *  51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
                 *  67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 80, 81, 82, 83, 85
                 * };  //需要生成时加双引号的类型的ID
                 * List<int> l = new List<int>();
                 * l.AddRange(strIDList);
                 * if (l.Contains(cexp.ReturnType.DBID))        //字符串,加引号
                 * {
                 *  return string.Format("\"{0}\"", cexp.DBValue.Replace("\"", "\\\""));
                 * }
                 * else
                 * {
                 *  return cexp.DBValue;
                 * }*/

                if (cexp.ReturnType.genAsString) // 字符串加引号
                {
                    return(string.Format("\"{0}\"", cexp.DBValue.Replace("\"", "\\\"")));
                }
                else
                {
                    return(cexp.DBValue);
                }
            }
            else if (exp is ObjectExp)
            {
                return(string.Format("arg[{0}]", (exp as ObjectExp).AsEventArgPos + 1)); //是事件的第几个参数, 0是第1个
            }
            else if (exp is VarExp)
            {
                return("ret");
            }
            else
            {
                return("");
            }
        }