예제 #1
0
        public static RecipeData LoadFromJson(string path)
        {
            var data = new RecipeData();

            if (!File.Exists(path))
            {
                return(data);
            }

            var json = File.ReadAllText(path);

            if (string.IsNullOrWhiteSpace(json))
            {
                GlobalLog.Info("[ChaosExaltRecipe] Fail to load stash data from json. File is empty.");
                return(data);
            }
            int[] jsonCounts;
            try
            {
                jsonCounts = JsonConvert.DeserializeObject <int[]>(json);
            }
            catch (Exception)
            {
                GlobalLog.Info("[ChaosExaltRecipe] Fail to load stash data from json. Exception during json deserialization.");
                return(data);
            }
            if (jsonCounts == null)
            {
                GlobalLog.Info("[ChaosExaltRecipe] Fail to load stash data from json. Json deserealizer returned null.");
                return(data);
            }
            Array.Copy(jsonCounts, data._counts, data._counts.Length);
            return(data);
        }
예제 #2
0
        public static bool ShouldPickupChaos(Item item)
        {
            if (!RecipeData.IsItemForChaosRecipe(item, out var type))
            {
                return(false);
            }

            if (ChaosStashData.GetItemCount(type) + ChaosPickupData.GetItemCount(type) >= settings.Instance.GetMaxChaosItemCount(type))
            {
                return(false);
            }

            Log.Warn($"[ChaosExaltRecipe] Adding \"{item.Name}\" (iLvl: {item.ItemLevel}) for pickup.");
            ChaosPickupData.IncreaseItemCount(type);
            return(true);
        }
        public async Task <bool> Run()
        {
            if (ErrorLimitReached)
            {
                return(false);
            }

            var area = World.CurrentArea;

            if (!area.IsTown && !area.IsHideoutArea)
            {
                return(false);
            }

            if (settings.Instance.ExaltRecipeEnabled)
            {
                {
                    if (!Class1.ElderStashData.HasCompleteSet())
                    {
                        GlobalLog.Info("[SellRecipeTask] No Elder exalted recipe set to sell.");
                        return(false);
                    }

                    GlobalLog.Debug("[SellRecipeTask] Now going to take and sell a set of Elder items for exalt recipe.");

                    if (!await Inventories.OpenStashTab(Settings.Instance.ElderStashTab))
                    {
                        ReportError();
                        return(true);
                    }

                    Class1.ElderStashData.SyncWithStashTab(RecipeData.ExaltRecipeItemType.Elder);

                    if (!Class1.ElderStashData.HasCompleteSet())
                    {
                        GlobalLog.Error("[SellRecipeTask] Saved Elder stash data does not match actual stash data.");
                        await Coroutines.CloseBlockingWindows();

                        return(false);
                    }

                    var takenItemData = new RecipeData();

                    int lowestItemType = RecipeItemType.None;
                    var lowestItem     = Inventories.StashTabItems
                                         .OrderBy(i => i.ItemLevel)
                                         .FirstOrDefault(i => RecipeData.IsItemForElderExaltRecipe(i, out lowestItemType));

                    if (lowestItem == null)
                    {
                        GlobalLog.Error("[SellRecipeTask] Unknown error. Fail to find actual item for Elder exalt recipe.");
                        ReportError();
                        return(true);
                    }

                    GlobalLog.Debug($"[SellRecipeTask] Now taking \"{lowestItem.Name}\" (iLvl: {lowestItem.ItemLevel})");

                    if (!await Inventories.FastMoveFromStashTab(lowestItem.LocationTopLeft))
                    {
                        ReportError();
                        return(true);
                    }

                    takenItemData.IncreaseItemCount(lowestItemType);

                    while (true)
                    {
                        int type = RecipeItemType.None;

                        for (int i = 0; i < RecipeItemType.TotalTypeCount; i++)
                        {
                            var count = takenItemData.GetItemCount(i);
                            if (count == 0 || (count == 1 && i == RecipeItemType.Ring))
                            {
                                type = i;
                                break;
                            }
                        }

                        if (type == RecipeItemType.None)
                        {
                            break;
                        }

                        var item = Inventories.StashTabItems
                                   .Where(i => RecipeData.IsItemForElderExaltRecipe(i, out var t) && t == type)
                                   .OrderByDescending(i => i.ItemLevel)
                                   .FirstOrDefault();

                        if (item == null)
                        {
                            GlobalLog.Error("[SellRecipeTask] Unknown error. Fail to find actual item for Elder exalt recipe.");
                            ReportError();
                            return(true);
                        }

                        GlobalLog.Debug($"[SellRecipeTask] Now taking \"{item.Name}\" (iLvl: {item.ItemLevel})");

                        if (!await Inventories.FastMoveFromStashTab(item.LocationTopLeft))
                        {
                            ReportError();
                            return(true);
                        }

                        takenItemData.IncreaseItemCount(type);
                    }

                    await Wait.SleepSafe(300);

                    Class1.ElderStashData.SyncWithStashTab(RecipeData.ExaltRecipeItemType.Elder);

                    var recipeItems = Inventories.InventoryItems
                                      .Where(i => RecipeData.IsItemForElderExaltRecipe(i, out var t))
                                      .Select(i => i.LocationTopLeft)
                                      .ToList();

                    if (recipeItems.Count == 0)
                    {
                        GlobalLog.Error("[SellRecipeTask] Unknown error. There are no items in player's inventory after taking them from stash.");
                        ReportError();
                        return(true);
                    }

                    if (!await TownNpcs.SellItems(recipeItems))
                    {
                        ReportError();
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }