Exemplo n.º 1
0
Arquivo: Bait.cs Projeto: 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;
		}
Exemplo n.º 2
0
        public async Task <bool> PurchaseItem(uint index, uint qty, byte attempts, ushort interval = 200)
        {
            var result           = SendActionResult.None;
            var purchaseAttempts = 0;

            while (result != SendActionResult.Success && !SelectYesno.IsOpen && purchaseAttempts++ < attempts &&
                   Behaviors.ShouldContinue)
            {
                // result = PurchaseItem(index);
                result = PurchaseItem(index, qty);

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

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

            // Wait an extra second in case interval is really short.
            await Coroutine.Wait(1000, () => SelectYesno.IsOpen);

            purchaseAttempts = 0;
            while (SelectYesno.IsOpen && purchaseAttempts++ < attempts && Behaviors.ShouldContinue)
            {
                SelectYesno.ClickYes();

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

            return(!SelectYesno.IsOpen);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public async Task <bool> OpenRetainer(byte retainersLeft, byte attempts = 5, int sleep = 70, ushort interval = 2000)
        {
            var result       = SendActionResult.None;
            var openAttempts = 0;
            await Behaviors.Wait(interval, () => RetainerList.IsOpen);

            while (result != SendActionResult.Success && !Talk.DialogOpen && openAttempts++ < attempts)
            {
                // Sleep here or else the game crashes. It's probably just that I'm inexperienced, but there seems to be no way to catch the exception.
                if (openAttempts < 2 || result == SendActionResult.InvalidWindow)
                {
                    await Coroutine.Sleep(sleep);
                }
                result = TryOpenRetainer(retainersLeft);
                if (result != SendActionResult.Success)
                {
                    await Refresh(interval);
                }
                // Any sort of injection error will crash the game here. But might as well have the clause.
                if (result == SendActionResult.InjectionError)
                {
                    return(false);
                }
            }

            return(openAttempts > attempts);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        protected override async Task <bool> Main()
        {
            if (!ScriptManager.GetCondition(Condition)())
            {
                Logger.Info(Localization.Localization.ExPurify_GetCondition, Condition);
                return(isDone = true);
            }

            await Behaviors.Wait(2000, () => !Window <Gathering> .IsOpen);

            await Behaviors.Wait(2000, () => !GatheringMasterpiece.IsOpen);

            Navigator.Stop();

            var ticks = 0;

            while (MovementManager.IsFlying && ticks++ < 5 && Behaviors.ShouldContinue)
            {
                MovementManager.StartDescending();
                await Coroutine.Wait(500, () => !MovementManager.IsFlying);
            }

            if (ticks > 5)
            {
                Logger.Error(Localization.Localization.ExPurify_Land);
                return(isDone = true);
            }

            await CommonTasks.StopAndDismount();

            if (await Coroutine.Wait(
                    MaxWait,
                    () =>
            {
                if (!ExProfileBehavior.Me.IsMounted)
                {
                    return(true);
                }

                ActionManager.Dismount();
                return(false);
            }))
            {
                await PurifyDialog.ReduceAllItems(InventoryManager.FilledSlots, (ushort)MaxWait);
            }
            else
            {
                Logger.Error(Localization.Localization.ExPurify_Dismount);
            }

            return(isDone = true);
        }
Exemplo n.º 7
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);
        }