Example #1
0
        public void Load(string FileName)
        {
            FileName = "round/" + FileName;

            XmlLoad X = new XmlLoad();

            if (!X.Load(FileName)) return;

            this.FileName = FileName;

            while (X.Read())
            {
                switch (X.ElementName)
                {
                    case "hash": Hash = X.GetAttribute("value"); break;
                    case "playercount": PlayerCount = X.GetIntAttribute("value"); break;
                    case "lobby": Lobby = X.GetIntAttribute("value"); break;
                    case "lobbytype": LobbyType = (LobbyType)X.GetIntAttribute("value"); break;
                    case "game": Index = X.GetIntAttribute("index"); break;
                    case "round": CurrentRound = X.GetIntAttribute("index"); break;
                    case "result": StringResult = X.GetAttribute("value"); break;
                    case "drawreason": DrawReason = X.GetIntAttribute("value"); break;
                    case "riichistick": RiichiStick = X.GetIntAttribute("value"); break;
                    case "renchanstick": RenchanStick = X.GetIntAttribute("value"); break;
                    case "balancebefore": BalanceBefore = X.ReadIntArray(); break;
                    case "balanceafter": BalanceAfter = X.ReadIntArray(); break;
                    case "pay": Pay = X.ReadIntArray(); break;
                    case "winner": Winner = X.ReadBoolArray(); break;
                    case "loser": Loser = X.ReadBoolArray(); break;
                    case "openedsets": OpenedSets = X.ReadIntArray(); break;
                    case "naki": Naki = X.ReadIntArray(); break;
                    case "riichi": Riichi = X.ReadIntArray(); break;
                    case "dealer": Dealer = X.ReadBoolArray(); break;
                    case "tempai": Tempai = X.ReadBoolArray(); break;
                    case "wind": Wind = X.ReadIntArray(); break;
                    case "stepcount": StepCount = X.ReadIntArray(); break;
                    case "firstdora": FirstDora = X.GetIntAttribute("pointer"); break;
                    case "wall":
                    {
                        if (Wall == null) Wall = new Mahjong.Wall();

                        Wall.Dice = DecompositeIntList(X.GetAttribute("dice"));
                        Wall.Tiles = DecompositeIntList(X.GetAttribute("tiles"));
                    }
                    break;
                    case "steps":
                        {
                            int Count = X.GetIntAttribute("count");
                            XmlLoad Subtree = X.GetSubtree();
 
                            for (int j = 0; j < Count; j++)
                            {
                                Step NewStep = new Step(-1);

                                NewStep.ReadXml(Subtree);

                                Steps.Add(NewStep);
                            }

                            Subtree.Close();
                        }
                        break;
                    case "hands":
                        {
                            XmlLoad Subtree = X.GetSubtree();

                            while (Subtree.Read())
                            {
                                switch (Subtree.ElementName)
                                {
                                    case "hand":
                                        {
                                            int Player = Subtree.GetIntAttribute("player");

                                            XmlLoad HandData = Subtree.GetSubtree();
                                            StartHands[Player] = new Hand();

                                            StartHands[Player].ReadXml(HandData);

                                            HandData.Close();
                                        }
                                        break;
                                }
                            }

                            Subtree.Close();
                        }
                        break;
                    case "shantenlist":
                        {
                            XmlLoad Subtree = X.GetSubtree();

                            while (Subtree.Read())
                            {
                                switch (Subtree.ElementName)
                                {
                                    case "shanten":
                                        {
                                            int Player = Subtree.GetIntAttribute("player");
                                            int Count = Subtree.GetIntAttribute("shanten");

                                            XmlLoad ShantenData = Subtree.GetSubtree();

                                            while (ShantenData.Read())
                                            {
                                                switch (ShantenData.ElementName)
                                                {
                                                    case "step":
                                                        {
                                                            int Value = ShantenData.GetIntAttribute("value");
                                                            Shanten[Player].Add(Value);
                                                        }
                                                        break;
                                                }
                                            }

                                            ShantenData.Close();
                                        }
                                        break;
                                }
                            }

                            Subtree.Close();
                        }
                        break;
                    case "agari":
                        {
                            int Player = X.GetIntAttribute("player");

                            HanCount[Player] = X.GetIntAttribute("han");
                            FuCount[Player] = X.GetIntAttribute("fu");
                            Cost[Player] = X.GetIntAttribute("cost");

                            XmlLoad Subtree = X.GetSubtree();
                            while (Subtree.Read())
                            {
                                switch (Subtree.ElementName)
                                {
                                    case "yakulist":
                                        {
                                            int Count = Subtree.GetIntAttribute("count");
                                            XmlLoad YakuList = Subtree.GetSubtree();

                                            while (YakuList.Read())
                                            {
                                                switch (YakuList.ElementName)
                                                {
                                                    case "yaku":
                                                        Yaku Y = new Yaku();
                                                        Y.Cost = YakuList.GetIntAttribute("cost");
                                                        Y.Index = YakuList.GetIntAttribute("index");

                                                        Yaku[Player].Add(Y);
                                                        break;
                                                }
                                            }

                                            YakuList.Close();
                                        }
                                        break;
                                    case "waitings":
                                        {
                                            int Count = Subtree.GetIntAttribute("count");
                                            XmlLoad WaitList = Subtree.GetSubtree();

                                            while (WaitList.Read())
                                            {
                                                switch (WaitList.ElementName)
                                                {
                                                    case "waiting":
                                                        WinWaiting[Player].Add(WaitList.GetIntAttribute("value"));
                                                        break;
                                                }
                                            }

                                            WaitList.Close();
                                        }
                                        break;
                                }
                            }

                            Subtree.Close();
                        }
                        break;

                    case "dora":
                        {
                            int Count = X.GetIntAttribute("count");
                            Dora.Clear();

                            XmlLoad Doras = X.GetSubtree();
                            while (Doras.Read())
                            {
                                switch (Doras.ElementName)
                                {
                                    case "dora":
                                        Dora.Add(Doras.GetIntAttribute("pointer"));
                                        break;
                                }
                            }
                            Doras.Close();
                        }
                        break;
                    case "uradora":
                        {
                            int Count = X.GetIntAttribute("count");

                            UraDora.Clear();

                            XmlLoad Doras = X.GetSubtree();
                            while (Doras.Read())
                            {
                                switch (Doras.ElementName)
                                {
                                    case "dora":
                                        UraDora.Add(Doras.GetIntAttribute("pointer"));
                                        break;
                                }
                            }
                            Doras.Close();
                        }
                        break;
                }
            }
        }
