예제 #1
0
        public static async Task <bool> FastMoveFromPremiumStashTab(InventoryControlWrapper control)
        {
            if (control == null)
            {
                GlobalLog.Error("[FastMoveFromPremiumStashTab] Inventory control is null.");
                return(false);
            }
            var item = control.CustomTabItem;

            if (item == null)
            {
                GlobalLog.Error("[FastMoveFromPremiumStashTab] Inventory control has no item.");
                return(false);
            }

            var itemName   = item.Name;
            var stackCount = item.StackCount;
            var tabName    = StashUi.TabControl.CurrentTabName;

            GlobalLog.Debug($"[FastMoveFromPremiumStashTab] Fast moving \"{itemName}\" from \"{tabName}\" tab.");

            var moved = control.FastMove();

            if (moved != FastMoveResult.None)
            {
                GlobalLog.Error($"[FastMoveFromPremiumStashTab] Fast move error: \"{moved}\".");
                return(false);
            }
            if (await Wait.For(() =>
            {
                var i = control.CustomTabItem;
                return(i == null || i.StackCount < stackCount);
            }, "fast move"))
            {
                GlobalLog.Debug($"[FastMoveFromPremiumStashTab] \"{itemName}\" has been successfully fast moved from \"{tabName}\" tab.");

                if (Settings.Instance.ArtificialDelays)
                {
                    await Wait.ArtificialDelay();
                }

                return(true);
            }
            GlobalLog.Error($"[FastMoveFromPremiumStashTab] Fast move timeout for \"{itemName}\" in \"{tabName}\" tab.");
            return(false);
        }
예제 #2
0
        /// <summary>
        /// Generic FastMove using new Inv Wrapper
        /// The inventory you refer is theinventory that will be used for moving the item from
        /// </summary>
        /// <param name="inv">This is the location where the item is picked up (can be stash or whatever you want)</param>
        /// <param name="id">This is the item localid</param>
        /// <param name="retries">Number of max fastmove attempts</param>
        /// <param name="breakFunc">If specified condition return true, FastMove will canceled and false will be returned</param>
        /// <returns>FastMoveResult enum entry</returns>
        public static async Task <bool> FastMove(InventoryControlWrapper inv, int id, int retries = 3, Func <bool> breakFunc = null)
        {
            // If the inventory is null for reasons, throw ana application-level error
            if (inv == null)
            {
                throw new ArgumentNullException(nameof(inv));
            }

            // Here the idea is to make a first fastmove attempt to get an error
            // If the error is different of None, return the error
            var err = inv.FastMove(id);

            //We assume it's currency stash tab, do not use LocalId with it
            if (err == FastMoveResult.Unsupported)
            {
                err = inv.FastMove();
            }

            if (err != FastMoveResult.None)
            {
                CommunityLib.Log.ErrorFormat("[CommunityLib][FastMove] FastMove has returned an error : {0}", err);
                return(false);
            }

            await Coroutines.LatencyWait();

            await Coroutines.ReactionWait();

            // The idea is to have a maximum of tries, but we don't want to spam them.
            // A Timer is started to "cool-off" the tries and a random lapse is calculated between each checks
            var nextfastmovetimer = Stopwatch.StartNew();
            var nextFastMove      = LokiPoe.Random.Next(2500, 4000);
            int nextFastMoveTries = 0;

            while (nextFastMoveTries < retries)
            {
                if (breakFunc != null)
                {
                    if (breakFunc())
                    {
                        return(false);
                    }
                }

                // Verifying if the item exists in the source inventory
                // If not, the item has been moved return true
                var itemExists = inv.Inventory.GetItemById(id);
                if (itemExists == null)
                {
                    await Coroutines.ReactionWait();

                    return(true);
                }

                // If it exists, and the timer has reached the random lapse we calculated above,
                // Attempt to make a new move
                if (nextfastmovetimer.ElapsedMilliseconds > nextFastMove)
                {
                    CommunityLib.Log.DebugFormat("[CommunityLib][FastMove] Attempt to fastmove ({0}/{1})", nextFastMoveTries, retries);
                    var error = inv.FastMove(id);
                    if (error == FastMoveResult.Unsupported)
                    {
                        inv.FastMove();
                    }

                    await Coroutines.LatencyWait();

                    await Coroutines.ReactionWait();

                    nextFastMove = LokiPoe.Random.Next(2500, 4000);
                    nextfastmovetimer.Restart();
                    nextFastMoveTries++;
                }

                await Coroutine.Sleep(20);
            }

            // It failed after the number of tries referenced, just return false.
            CommunityLib.Log.ErrorFormat("[CommunityLib][FastMove] Operation failed after {0} tries", retries);
            return(false);
        }