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("[ChaosRecipe] Fail to load stash data from json. File is empty.");
                return(data);
            }
            int[] jsonCounts;
            try
            {
                jsonCounts = JsonConvert.DeserializeObject <int[]>(json);
            }
            catch (Exception)
            {
                GlobalLog.Info("[ChaosRecipe] Fail to load stash data from json. Exception during json deserialization.");
                return(data);
            }
            if (jsonCounts == null)
            {
                GlobalLog.Info("[ChaosRecipe] Fail to load stash data from json. Json deserealizer returned null.");
                return(data);
            }
            Array.Copy(jsonCounts, data._counts, data._counts.Length);
            return(data);
        }
Exemple #2
0
        public static bool ShouldPickup(Item item)
        {
            if (!RecipeData.IsItemForChaosRecipe(item, out var type))
            {
                return(false);
            }

            if (StashData.GetItemCount(type) + PickupData.GetItemCount(type) >= settings.Instance.GetMaxItemCount(type))
            {
                return(false);
            }

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

            var area = World.CurrentArea;

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

            if (!ChaosRecipe.StashData.HasCompleteSet())
            {
                GlobalLog.Info("[SellRecipeTask] No chaos recipe set to sell.");
                return(false);
            }

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

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

            ChaosRecipe.StashData.SyncWithStashTab();

            if (!ChaosRecipe.StashData.HasCompleteSet())
            {
                GlobalLog.Error("[SellRecipeTask] Saved 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.IsItemForChaosRecipe(i, out lowestItemType));

            if (lowestItem == null)
            {
                GlobalLog.Error("[SellRecipeTask] Unknown error. Fail to find actual item for chaos 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.IsItemForChaosRecipe(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 chaos 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);

            ChaosRecipe.StashData.SyncWithStashTab();

            var recipeItems = Inventories.InventoryItems
                              .Where(i => RecipeData.IsItemForChaosRecipe(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();
            }

            return(true);
        }