Example #2
0
        public bool LoadXml(string Hash)
        {
            string FileName = "replay/" + Hash + ".xml";
            XmlLoad X = new XmlLoad();

            if (!X.Load(FileName)) return false;
            while (X.Read())
            {
                switch (X.ElementName)
                {
                    case "hash": this.Hash = X.GetAttribute("value"); break;
                    case "playercount": PlayerCount = X.GetIntAttribute("value"); break;
                    case "lobby": Lobby = X.GetIntAttribute("value"); break;
                    case "lobbytype": LobbyType = (LobbyType)X.GetIntAttribute("value"); break;
                    case "balance": Balance = X.ReadIntArray(); break;
                    case "result": Result = X.ReadIntArray(); break;
                    case "place": Place = X.ReadIntArray(); break;
                    case "playerlist":
                        {
                            int Count = 4;
                            XmlLoad Subtree = X.GetSubtree();

                            for (int j = 0; j < Count; j++)
                            {
                                Players[j] = new Player();
                                Players[j].ReadXml(Subtree);
                            }

                            Subtree.Close();
                        }
                        break;
                    case "roundlist":
                        {
                            int Count = X.GetIntAttribute("count");

                            XmlLoad Subtree = X.GetSubtree();
                            for (int j = 0; j < Count; j++)
                            {
                                if (!Subtree.Read()) break;

                                switch (Subtree.ElementName)
                                {
                                    case "round":
                                        string FName = Subtree.GetAttribute("filename");
                                        int Index = Subtree.GetIntAttribute("index");
                                        Round R = new Round();
                                        Rounds.Add(R);

                                        RoundFiles.Add(FName);

                                        XmlLoad RoundData = Subtree.GetSubtree();
                                        while (RoundData.Read())
                                        {
                                            switch (Subtree.ElementName)
                                            {
                                                case "round": R.CurrentRound = RoundData.GetIntAttribute("index"); break;
                                                case "renchan": R.RenchanStick = RoundData.GetIntAttribute("index"); break;
                                                case "result": R.StringResult = RoundData.GetAttribute("value"); break;
                                                case "balancebefore": R.BalanceBefore = RoundData.ReadIntArray(); break;
                                                case "balanceafter": R.BalanceAfter = RoundData.ReadIntArray(); break;
                                                case "pay": R.Pay = RoundData.ReadIntArray(); break;
                                                case "han": R.HanCount = RoundData.ReadIntArray(); break;
                                                case "fu": R.FuCount = RoundData.ReadIntArray(); break;
                                                case "cost": R.Cost = RoundData.ReadIntArray(); break;
                                                case "winner": R.Winner = RoundData.ReadBoolArray(); break;
                                                case "loser": R.Loser = RoundData.ReadBoolArray(); break;
                                                case "openedsets": R.OpenedSets = RoundData.ReadIntArray(); break;
                                                case "riichi": R.Riichi = RoundData.ReadIntArray(); break;
                                                case "dealer": R.Dealer = RoundData.ReadBoolArray(); break;
                                            }
                                        }

                                        RoundData.Close();

                                        // try to load more data
                                        R.Load(FName);
                                        break;
                                }
                            }

                            Subtree.Close();
                        }
                        break;
                }
            }

            Date = GetDateTimeFromHash(Hash);

            return true;
        }