/// <summary> /// 初始化数据 /// </summary> /// <param name="dir">目标数据所在目录</param> public void init(string dir) { datas = new ArrayList(); events = new ArrayList(); oldPoint = new Hashtable(); string [] txts = null; try { txts = Directory.GetFiles(dir, "*.txt"); } catch { } if (txts != null && txts.Length > 0) { foreach (string txt in txts) { string [] edata = File.ReadAllLines(txt); datas.AddRange(edata); } } if (datas.Count > 0) { for (int t = 0, l = datas.Count; t < l; t++) { string d = (string)datas[t]; MGEvent ev = selectFromTxt(d); ev.tindex = t; events.Add(ev); } } if (f != null) { f(); } }
private bool checkTitles(MGEvent ev, ArrayList titles) { if (titles != null && titles.Count > 0) { if (titles.Contains(ev.title)) { return(true); } } return(false); }
// 转换文本至索引 private MGEvent selectFromTxt(string d) { MGEvent ev = new MGEvent(); ev.x = int.MaxValue; ev.y = int.MaxValue; ev.z = int.MaxValue; int i = d.IndexOf('['); int j = d.IndexOf(']'); if (i == 0) { if (j > i) { string dandt = d.Substring(i + 1, j - i - 1); string [] dtt = dandt.Split(' '); if (dtt.Length == 3) { try { ev.dt = DateTime.Parse(dtt[0] + " " + dtt[1]); }catch {} ev.title = dtt[2]; } } } else { return(ev); } string nextNode = null; i = d.IndexOf("玩家"); if (i > -1) { nextNode = d.Substring(i); int pnodeNums = 0; string [] pinfos = nextNode.Split(' '); bool oped = false, closed = false; if (pinfos.Length > 0) { if (pinfos[0] == "玩家") { ev.player = ""; while (pinfos[pnodeNums + 1][0] < 127 && pnodeNums < pinfos.Length - 1) { ev.player += (pinfos[1 + pnodeNums] + " "); ++pnodeNums; } ev.player = ev.player.Trim(); } if (pinfos[pnodeNums + 1] == "悬空地") { ev.isFloat = true; } else if (pinfos[pnodeNums + 1] == "改变维度至") { ev.dimension = pinfos[pnodeNums + 2]; } else { string [] opi = pinfos[pnodeNums + 1].Split(new String [] { "在" }, StringSplitOptions.RemoveEmptyEntries); if (opi.Length > 1) { ev.dimension = opi[1]; oped = opi[0].Equals("开启"); closed = opi[0].Equals("关闭"); } } } int points = nextNode.IndexOf('('); if (points > -1) { int pointe = nextNode.IndexOf(')'); if (pointe > points) { string pointstr = nextNode.Substring(points + 1, pointe - points - 1); string [] ps = pointstr.Split(','); if (ps.Length > 2) { ev.x = int.Parse(ps[0]); ev.y = int.Parse(ps[1]); ev.z = int.Parse(ps[2]); if (oped) { oldPoint[ev.player] = new P3D(ev.x, ev.y, ev.z); } if (closed) { oldPoint[ev.player] = null; } } } } else { if (!string.IsNullOrEmpty(ev.player)) { Object ooldp = oldPoint[ev.player]; if (null != ooldp) { P3D oldp = (P3D)ooldp; ev.x = oldp.x; ev.y = oldp.y; ev.z = oldp.z; } } } } return(ev); }
private bool checkXboxID(MGEvent ev, string id) { return(id == null || (id != null && ev.player == id)); }
private bool checkZs(MGEvent ev, int [] zs) { return(zs == null || (zs != null && (ev.z >= zs[0] && ev.z <= zs[1]))); }
private bool checkYs(MGEvent ev, int [] ys) { return(ys == null || (ys != null && (ev.y >= ys[0] && ev.y <= ys[1]))); }
private bool checkXs(MGEvent ev, int [] xs) { return(xs == null || (xs != null && (ev.x >= xs[0] && ev.x <= xs[1]))); }
private bool checkDT(MGEvent ev, DateTime [] dts) { return(dts == null || (dts != null && (ev.dt >= dts[0] && ev.dt <= dts[1]))); }