Example #1
0
        private async Task <bool> Run()
        {
            TradeQueue.Clear();
            BattleCharacter target = GameObjectManager.Target as BattleCharacter;

            if (target == null)
            {
                Log("No target found to trade to.");
                return(false);
            }
            if (target.IsMe)
            {
                Log("We can't trade with ourselves.");
                return(false);
            }
            if (target.Type != GameObjectType.Pc)
            {
                Log("We can't trade with an NPC.");
                return(false);
            }
            if (!target.IsWithinInteractRange)
            {
                Log("Target is too far away to interact with.");
                return(false);
            }

            Log($"Starting to trade with {target.Name}.");

            await QueueTradeItems(AutoTradeSettings.ItemsToTrade);

            await TradeItems(TradeQueue, target);

            if (FailedTradeCount >= 5)
            {
                LogCritical("Too many failed trades, exiting.");
            }
            else if (!TradeQueue.Any())
            {
                LogSuccess("Done trading!");
            }
            else
            {
                LogCritical("We're done trading, but didn't trip FailedTradeCount and have items still in the queue?");
            }

            if (InputNumeric.IsOpen)
            {
                InputNumeric.Close();
                await Coroutine.Wait(5000, () => !InputNumeric.IsOpen);
            }

            if (Trade.IsOpen)
            {
                Trade.Close();
                await Coroutine.Wait(5000, () => !Trade.IsOpen);
            }

            TradeQueue.TrimExcess();

            TreeRoot.Stop("Finished trading.");
            return(true);
        }