예제 #1
0
        public virtual async Task <bool> CloseInstanceGently(byte maxTicks = 10, ushort interval = 200)
        {
            if (!IsValid)
            {
                return(true);
            }

            if (await CloseInstance(interval) == SendActionResult.Success)
            {
                if (!IsValid)
                {
                    return(true);
                }
            }

            await Behaviors.Sleep(interval);

            var result = SendActionResult.None;
            var ticks  = 0;

            while (result != SendActionResult.Success && ticks++ < maxTicks && IsValid && Behaviors.ShouldContinue)
            {
                if (result == SendActionResult.InvalidWindow)
                {
                    return(true);
                }

                result = await CloseInstance(interval);
            }

            return(result > SendActionResult.UnexpectedResult && !IsValid);
        }
예제 #2
0
파일: Bait.cs 프로젝트: zmsl/ExBuddy
		public async Task<bool> SelectBait(
			uint baitId,
			ushort baitDelay = 200,
			ushort maxWait = 2000,
			bool closeWindow = true)
		{
			if (!IsValid)
			{
				ActionManager.DoAction(288, GameObjectManager.LocalPlayer);
				await Refresh(maxWait);
				await Behaviors.Sleep(maxWait);
			}

			var result = SendActionResult.None;
			var attempts = 0;
			while ((result != SendActionResult.Success || FishingManager.SelectedBaitItemId != baitId) && attempts++ < 3
				   && Behaviors.ShouldContinue)
			{
				result = SetBait(baitId);
				if (result == SendActionResult.InjectionError)
				{
					await Behaviors.Sleep(500);
				}

				await Behaviors.Wait(maxWait, () => FishingManager.SelectedBaitItemId == baitId);
			}

			if (closeWindow)
			{
				await CloseInstanceGently(interval: 500);
			}

			return result > SendActionResult.InjectionError;
		}
예제 #3
0
        public async Task <bool> SelectGiG(
            int gigId,
            ushort baitDelay = 200,
            ushort maxWait   = 2000)
        {
            if (!IsValid)
            {
                ActionManager.DoAction(7634, GameObjectManager.LocalPlayer);
                await Refresh(maxWait);

                await Behaviors.Sleep(maxWait);
            }

            var result   = SendActionResult.None;
            var attempts = 0;

            while (result != SendActionResult.Success && attempts++ < 3 &&
                   Behaviors.ShouldContinue)
            {
                result = SetGig(gigId);
                if (result == SendActionResult.InjectionError)
                {
                    await Behaviors.Sleep(500);
                }

                await Behaviors.Wait(maxWait, () => !Window <HarpoonTip> .IsOpen);
            }

            return(result > SendActionResult.InjectionError);
        }
예제 #4
0
        public static async Task <bool> DesynthesizeAllItems(
            IEnumerable <BagSlot> bagSlots,
            ushort maxWait = 5000,
            bool desynthUniqueUntradeable = false)
        {
            foreach (var bagSlot in bagSlots)
            {
                if (!desynthUniqueUntradeable && bagSlot.Item != null && (bagSlot.Item.Unique || bagSlot.Item.Untradeable))
                {
                    continue;
                }

                if (bagSlot != null)
                {
                    var startingId = bagSlot.TrueItemId;

                    //Check to make sure the bagslots contents doesn't change
                    while (bagSlot.TrueItemId == startingId && bagSlot.Count > 0)
                    {
                        var result = await CommonTasks.Desynthesize(bagSlot, maxWait);

                        if (result.HasFlag(DesynthesisResult.Failure))
                        {
                            Logger.Instance.Error(Localization.Localization.SalvageDialog, result);
                            break;
                        }
                    }
                }

                await Behaviors.Sleep(500);
            }

            return(true);
        }
