Exemple #1
0
        public static async Task <Prices> GetPricesAsync(int ID)
        {
            Prices prices = null;

            ApiItem tempItem = await GetItemAsync(ID).ConfigureAwait(false);

            if (tempItem.flags.Contains("AccountBound"))
            {
                return(prices);
            }

            string strApiPath;

            strApiPath = "commerce/prices/" + ID.ToString();

            HttpResponseMessage response = await client.GetAsync(strApiPath).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                string jsonString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                //MessageBox.Show(jsonString);

                var price = JsonConvert.DeserializeObject <Prices>(jsonString);

                prices = price;
            }
            else
            {
                MessageBox.Show("Failed to retrieve data from:\n\r" + strApiPath);
            }


            return(prices);
        }
Exemple #2
0
        public static async Task <ApiItem> GetItemAsync(int ID)
        {
            ApiItem apiItem = null;
            string  strApiPath;

            strApiPath = "items";
            if (ID != -1)
            {
                strApiPath = strApiPath + "?ids=" + ID.ToString();
            }

            HttpResponseMessage response = await client.GetAsync(strApiPath).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                string jsonString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var item = JsonConvert.DeserializeObject <List <ApiItem> >(jsonString);

                foreach (ApiItem i in item)
                {
                    apiItem = i;
                }
            }
            else
            {
                MessageBox.Show("Failed to retrieve data from:\n\r" + strApiPath);
            }


            return(apiItem);
        }
Exemple #3
0
        public static async Task LoadItemAsync(int ID, Item curItem, int multiplier)
        {
            //MessageBox.Show("Test");

            try
            {
                curItem.itemData = new ApiItem();
                curItem.itemData = await GetItemAsync(ID).ConfigureAwait(false);

                curItem.itemRecipe = new Recipe();

                ApiRecipe curRecipe = new ApiRecipe();
                curRecipe = await GetRecipeAsync(ID).ConfigureAwait(false);

                ApiItem temp = new ApiItem();

                //string testString = string.Format("Current Recipe: {0}", curItem.itemData.name);
                if (curRecipe != null && (!RefinedIDs.Contains(curItem.itemData.id) || !bUseRefinedMaterials))
                {
                    //MessageBox.Show(string.Format("Current Item: {0}\n\rCalculating ingredients", curItem.itemData.name));
                    foreach (ApiIngredient i in curRecipe.Ingredients)
                    {
                        temp = await GetItemAsync(i.item_id).ConfigureAwait(false);

                        //MessageBox.Show(curItem.itemRecipe.itemIDs[0].ToString());
                        curItem.itemRecipe.itemIDs.Add(temp.id);
                        curItem.itemRecipe.itemCounts.Add(i.count);
                        curItem.itemRecipe.itemNames.Add(temp.name);
                    }

                    switch (curItem.itemRecipe.itemIDs.Count)
                    {
                    case 4:
                        curItem.itemIngredient4 = new Item
                        {
                            iQuantity = curItem.itemRecipe.itemCounts[3]
                        };
                        LoadItemAsync(curItem.itemRecipe.itemIDs[3], curItem.itemIngredient4, curItem.iQuantity * multiplier).GetAwaiter().GetResult();
                        goto case 3;

                    case 3:
                        curItem.itemIngredient3 = new Item
                        {
                            iQuantity = curItem.itemRecipe.itemCounts[2]
                        };
                        LoadItemAsync(curItem.itemRecipe.itemIDs[2], curItem.itemIngredient3, curItem.iQuantity * multiplier).GetAwaiter().GetResult();
                        goto case 2;

                    case 2:
                        curItem.itemIngredient2 = new Item
                        {
                            iQuantity = curItem.itemRecipe.itemCounts[1]
                        };
                        LoadItemAsync(curItem.itemRecipe.itemIDs[1], curItem.itemIngredient2, curItem.iQuantity * multiplier).GetAwaiter().GetResult();
                        goto case 1;

                    case 1:
                        curItem.itemIngredient1 = new Item
                        {
                            iQuantity = curItem.itemRecipe.itemCounts[0]
                        };
                        LoadItemAsync(curItem.itemRecipe.itemIDs[0], curItem.itemIngredient1, curItem.iQuantity * multiplier).GetAwaiter().GetResult();
                        goto default;

                    default:
                        break;
                    }
                }
                else
                {
                    if (!curItem.itemData.flags.Contains("AccountBound"))
                    {
                        //MessageBox.Show(string.Format("Ingredient '{0}' does not have sub-recipe.", curItem.itemData.name));
                        if (iMasterListIDs.Contains(curItem.itemData.id))
                        {
                            iMasterListCount[iMasterListIDs.IndexOf(curItem.itemData.id)] += (curItem.iQuantity * multiplier);
                            //MessageBox.Show(string.Format("Item Exists.  Added {0} to {1}.", (curItem.iQuantity * multiplier), curItem.itemData.name));
                        }
                        else
                        {
                            iMasterListCount.Add(curItem.iQuantity * multiplier);
                            iMasterListIDs.Add(curItem.itemData.id);
                            strMasterListNames.Add(curItem.itemData.name);
                            //MessageBox.Show(string.Format("Item Does not Exist.  Added {0} of {1}.", (curItem.iQuantity * multiplier), curItem.itemData.name));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed: " + e.ToString());
            }
        }