コード例 #1
0
        public static MoveItemResult StashItemsAndGold(Game game, List <Item> items, int gold)
        {
            var stashes = game.GetEntityByCode(EntityCode.Stash);

            if (!stashes.Any())
            {
                Log.Error($"{game.Me.Name}: No stash found");
                return(MoveItemResult.Failed);
            }

            var stash = stashes.Single();

            bool result = GeneralHelpers.TryWithTimeout((retryCount) =>
            {
                if (game.Me.Location.Distance(stash.Location) >= 5)
                {
                    game.MoveTo(stash);
                }
                else
                {
                    return(game.OpenStash(stash));
                }

                return(false);
            }, TimeSpan.FromSeconds(4));

            if (!result)
            {
                Log.Error($"{game.Me.Name}: Failed to open stash while at location {game.Me.Location} with stash at {stash.Location}");
                return(MoveItemResult.Failed);
            }

            if (gold > 0)
            {
                game.MoveGoldToStash(gold);
            }

            var moveResult = MoveItemResult.Succes;

            Thread.Sleep(100);
            foreach (Item item in items)
            {
                if (game.Stash.FindFreeSpace(item) == null)
                {
                    moveResult = MoveItemResult.NoSpace;
                    continue;
                }

                var currentMoveResult = MoveItemToStash(game, item);
                if (currentMoveResult != MoveItemResult.Succes)
                {
                    moveResult = currentMoveResult;
                    break;
                }
                ;
            }

            game.ClickButton(ClickType.CloseStash);
            Thread.Sleep(100);
            game.ClickButton(ClickType.CloseStash);
            return(moveResult);
        }