예제 #1
0
        public async Task <Advert> FetchAdvertAsync(string id)
        {
            var server     = _getServerUrl();
            var requestUrl = string.Format(URL, server, id);

            try
            {
                // Create an HTTP web request using the URL:
                var request = (HttpWebRequest)WebRequest.Create(new Uri(requestUrl));
                request.ContentType = "application/json";
                request.Method      = "GET";

                // Send the request to the server and wait for the response:
                using (WebResponse response = await request.GetResponseAsync())
                {
                    // Get a stream representation of the HTTP web response:
                    using (System.IO.Stream stream = response.GetResponseStream())
                    {
                        using (var reader = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
                        {
                            string responseText = reader.ReadToEnd();
                            return(_parser.ParseJson <Advert>(responseText));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #2
0
    public Armor CreateArmor()
    {
        ItemDataFile data = parser.ParseJson("itemGeneration/Armors");

        //LoadFile
        Armor armor = new Armor("armorObject ", "items_" + random.Next(102, 124), 10);

        armor.Name = data.names[random.Next(0, data.names.Length)];

        armor.description = data.descriptions[random.Next(0, data.descriptions.Length)];
        armor.rarity      = CreateItemRarity();

        armor.Price      = ((int)armor.rarity + 1) * random.Next(minPriceValue, maxPriceValue) * armorPriceMultiplier;
        armor.attributes = random.Next(minArmor, MaxArmor) + " armor";

        for (int i = 0; i < (int)armor.rarity; i++)
        {
            armor.echantements.Add(data.enchantements[random.Next(data.enchantements.Length)]);
        }
        return(armor);
    }