Пример #1
0
        public static async Task <bool> Execute(bool dontStashCraftingMaterials = false)
        {
            if (!ZetaDia.IsInTown)
            {
                Core.Logger.Verbose("[StashItems] Need to be in town to stash items");
                return(false);
            }

            var stashItems = Core.Inventory.Backpack.Where(ShouldStash).Where(i => AllowedToStash(dontStashCraftingMaterials, i)).ToList();

            if (!stashItems.Any())
            {
                Core.Logger.Verbose($"[StashItems] Nothing to stash");
                return(false);
            }

            Core.Logger.Verbose($"[StashItems] Now to stash {stashItems.Count} items");
            stashItems.ForEach(i => Core.Logger.Debug($"[StashItems] Stashing: {i.Name} ({i.ActorSnoId}) InternalName={i.InternalName} Ancient={i.IsAncient} Ann={i.AnnId}"));

            GameUI.CloseVendorWindow();

            await MoveToStash();

            if (!UIElements.StashWindow.IsVisible)
            {
                var stash = ZetaDia.Actors.GetActorsOfType <GizmoPlayerSharedStash>().FirstOrDefault();
                if (stash == null)
                {
                    return(false);
                }

                if (!await MoveTo.Execute(stash.Position))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to stash interact position ({stash.Name}) to stash items :(");
                    return(false);
                }
                ;
                Navigator.PlayerMover.MoveTowards(stash.Position);
                if (!await MoveToAndInteract.Execute(stash, 5f))
                {
                    Core.Logger.Error($"[SalvageItems] Failed to move to stash ({stash.Name}) to stash items :(");
                    return(false);
                }
                ;
                await Coroutine.Yield();

                stash.Interact();
            }

            if (UIElements.StashWindow.IsVisible)
            {
                if (Core.Settings.Items.BuyStashTabs && StashPagesAvailableToPurchase)
                {
                    Core.Logger.Error("[StashItems] Attempting to buy stash pages");
                    InventoryManager.BuySharedStashSlots();
                }

                await StackRamaladnisGift();
                await StackCraftingMaterials();

                var isStashFull = false;

                // Get items again to make sure they are valid and current this tick
                var freshItems = Core.Inventory.Backpack.Where(ShouldStash).Where(i => AllowedToStash(dontStashCraftingMaterials, i)).ToList();
                if (!freshItems.Any())
                {
                    Core.Logger.Verbose($"[StashItems] No items to stash");
                }
                else
                {
                    foreach (var item in freshItems)
                    {
                        try
                        {
                            item.OnUpdated(); // make sure wrong col/row/location is not cached after a move.

                            var page = GetBestStashLocation(item, out var col, out var row);
                            if (page == -1)
                            {
                                Core.Logger.Verbose($"[StashItems] No place to put item, stash is probably full ({item.Name} [{col},{row}] Page={page})");
                                HandleFullStash();
                                isStashFull = true;
                                continue;
                            }

                            if (page != InventoryManager.CurrentStashPage)
                            {
                                Core.Logger.Verbose($"[StashItems] Changing to stash page: {page}");
                                InventoryManager.SwitchStashPage(page);
                                await Coroutine.Yield();
                            }

                            Core.Logger.Debug($"[StashItems] Stashing: {item.Name} ({item.ActorSnoId}) [{item.InventoryColumn},{item.InventoryRow} {item.InventorySlot}] Quality={item.ItemQualityLevel} IsAncient={item.IsAncient} InternalName={item.InternalName} StashPage={page}");
                            InventoryManager.MoveItem(item.AnnId, Core.Player.MyDynamicID, InventorySlot.SharedStash, col, row);
                            await Coroutine.Yield();

                            Core.Actors.Update();

                            await Coroutine.Wait(5000, () => !item.IsValid || item.InventoryRow == row && item.InventoryColumn == col);

                            ItemEvents.FireItemStashed(item);
                        }
                        catch (Exception ex)
                        {
                            Core.Logger.Log($"Exception Stashing Item: {ex}");
                        }
                    }
                }

                await Coroutine.Yield();

                await RepairItems.Execute();

                if (isStashFull)
                {
                    return(false);
                }

                return(true);
            }

            Core.Logger.Error($"[StashItems] Failed to stash items");
            return(false);
        }
Пример #2
0
        public static async Task <CoroutineResult> StashItems()
        {
            if (!ZetaDia.IsInTown)
            {
                return(CoroutineResult.NoAction);
            }

            var item = InventoryManager.Backpack.FirstOrDefault(ShouldStash);

            if (item == null)
            {
                return(CoroutineResult.Done);
            }

            if (!UIElements.StashWindow.IsVisible)
            {
                var stash = ZetaDia.Actors.GetActorsOfType <GizmoPlayerSharedStash>().FirstOrDefault();
                if (stash == null)
                {
                    return(CoroutineResult.Failed);
                }

                if (await CommonCoroutines.MoveAndInteract(
                        stash,
                        () => UIElements.StashWindow.IsVisible) == CoroutineResult.Running)
                {
                    return(CoroutineResult.Running);
                }
            }

            if (Core.Settings.Items.BuyStashTabs &&
                StashPagesAvailableToPurchase)
            {
                s_logger.Error($"[{nameof(StashItems)}] Attempting to buy stash pages");
                InventoryManager.BuySharedStashSlots();
            }

            // TODO: Figure out if those 2 calls are still relevant.
            await StackRamaladnisGift();
            await StackCraftingMaterials();

            try
            {
                var page = GetBestStashLocation(item, out var col, out var row);
                if (page == -1)
                {
                    s_logger.Error($"[{nameof(StashItems)}] No place to put item, stash is probably full ({item.Name} [{col},{row}] Page={page})");
                    HandleFullStash();
                    return(CoroutineResult.Failed);
                }

                if (page != InventoryManager.CurrentStashPage)
                {
                    s_logger.Debug($"[{nameof(StashItems)}] Changing to stash page: {page}");
                    InventoryManager.SwitchStashPage(page);
                    Core.StuckHandler.Reset("Still stashing...");
                    return(CoroutineResult.Running);
                }

                s_logger.Information($"[{nameof(StashItems)}] Stashing: {item.Name} ({item.ActorSnoId}) [{item.InventoryColumn},{item.InventoryRow} {item.InventorySlot}] Quality={item.ItemQualityLevel} IsAncient={item.Stats.IsAncient} InternalName={item.InternalName} StashPage={page}");

                ItemEvents.FireItemStashed(item);
                InventoryManager.MoveItem(
                    item.AnnId,
                    Core.Player.MyDynamicID,
                    InventorySlot.SharedStash,
                    col,
                    row);
            }
            catch (Exception ex)
            {
                s_logger.Error($"[{nameof(StashItems)}] Exception Stashing Item", ex);
            }

            Core.StuckHandler.Reset("Still stashing...");
            return(CoroutineResult.Running);
        }