Exemple #1
0
        //get player's ships
        private static List<Ship> GetShips(long playerId)
        {
            string appKey = @"11749197d5c8ca823ed4beb2199922aa";
            string url = @"https://api.worldofwarships.com/wows/ships/stats/";
            string.Format(url, appKey);
            var restClient = new RestClient(url);
            var request = new RestRequest(Method.GET);
            request.AddParameter("application_id", appKey);
            request.AddParameter("account_id", playerId.ToString());
            request.AddParameter("in_garage", "1");
            var response = restClient.Execute(request);
            string tmp = response.Content;

            //File.WriteAllText(@"D:\projects\tmp\ships.json", response.Content);

            List<Ship> results = new List<Ship>();
            //String tmp = File.ReadAllText(@"D:\projects\tmp\zigships.json");

            JObject d = JObject.Parse(tmp);
            //Dictionary<string, JObject> ships = d["data"].First()[0].First().ToObject<Dictionary<string, JObject>>();

            foreach (var s in d["data"].First().First())
            {
                try
                {
                    Ship ship = new Ship();  ;// = GetShip(s["ship_id"].ToString());
                    //ship.Experience = Convert.ToInt32(s["pvp"]["xp"].ToString());
                    results.Add(ship);
                }
                catch
                { }
            }
            return results;
        }
Exemple #2
0
        //this method needs work, it also might not belong here.....
        private Ship SetShipAttributes(Ship ship)
        {
            Dictionary<long, Module> modules = Modules.Modules;
            ship.ArtilleryMax = 0;
            ship.ArtilleryMin = 0;
            decimal minRange = int.MaxValue;
            decimal maxRange = int.MinValue;
            decimal minSpeed = int.MaxValue;
            decimal maxSpeed = int.MinValue;
            decimal maxTorpRange = int.MinValue;

            //need to relode modules, looks like there's new ships ????

            foreach (Module module in ship.Modules)
            {
                if (module.Type.Equals("fire_control"))
                {
                    Module m = modules[module.ID];
                    //Console.WriteLine(module.ID + " " + m.Range);
                    minRange = Math.Min(minRange, m.Range);
                    maxRange = Math.Max(maxRange, m.Range);
                }
                else if (module.Type.Equals("engine"))
                {
                    Module m = modules[module.ID];
                    //Console.WriteLine(module.ID + " " + m.Range);
                    minSpeed = Math.Min(minSpeed, m.Speed);
                    maxSpeed = Math.Max(maxSpeed, m.Speed);
                }
                else if (module.Type.Equals("torpedoes"))
                {
                    Module m = modules[module.ID];
                    //Console.WriteLine(module.ID + " " + m.Range);
                    maxTorpRange = Math.Max(maxTorpRange, m.Range);
                }

            }
            if (maxRange != int.MinValue)
                ship.ArtilleryMax = maxRange;
            if (minRange != int.MaxValue)
                ship.ArtilleryMin = minRange;

            if (maxTorpRange != int.MinValue)
                ship.TorpRangeMax = maxTorpRange;
            else
                ship.TorpRangeMax = 0;

            ship.SpeedMax = maxSpeed;
            ship.SpeedMin = minSpeed;

            return ship;
        }
Exemple #3
0
        private ShipsData GetAllShips(string json)
        {
            ShipsData results = new ShipsData();

            JObject d = JObject.Parse(json);

            Dictionary<string, JToken> ships2 = d["data"].ToObject<Dictionary<string, JToken>>();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            foreach (string key in ships2.Keys)
            {
                Ship ship = new Ship(key, ships2[key]);
                Console.WriteLine("CheckShip");
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            Dictionary<string, JObject> ships = d["data"].ToObject<Dictionary<string, JObject>>();

            HashSet<String> allTiers = new HashSet<string>();
            HashSet<String> allTypes = new HashSet<string>();
            HashSet<String> allNations = new HashSet<string>();
            Dictionary<long, Ship> allShips = new Dictionary<long, Ship>();

            foreach (var key in ships.Keys)
            {
                Ship ship = new Ship(key, ships[key]);
                ship = SetShipAttributes(ship);
                allShips[ship.ID] = ship;
                if (!allTiers.Contains(ship.Tier.ToString()))
                    allTiers.Add(ship.Tier.ToString());
                if (!allTypes.Contains(ship.Type))
                    allTypes.Add(ship.Type);
                if (!allNations.Contains(ship.Nation))
                    allNations.Add(ship.Nation);

            }
            results.AllShips = allShips;
            results.AllNations = allNations.ToList();
            results.AllNations.Sort();
            results.AllTypes = allTypes.ToList();
            results.AllTypes.Sort();
            results.AllTiers = allTiers.ToList();
            results.AllTiers.Sort();
            results.DataCreatedAt = DateTime.Now.ToUniversalTime();
            return results;
        }