예제 #5
0
        public async Task <bool> TurnInAndHandOver(uint index, BagSlot bagSlot, byte attempts = 20, ushort interval = 200)
        {
            var result          = SendActionResult.None;
            var requestAttempts = 0;

            while (result != SendActionResult.Success && !Request.IsOpen && requestAttempts++ < attempts &&
                   Behaviors.ShouldContinue)
            {
                result = TurnIn(index);
                if (result == SendActionResult.InjectionError)
                {
                    await Behaviors.Sleep(interval);
                }

                await Behaviors.Wait(interval, () => Request.IsOpen);
            }

            if (requestAttempts > attempts)
            {
                return(false);
            }

            await Behaviors.Sleep(interval);

            // Try waiting half of the overall set time, up to 3 seconds
            if (!Request.IsOpen)
            {
                if (!await Coroutine.Wait(Math.Min(3000, (interval * attempts) / 2), () => Request.IsOpen))
                {
                    Logger.Instance.Warn(
                        Localization.Localization.MasterPieceSupply_CollectabilityValueNotEnough,
                        bagSlot.Collectability,
                        bagSlot.EnglishName);
                    return(false);
                }
            }

            requestAttempts = 0;
            while (Request.IsOpen && requestAttempts++ < attempts && Behaviors.ShouldContinue && bagSlot.Item != null)
            {
                bagSlot.Handover();

                await Behaviors.Wait(interval, () => Request.HandOverButtonClickable);

                Request.HandOver();

                await Behaviors.Wait(interval, () => !Request.IsOpen || SelectYesno.IsOpen);
            }

            if (SelectYesno.IsOpen)
            {
                Logger.Instance.Warn(Localization.Localization.MasterPieceSupply_FullScrips, bagSlot.EnglishName);
                return(false);
            }

            return(!Request.IsOpen);
        }
예제 #6
0
        public static async Task <bool> ReduceAllItems(IEnumerable <BagSlot> bagSlots, ushort maxWait = 5000)
        {
            // TODO: Maybe log info why we can't reduce better
            foreach (var bagSlot in bagSlots.Where(bs => bs.IsReducable))
            {
                var result = await CommonTasks.AetherialReduction(bagSlot);

                if (result.HasFlag(AetherialReductionResult.Failure))
                {
                    Logger.Instance.Error(Localization.Localization.PurifyDialog, result);
                }
                await Behaviors.Sleep(500);
            }

            return(true);
        }
예제 #7
0
        public virtual async Task <SendActionResult> CloseInstance(ushort interval = 250)
        {
            await Behaviors.Sleep(interval / 2);

            Logger.Instance.Verbose(Localization.Localization.Window_Attempting, Name);

            var result = TrySendAction(1, 3, uint.MaxValue);

            await Refresh(interval / 2, false);

            if (result == SendActionResult.Success)
            {
                if (!IsValid)
                {
                    Logger.Instance.Verbose(Localization.Localization.Window_Closed, Name);
                    await CloseSelectString();
                    await CloseYesNo();

                    return(result);
                }

                Logger.Instance.Verbose(Localization.Localization.Window_WaitToClose, interval * 2, Name);
                await Refresh(interval * 2, false);

                if (!IsValid)
                {
                    Logger.Instance.Verbose(Localization.Localization.Window_Closed, Name);
                    await CloseSelectString();
                    await CloseYesNo();

                    return(result);
                }

                Logger.Instance.Verbose(Localization.Localization.Window_UnexpectedResult, Name);
                return(SendActionResult.UnexpectedResult);
            }

            if (result == SendActionResult.InvalidWindow)
            {
                Logger.Instance.Verbose(Localization.Localization.Window_invalid, Name);
            }

            return(result);
        }
예제 #8
0
        public async Task <bool> SelectRetainerAndSkipDialog(uint index, byte attempts = 20, ushort interval = 200)
        {
            var result          = SendActionResult.None;
            var requestAttempts = 0;
            await Behaviors.Wait(interval, () => RetainerList.IsOpen);

            while (result != SendActionResult.Success && !Talk.DialogOpen && requestAttempts++ < attempts && Behaviors.ShouldContinue)
            {
                result = SelectRetainer(index);
                if (result == SendActionResult.InjectionError)
                {
                    await Behaviors.Sleep(interval);
                }
                if (result == SendActionResult.InvalidWindow)
                {
                    await Refresh(interval);
                }

                await Behaviors.Wait(interval, () => Talk.DialogOpen);
            }

            if (requestAttempts > attempts)
            {
                return(false);
            }

            await Behaviors.Sleep(interval);

            await Behaviors.Wait(5000, () => Talk.DialogOpen);

            // Dialog didin't open somehow
            if (!Talk.DialogOpen)
            {
                return(false);
            }

            Talk.Next();

            await Behaviors.Wait(interval, () => SelectString.IsOpen);

            return(SelectString.IsOpen);
        }