using System; using nativeCom; using System.Runtime.InteropServices; using System.Diagnostics; using System.IO; using MrWu.Configuration; using System.Xml; using Game.Data; public class mj_ : mj { public static mj_ instance; protected virtual int playerCnt { get { return 4; } } /* [Conditional("DEBUG")] public virtual void hufan_ut(){ //hpr fangpaonew fanidx pk.zjpos; int hpr; int fangpaonew; int zjpos; int[] fangpaos = new int[]{ -1,0,1,2,3,10,11,12,13 }; for(int i=0;i /// 排列组合 根据几个获取数组 /// public int[][] pailiezuhe_count(int count){ int[][] duilie = new int[count][]; } /// /// 以idx开头的数组 /// /// public int[] pailiezuhe_startIdx(int StartIdx,int count){ } /// /// 获取Startidx开头的第x个 /// /// /// /// /// public int pailiezhuhe_startIdx_idx(int idx,int StratIdx,int count){ } */ protected MemoryStream gzObj; /// /// 解析麻将子游戏规则 /// /// public virtual void setZyxGz(ref tcls_mem_dll_agame now) { } /// /// 获取规则 /// /// /// unsafe protected void getGz(int address, out Tr_MJGZ gz) { ABlock ab = new ABlock(); myCom_zyx.Instance.getDataOfStruct(address, ref ab, (int*)&ab); IntPtr ptr = new IntPtr((int)ab.pt + 100); gz = (Tr_MJGZ)Marshal.PtrToStructure(ptr, typeof(Tr_MJGZ)); } unsafe protected void getGz(int address, ref ABlock ab, out Tr_MJGZ gz) { IntPtr ptr = new IntPtr((int)ab.pt + 100); gz = (Tr_MJGZ)Marshal.PtrToStructure(ptr, typeof(Tr_MJGZ)); } /// /// 设置规则 /// /// unsafe public override void setGz(ref tcls_mem_dll_agame now, int memoryAddress) { MrWu.Debug.Debug.Info("读取规则!"); //解析通用规则 if (now.isLibrary == 0) { //测试取测试的 //now.gz = Form2.fmSub.gzTest; log("读取测试规则!"); return; } //第一步硬盘读文件 if (gzObj == null) { string gzPath = funs.instance.getGzPath(); XmlDocument doc = new XmlDocument(); doc.Load(gzPath); Object tmp = (Tr_MJGZ)Configuration.LoadConfiguration(typeof(Tr_MJGZ), doc.DocumentElement); // MrWu.Debug.Debug.Log("反序列化:"); //Object tmp = baseFuntion.DeSerizeable(gzPath); // MrWu.Debug.Debug.Log("反序列化之后!"); gzObj = baseFuntion.Serizeable(tmp); } now.gz = (Tr_MJGZ)baseFuntion.DeSerizeable(gzObj); if (now.gzcs_big != null) { string stt = ""; int len = now.gzcs_big.Length; for (int i = 0; i < len; i++) { stt += now.gzcs_big[i]; }; MrWu.Debug.Debug.Info("通用规则:" + stt); //牌类型 now.gz.StyOf_Pai = (sbyte)now.gzcs_big[0];//tyGz[0].charToInt(); //1表示不能吃 2可以吃 now.gz.Not_Chi = to0(now.gzcs_big[1], now.gz.Not_Chi); //2电脑喜欢杠 now.gz.Fan_GangPai = to0(now.gzcs_big[2], now.gz.Fan_GangPai); //3必须自摸 if (now.gzcs_big[3] != 0) { if (now.gzcs_big[3] == 1) now.gz.StyOf_HuPai = 2; else if (now.gzcs_big[3] == 2) now.gz.StyOf_HuPai = 1; else now.gz.StyOf_HuPai = 0; } //4吃就清一色 if (now.gzcs_big[4] != 0) { if (now.gzcs_big[4] == 1) now.gz.chijiuqys = 1; else if (now.gzcs_big[4] == 2) now.gz.chijiuqys = 0; else now.gz.chijiuqys = 11; } now.gz.chijiuqys = (sbyte)now.gzcs_big[4];//.charToInt(); //5听功能 now.gz.TingStyle_ = getLast(now.gzcs_big[5], now.gz.TingStyle_);// (sbyte)(tyGz[5].charToInt() - 1); //6牌墙蹲高 now.gz.dungaoCnt = (sbyte)now.gzcs_big[6];//.charToInt(); //8风可成阙 now.gz.ChiXi = getLast(now.gzcs_big[8], now.gz.ChiXi);// (sbyte)(tyGz[8].charToInt() - 1); //9箭可成阙 now.gz.ChiYuan = getLast(now.gzcs_big[9], now.gz.ChiYuan);// (sbyte)(tyGz[9].charToInt() - 1); //10加倍次数 //log("通用规则加倍次数:" + now.gz.jiabeiCnt + "," + now.gzcs_big[10]); now.gz.jiabeiCnt = Tojiabei(now.gzcs_big[10], now.gz.jiabeiCnt);// tyGz[10].charToInt(); //11前多少张可以加倍 now.gz.jiabeichupaicnt = Tojiabei(now.gzcs_big[11], now.gz.jiabeichupaicnt); //12听后看牌 now.gz.tinghoukanpai = getLast(now.gzcs_big[12], now.gz.tinghoukanpai);// (sbyte)(tyGz[12].charToInt() - 1); } else { log("没有找到通用规则!"); } //解析前25个通用规则 if (now.gzcs_friend != null) { int len = now.gzcs_friend.Length; string stt = ""; for(int i=0;i(memoryAddress, ref ab1, (int*)&ab1); int gzSize = Marshal.SizeOf(typeof(Tr_MJGZ)); //log("规则大小:" + gzSize +"自摸方式:" + now.gz.StyOf_HuPai + ",清一色:" + now.gz.chijiuqys); byte[] bts = new byte[gzSize]; byte[] gzdata = funs.instance.StructToBytes(now.gz); Buffer.BlockCopy(gzdata, 0, bts, 0, gzSize); funs.instance.memToNative_bytes(bts, ref ab1, 100); } /// /// 0表示不生效 1表示可以 2表示不可以 装换成 0不可以 1可以 /// protected sbyte to0(byte ch, int org) { //sbyte t_sty = ch.charToInt(); if (ch == 1) return (sbyte)ch; if (ch == 0) return (sbyte)org; return 0; } /// /// 获取上一个 0无效返回原值 /// /// protected sbyte getLast(byte ch, int org) { //sbyte t_sty = ch.charToInt(); if (ch == 0) return (sbyte)org; return (sbyte)(ch - 1); } /// /// 加倍的转换 0无效 1不加 2加几次 转 0不加 >2加几次 /// /// private sbyte Tojiabei(byte ch, int org) { //sbyte t_sty = ch.charToInt(); if (ch == 0) return (sbyte)org; if (ch == 1) return 0; return (sbyte)ch; } }