Exemplo n.º 1
0
        public static async Task <bool> Execute(List <ItemSelectionType> types = null)
        {
            if (!CanRun())
            {
                return(true);
            }

            Core.Logger.Verbose("[CubeItemsToMaterials] Time to Convert some junk into delicious crafting materials.");

            if (!await MoveToAndInteract.Execute(TownInfo.KanaisCube))
            {
                Core.Logger.Log("[CubeItemsToMaterials] Failed to move to the cube, quite unfortunate.");
                return(true);
            }

            // * Never create more of the material you have most of.
            // * Always use the material you have most of to create others.
            // * Only allow creation of a material if it has been selected in settings.

            var settingsTypes = Core.Settings.KanaisCube.GetCraftingMaterialTypes();
            var allTypes      = GetAllConversionTypes();
            var orderedTypes  = OrderByAmount(allTypes);
            var highestCount  = orderedTypes.First();
            var allowedTypes  = settingsTypes.Select(GetCurrencyType);
            var otherTypes    = orderedTypes.Skip(1).Where(t => allowedTypes.Contains(t)).ToList();

            foreach (var toType in otherTypes)
            {
                if (!await ConvertMaterials.Execute(highestCount, toType))
                {
                    Core.Logger.Log("[Cube] Failed! Finished!");
                    return(true);
                }
                await Coroutine.Sleep(100);

                await Coroutine.Yield();
            }

            Core.Logger.Verbose("[Cube] CubeItemsToMaterials Finished!");
            return(true);
        }
Exemplo n.º 2
0
        public static bool CanRun()
        {
            if (!ZetaDia.IsInGame || !ZetaDia.IsInTown)
            {
                return(false);
            }

            if (!LastCanRunResult && DateTime.UtcNow.Subtract(LastCanRunCheck).TotalSeconds < 5)
            {
                return(LastCanRunResult);
            }

            var kule = TownInfo.ZoltunKulle?.GetActor() as DiaUnit;

            if (kule != null)
            {
                if (kule.IsQuestGiver)
                {
                    Core.Logger.Verbose("[CubeRaresToLegendary] Cube is not unlocked yet");
                    return(false);
                }
            }

            var settingsTypes = Core.Settings.KanaisCube.GetCraftingMaterialTypes();

            if (!settingsTypes.Any())
            {
                Core.Logger.Verbose("[CubeItemsToMaterials] No materials have been selected in settings");
                return(false);
            }

            // * Never create more of the material you have most of.
            // * Always use the material you have most of to create others.
            // * Only allow creation of a material if it has been selected in settings.

            var allTypes         = GetAllConversionTypes();
            var orderedTypes     = OrderByAmount(allTypes);
            var highestCountType = orderedTypes.First();
            var allowedTypes     = settingsTypes.Select(GetCurrencyType);
            var otherTypes       = orderedTypes.Skip(1).Where(t => allowedTypes.Contains(t)).ToList();
            var result           = (int)highestCountType != -1 && otherTypes.Any(t => ConvertMaterials.CanRun(highestCountType, t, true));

            if (result)
            {
                Core.Logger.Verbose($"[CubeItemsToMaterials] Selected {highestCountType} as the material with highest count - {Core.Inventory.Currency.GetCurrency(highestCountType)}");
            }

            LastCanRunCheck  = DateTime.UtcNow;
            LastCanRunResult = result;
            return(result);
        }