Exemple #1
0
        static public Dictionary <string, Ship> GetShips()
        {
            var result   = new Dictionary <string, Ship>();
            var shipInfo = WebInteraction.GET(SHIP_INFO_URL);

            shipInfo = shipInfo.Substring(13);
            shipInfo = shipInfo.Replace(@"'", @"""");

            var reader = new JsonTextReader(new StringReader(shipInfo));

            while (reader.Read())
            {
                if (reader.Path != string.Empty && Regex.Match(reader.Path, @"\d{10}").Value == reader.Path)
                {
                    if (!result.ContainsKey(reader.Path))
                    {
                        var ship = new Ship(reader.Path);
                        result.Add(ship.Cd, ship);
                    }
                    continue;
                }
                var match = Regex.Match(reader.Path, @"(\d{10})\.(.+)");
                switch (match.Groups[2].Value)
                {
                case "name":
                    result[match.Groups[1].Value].Name = reader.ReadAsString();
                    break;

                case "alias":
                    result[match.Groups[1].Value].Alias = reader.ReadAsString();
                    break;

                case "country":
                    result[match.Groups[1].Value].Country = reader.ReadAsString();
                    break;

                case "type":
                    result[match.Groups[1].Value].Type = reader.ReadAsString();
                    break;

                case "lvl":
                    result[match.Groups[1].Value].Lvl = reader.ReadAsInt32().Value;
                    break;
                }
            }
            return(result);
        }
Exemple #2
0
        public QueryResult LoadRecord()
        {
            var result = new QueryResult();

            var urlName = HttpUtility.UrlEncode(Username);
            var zone    = IsSouth ? "south" : "north";
            var json    = WebInteraction.GET(GET_LOGIN_URL + "name=" + urlName + "&zone=" + zone);

            // "account_db_id":"1837225125"
            if (json == @"{""errno"":2}")
            {
                throw new Exception("UserNotExits");
            }
            Aid = Regex.Match(json, @"(?<=""account_db_id"":"")\d{10}(?="")").Value;

            var shipInfo = WebInteraction.GET(SHIP_INFO_URL + "aid=" + Aid);
            var ships    = Ships.GetShips();

            //var shipInfos = new Dictionary<int, ShipInfo>();
            var shipCounts = new int[10];
            var shipPov    = new int[10];

            var    reader = new JsonTextReader(new StringReader(shipInfo));
            string thisId = "";

            while (reader.Read())
            {
                var match = Regex.Match(reader.Path, @"\[(\d+?)]\.(.+)");
                if (match.Groups[2].Value == "id.vehicleTypeCd")
                {
                    thisId = reader.ReadAsString();
                }
                if (match.Groups[2].Value == "battles")
                {
                    var lvl     = ships[thisId].Lvl;
                    var type    = ships[thisId].Type;
                    var battles = reader.ReadAsInt32().Value;
                    shipCounts[--lvl] += battles;
                    switch (type)
                    {
                    case "Cruiser":
                        result.CA += battles;
                        break;

                    case "AirCarrier":
                        result.CV += battles;
                        break;

                    case "Destroyer":
                        result.DD += battles;
                        break;

                    case "Battleship":
                        result.BB += battles;
                        break;
                    }
                }
                if (match.Groups[2].Value == "wins")

                {
                    var lvl = ships[thisId].Lvl;
                    shipPov[--lvl] += reader.ReadAsInt32().Value;
                }
            }

            result.LvlShipCount  = shipCounts;
            result.LvlShipVicPer = shipPov;

            return(result);
        }