public void Save(string FileName) { if (!Directory.Exists("round")) Directory.CreateDirectory("round"); FileName = "round/" + FileName; XmlSave X = new XmlSave(FileName); this.FileName = FileName; if (PlayerCount == 3) X.Xml3Man(); X.StartXML("mjround"); X.WriteTag("version", "value", 175); X.WriteTag("hash", "value", Hash); X.WriteTag("game", "index", Index); X.WriteTag("playercount", "value", PlayerCount); X.WriteTag("lobby", "value", Lobby); X.WriteTag("lobbytype", "value", Convert.ToInt32(LobbyType)); X.WriteTag("round", "index", CurrentRound); X.WriteTag("result", "value", StringResult); X.WriteTag("drawreason", "value", DrawReason); X.WriteTag("riichistick", "value", RiichiStick); X.WriteTag("renchanstick", "value", RenchanStick); X.WriteTag("balancebefore", BalanceBefore); X.WriteTag("balanceafter", BalanceAfter); X.WriteTag("pay", Pay); X.WriteTag("winner", Winner); X.WriteTag("loser", Loser); X.WriteTag("openedsets", OpenedSets); X.WriteTag("naki", Naki); X.WriteTag("riichi", Riichi); X.WriteTag("wind", Wind); X.WriteTag("dealer", Dealer); X.WriteTag("stepcount", StepCount); X.WriteTag("tempai", Tempai); X.WriteTag("firstdora", "pointer", FirstDora); // Wall if(Wall != null) { string Tiles = String.Join(",", Wall.Tiles.Select(p => p.ToString()).ToArray()); string Dice = String.Join(",", Wall.Dice.Select(p => p.ToString()).ToArray()); X.StartTag("wall"); X.Attribute("tiles", Tiles); X.Attribute("dice", Dice); X.EndTag(); } // Dora { X.StartTag("dora"); X.Attribute("count", Dora.Count); for (int j = 0; j < Dora.Count; j++) { X.WriteTag("dora", "pointer", Dora[j]); } X.EndTag(); } if (UraDora.Count > 0) { X.StartTag("uradora"); X.Attribute("count", UraDora.Count); for (int j = 0; j < UraDora.Count; j++) { X.WriteTag("dora", "pointer", UraDora[j]); } X.EndTag(); } // Start hands { X.StartTag("hands"); for (int i = 0; i < PlayerCount; i++) { X.StartTag("hand"); X.Attribute("player", i); StartHands[i].WriteXml(X); X.EndTag(); } X.EndTag(); } // Actions { X.StartTag("steps"); X.Attribute("count", Steps.Count); for (int j = 0; j < Steps.Count; j++) { Steps[j].WriteXml(X); } X.EndTag(); } // Shanten dynamic { X.StartTag("shantenlist"); for (int i = 0; i < PlayerCount; i++) { if (Shanten[i].Count == 0) continue; X.StartTag("shanten"); X.Attribute("player", i); X.Attribute("count", Shanten[i].Count); for (int j = 0; j < Shanten[i].Count; j++) X.WriteTag("step", "value", Shanten[i][j]); X.EndTag(); } X.EndTag(); } // Yaku list { for (int i = 0; i < PlayerCount; i++) { if (Yaku[i].Count == 0) continue; X.StartTag("agari"); X.Attribute("player", i); X.Attribute("han", HanCount[i]); X.Attribute("fu", FuCount[i]); X.Attribute("cost", Cost[i]); { X.StartTag("yakulist"); X.Attribute("count", Yaku[i].Count); for (int j = 0; j < Yaku[i].Count; j++) { X.StartTag("yaku"); X.Attribute("index", Yaku[i][j].Index); X.Attribute("cost", Yaku[i][j].Cost); X.EndTag(); } X.EndTag(); } if (Winner[i]) { // Waiting hand List<int> WaitingList = WinWaiting[i]; X.StartTag("waitings"); X.Attribute("count", WaitingList.Count); for (int k = 0; k < WaitingList.Count; k++) { X.WriteTag("waiting", "value", WaitingList[k]); } X.EndTag(); } X.EndTag(); } } X.EndXML(); X.Close(); }
public void SaveXml(string FileName) { XmlSave X = new XmlSave(FileName); if (PlayerCount == 3) X.Xml3Man(); X.StartXML("mjreplay"); // replay ID X.WriteTag("hash", "value", Hash); X.WriteTag("playercount", "value", PlayerCount); X.WriteTag("lobby", "value", Lobby); X.WriteTag("lobbytype", "value", Convert.ToInt32(LobbyType)); X.WriteTag("result", Result); X.WriteTag("balance", Balance); X.WriteTag("place", Place); { X.StartTag("playerlist"); for (int j = 0; j < PlayerCount; j++) { Players[j].WriteXml(X); } X.EndTag(); } { X.StartTag("roundlist"); X.Attribute("count", Rounds.Count); for (int i = 0; i < Rounds.Count; i++) { if(Rounds[i].FileName.CompareTo("") == 0) Rounds[i].FileName = Hash + "_" + i.ToString() + ".xml"; X.StartTag("round"); X.Attribute("index", i); X.Attribute("filename", Rounds[i].FileName); // Results { int[] StepCount = new int[4]; for (int j = 0; j < 4; j++) StepCount[j] = 0; for (int j = 0; j < Rounds[i].Steps.Count; j++) { if (Rounds[i].Steps[j].Type == StepType.STEP_DISCARDTILE) StepCount[Rounds[i].Steps[j].Player]++; } X.WriteTag("round", "index", Rounds[i].CurrentRound); X.WriteTag("renchan", "index", Rounds[i].RenchanStick); X.WriteTag("result", "value", Rounds[i].StringResult); X.WriteTag("balancebefore", Rounds[i].BalanceBefore); X.WriteTag("balanceafter", Rounds[i].BalanceAfter); X.WriteTag("pay", Rounds[i].Pay); X.WriteTag("han", Rounds[i].HanCount); X.WriteTag("fu", Rounds[i].FuCount); X.WriteTag("cost", Rounds[i].Cost); X.WriteTag("steps", StepCount); X.WriteTag("winner", Rounds[i].Winner); X.WriteTag("loser", Rounds[i].Loser); X.WriteTag("openedsets", Rounds[i].OpenedSets); X.WriteTag("riichi", Rounds[i].Riichi); X.WriteTag("dealer", Rounds[i].Dealer); } X.EndTag(); } X.EndTag(); } X.EndXML(); X.Close(); }