protected override async Task<bool> Main()
		{
			if (interactTimeout.Elapsed.TotalSeconds > Timeout)
			{
				Logger.Error(Localization.Localization.ExTurnInGuildLeve_TurninTimeout);
				isDone = true;
				return true;
			}

			if (!checkedTransport)
			{
				checkedTransport = true;

				StatusText = Localization.Localization.ExTurnInGuildLeve_CheckTransport;

				var selectYesnoCountWindow = new SelectYesnoCount();
				if (await selectYesnoCountWindow.Refresh(2000))
				{
					StatusText = Localization.Localization.ExTurnInGuildLeve_SelectTransport;

					if (AcceptTransport)
					{
						selectYesnoCountWindow.Yes();
						await Coroutine.Wait(5000, () => CommonBehaviors.IsLoading);
						await Coroutine.Wait(System.Threading.Timeout.Infinite, () => !CommonBehaviors.IsLoading);
					}
					else
					{
						await selectYesnoCountWindow.CloseInstance();
					}

					return true;
				}
			}

			// Movement
			if (ExProfileBehavior.Me.Distance(Location) > 3.5)
			{
				StatusText = Localization.Localization.ExTurnInGuildLeve_Move + NpcId;

				await Location.MoveTo(radius: 3.4f, name: " NpcId: " + NpcId);
				return true;
			}

			if (!interactTimeout.IsRunning)
			{
				interactTimeout.Restart();
			}

			// Interact
			if (Core.Target == null && ExProfileBehavior.Me.Distance(Location) <= 3.5)
			{
				return await InteractWithNpc();
			}

			if (Talk.DialogOpen)
			{
				await HandleTalk();
			}

			if (SelectIconString.IsOpen)
			{
				if (iconStringIndex == 9001)
				{
					iconStringIndex = (uint) SelectIconString.Lines().Count - 1;
				}

				// We will just click the last quest and decrement until we have either no quests left or none to turn in.
				SelectIconString.ClickSlot(--iconStringIndex);
				await Coroutine.Sleep(500);

				if (iconStringIndex == uint.MaxValue)
				{
					Logger.Warn(Localization.Localization.ExTurnInGuildLeve_NothingToTurnin);

					isDone = true;
					return true;
				}

				return true;
			}

			if (SelectString.IsOpen)
			{
				var lines = SelectString.Lines();

				// If Collect Reward exists, we click that; otherwise we will click Close. (-1 as uint = uint.MaxValue)
				var index = (uint) lines.IndexOf(CollectRewardText, StringComparer.InvariantCultureIgnoreCase);

				if (index != uint.MaxValue)
				{
					Logger.Info(Localization.Localization.ExTurnInGuildLeve_CollectReward, WorldManager.EorzaTime);
					SelectString.ClickSlot(index);
					await Coroutine.Yield();
					return true;
				}

				// If yes is an option, click it to turn in more items.(crafting)
				index = (uint) lines.IndexOf(YesText, StringComparer.InvariantCultureIgnoreCase);

				if (index != uint.MaxValue)
				{
					Logger.Info(Localization.Localization.ExTurnInGuildLeve_TurninMore, WorldManager.EorzaTime);
					SelectString.ClickSlot(index);
					await Coroutine.Yield();
					return true;
				}

				Logger.Warn(Localization.Localization.ExTurnInGuildLeve_NoRewardsLeft);
				isDone = true;
				SelectString.ClickSlot(index);
				await Coroutine.Yield();
				return true;
			}

			if (Request.IsOpen)
			{
				var itemCount = Memory.Request.ItemsToTurnIn.Length;

				var itemId = Memory.Request.ItemId1;

				IEnumerable<BagSlot> itemSlots =
					InventoryManager.FilledInventoryAndArmory.Where(
						bs => bs.RawItemId == itemId && !Blacklist.Contains((uint) bs.Pointer.ToInt32(), BlacklistFlags.Loot)).ToArray();

				if (HqOnly)
				{
					itemSlots = itemSlots.Where(bs => bs.IsHighQuality);
				}

				if (NqOnly)
				{
					itemSlots = itemSlots.Where(bs => !bs.IsHighQuality);
				}

				var items = itemSlots.Take(itemCount).ToArray();

				if (items.Length == 0)
				{
					Logger.Warn(Localization.Localization.ExTurnInGuildLeve_NoItemToTurnin, HqOnly, NqOnly, itemId);
					isDone = true;
					return true;
				}

				StatusText = Localization.Localization.ExTurnInGuildLeve_TurnIn;

				var isHq = items.Any(i => i.IsHighQuality);
				var itemName = items[0].EnglishName;
				var requestAttempts = 0;
				while (Request.IsOpen && requestAttempts++ < 5 && Behaviors.ShouldContinue)
				{
					foreach (var item in items)
					{
						item.Handover();
						await Coroutine.Yield();
					}

					await Coroutine.Wait(1000, () => Request.HandOverButtonClickable);

					if (Request.HandOverButtonClickable)
					{
						Request.HandOver();

						if (isHq)
						{
							await Coroutine.Wait(2000, () => !Request.IsOpen && SelectYesno.IsOpen);
						}
						else
						{
							await Coroutine.Wait(2000, () => !Request.IsOpen);
						}
					}
				}

				turnedItemsIn = true;

				if (SelectYesno.IsOpen)
				{
					SelectYesno.ClickYes();
					await Coroutine.Yield();
					Logger.Info(Localization.Localization.ExTurnInGuildLeve_TurnInHq, itemName, WorldManager.EorzaTime);
				}
				else
				{
					Logger.Info(Localization.Localization.ExTurnInGuildLeve_TurnInNq, itemName, WorldManager.EorzaTime);
				}

				await HandleTalk();

				await Coroutine.Wait(2000, () => JournalResult.IsOpen);
				return true;
			}

			if (JournalResult.IsOpen)
			{
				await Coroutine.Wait(2000, () => JournalResult.ButtonClickable);
				JournalResult.Complete();
				Logger.Info(Localization.Localization.ExTurnInGuildLeve_Complete, WorldManager.EorzaTime);

				await Coroutine.Wait(2000, () => !JournalResult.IsOpen);
				await HandleTalk();

				return true;
			}

			if (!await WaitForOpenWindow())
			{
				if (MultipleQuests)
				{
					Logger.Info(Localization.Localization.ExTurnInGuildLeve_OpenWindow);
					CloseWindows();
					ExProfileBehavior.Me.ClearTarget();
				}
				else
				{
					isDone = true;
				}
			}

			return true;
		}
示例#2
0
        protected override async Task <bool> Main()
        {
            if (interactTimeout.Elapsed.TotalSeconds > Timeout)
            {
                Logger.Error(Localization.Localization.ExTurnInGuildLeve_TurninTimeout);
                isDone = true;
                return(true);
            }

            if (!checkedTransport)
            {
                checkedTransport = true;

                StatusText = Localization.Localization.ExTurnInGuildLeve_CheckTransport;

                var selectYesnoCountWindow = new SelectYesnoCount();
                if (await selectYesnoCountWindow.Refresh(2000))
                {
                    StatusText = Localization.Localization.ExTurnInGuildLeve_SelectTransport;

                    if (AcceptTransport)
                    {
                        selectYesnoCountWindow.Yes();
                        await Coroutine.Wait(5000, () => CommonBehaviors.IsLoading);

                        await Coroutine.Wait(System.Threading.Timeout.Infinite, () => !CommonBehaviors.IsLoading);
                    }
                    else
                    {
                        await selectYesnoCountWindow.CloseInstance();
                    }

                    return(true);
                }
            }

            // Movement
            if (ExProfileBehavior.Me.Distance(Location) > 3.5)
            {
                StatusText = Localization.Localization.ExTurnInGuildLeve_Move + NpcId;

                await Location.MoveTo(radius : 3.4f, name : " NpcId: " + NpcId);

                return(true);
            }

            if (!interactTimeout.IsRunning)
            {
                interactTimeout.Restart();
            }

            // Interact
            if (Core.Target == null && ExProfileBehavior.Me.Distance(Location) <= 3.5)
            {
                return(await InteractWithNpc());
            }

            if (Talk.DialogOpen)
            {
                await HandleTalk();
            }

            if (SelectIconString.IsOpen)
            {
                if (iconStringIndex == 9001)
                {
                    iconStringIndex = (uint)SelectIconString.Lines().Count - 1;
                }

                // We will just click the last quest and decrement until we have either no quests left or none to turn in.
                SelectIconString.ClickSlot(--iconStringIndex);
                await Coroutine.Sleep(500);

                if (iconStringIndex == uint.MaxValue)
                {
                    Logger.Warn(Localization.Localization.ExTurnInGuildLeve_NothingToTurnin);

                    isDone = true;
                    return(true);
                }

                return(true);
            }

            if (SelectString.IsOpen)
            {
                var lines = SelectString.Lines();

                // If Collect Reward exists, we click that; otherwise we will click Close. (-1 as uint = uint.MaxValue)
                var index = (uint)lines.IndexOf(CollectRewardText, StringComparer.InvariantCultureIgnoreCase);

                if (index != uint.MaxValue)
                {
                    Logger.Info(Localization.Localization.ExTurnInGuildLeve_CollectReward, WorldManager.EorzaTime);
                    SelectString.ClickSlot(index);
                    await Coroutine.Yield();

                    return(true);
                }

                // If yes is an option, click it to turn in more items.(crafting)
                index = (uint)lines.IndexOf(YesText, StringComparer.InvariantCultureIgnoreCase);

                if (index != uint.MaxValue)
                {
                    Logger.Info(Localization.Localization.ExTurnInGuildLeve_TurninMore, WorldManager.EorzaTime);
                    SelectString.ClickSlot(index);
                    await Coroutine.Yield();

                    return(true);
                }

                Logger.Warn(Localization.Localization.ExTurnInGuildLeve_NoRewardsLeft);
                isDone = true;
                SelectString.ClickSlot(index);
                await Coroutine.Yield();

                return(true);
            }

            if (Request.IsOpen)
            {
                var itemCount = Memory.Request.ItemsToTurnIn.Length;

                var itemId = Memory.Request.ItemId1;

                IEnumerable <BagSlot> itemSlots =
                    InventoryManager.FilledInventoryAndArmory.Where(
                        bs => bs.RawItemId == itemId && !Blacklist.Contains((uint)bs.Pointer.ToInt32(), BlacklistFlags.Loot)).ToArray();

                if (HqOnly)
                {
                    itemSlots = itemSlots.Where(bs => bs.IsHighQuality);
                }

                if (NqOnly)
                {
                    itemSlots = itemSlots.Where(bs => !bs.IsHighQuality);
                }

                var items = itemSlots.Take(itemCount).ToArray();

                if (items.Length == 0)
                {
                    Logger.Warn(Localization.Localization.ExTurnInGuildLeve_NoItemToTurnin, HqOnly, NqOnly, itemId);
                    isDone = true;
                    return(true);
                }

                StatusText = Localization.Localization.ExTurnInGuildLeve_TurnIn;

                var isHq            = items.Any(i => i.IsHighQuality);
                var itemName        = items[0].EnglishName;
                var requestAttempts = 0;
                while (Request.IsOpen && requestAttempts++ < 5 && Behaviors.ShouldContinue)
                {
                    foreach (var item in items)
                    {
                        item.Handover();
                        await Coroutine.Yield();
                    }

                    await Coroutine.Wait(1000, () => Request.HandOverButtonClickable);

                    if (Request.HandOverButtonClickable)
                    {
                        Request.HandOver();

                        if (isHq)
                        {
                            await Coroutine.Wait(2000, () => !Request.IsOpen && SelectYesno.IsOpen);
                        }
                        else
                        {
                            await Coroutine.Wait(2000, () => !Request.IsOpen);
                        }
                    }
                }

                turnedItemsIn = true;

                if (SelectYesno.IsOpen)
                {
                    SelectYesno.ClickYes();
                    await Coroutine.Yield();

                    Logger.Info(Localization.Localization.ExTurnInGuildLeve_TurnInHq, itemName, WorldManager.EorzaTime);
                }
                else
                {
                    Logger.Info(Localization.Localization.ExTurnInGuildLeve_TurnInNq, itemName, WorldManager.EorzaTime);
                }

                await HandleTalk();

                await Coroutine.Wait(2000, () => JournalResult.IsOpen);

                return(true);
            }

            if (JournalResult.IsOpen)
            {
                await Coroutine.Wait(2000, () => JournalResult.ButtonClickable);

                JournalResult.Complete();
                Logger.Info(Localization.Localization.ExTurnInGuildLeve_Complete, WorldManager.EorzaTime);

                await Coroutine.Wait(2000, () => !JournalResult.IsOpen);
                await HandleTalk();

                return(true);
            }

            if (!await WaitForOpenWindow())
            {
                if (MultipleQuests)
                {
                    Logger.Info(Localization.Localization.ExTurnInGuildLeve_OpenWindow);
                    CloseWindows();
                    ExProfileBehavior.Me.ClearTarget();
                }
                else
                {
                    isDone = true;
                }
            }

            return(true);
        }
示例#3
0
		private async Task<bool> Main()
		{
			if (interactTimeout.Elapsed.TotalSeconds > Timeout)
			{
				Logger.Error("Timeout while turning in leve.");
				isDone = true;
				return true;
			}

			if (!checkedTransport)
			{
				checkedTransport = true;

				StatusText = "Checking for transport window.";

				var selectYesnoCountWindow = new SelectYesnoCount();
				if (await selectYesnoCountWindow.Refresh(2000))
				{
					StatusText = "Selecting transport option.";

					if (AcceptTransport)
					{
						selectYesnoCountWindow.Yes();
						await Coroutine.Wait(5000, () => CommonBehaviors.IsLoading);
						await Coroutine.Wait(System.Threading.Timeout.Infinite, () => !CommonBehaviors.IsLoading);
					}
					else
					{
						await selectYesnoCountWindow.CloseInstance();
					}

					return true;
				}
			}

			// Movement
			if (Me.Distance(NpcLocation) > 3.5)
			{
				StatusText = "Moving to Npc -> " + NpcId;

				await Behaviors.MoveTo(NpcLocation, radius: 3.4f, name: " NpcId: " + NpcId);
				return true;
			}

			if (!interactTimeout.IsRunning)
			{
				interactTimeout.Restart();
			}

			// Interact
			if (Core.Target == null && Me.Distance(NpcLocation) <= 3.5)
			{
				return await InteractWithNpc();
			}

			if (Talk.DialogOpen)
			{
				Talk.Next();
				return true;
			}

			if (SelectIconString.IsOpen)
			{
				if (iconStringIndex == 9001)
				{
					iconStringIndex = (uint)SelectIconString.Lines().Count - 1;
				}

				// We will just click the last quest and decrement until we have either no quests left or none to turn in.
				SelectIconString.ClickSlot(--iconStringIndex);
				await Coroutine.Sleep(500);

				if (iconStringIndex == uint.MaxValue)
				{
					Logger.Warn("We don't have any completed quests left to turn in.");

					isDone = true;
					return true;
				}

				return true;
			}

			if (SelectString.IsOpen)
			{
				var lines = SelectString.Lines();

				// If Collect Reward exists, we click that; otherwise we will click Close. (-1 as uint = uint.MaxValue)
				var index = (uint)lines.IndexOf(CollectRewardText, StringComparer.InvariantCultureIgnoreCase);

				if (index != uint.MaxValue)
				{
					Logger.Info("Collecting reward on {0} ET", WorldManager.EorzaTime);
					SelectString.ClickSlot(index);
					return true;
				}

				// If yes is an option, click it to turn in more items.(crafting)
				index = (uint)lines.IndexOf(YesText, StringComparer.InvariantCultureIgnoreCase);

				if (index != uint.MaxValue)
				{
					Logger.Info("Turning in more items on {0} ET", WorldManager.EorzaTime);
					SelectString.ClickSlot(index);
					return true;
				}

				Logger.Warn("No rewards left, turn-ins complete.");
				isDone = true;
				SelectString.ClickSlot(index);
				return true;
			}

			if (Request.IsOpen)
			{
				////TODO: Want to support 3 turn ins of the same item (armor pieces etc.)  Probably going to have to either find out how to check if there are multiple requests, or just check the hand over prop and try to find new items to turn in...but this is...

				var itemId = Memory.Request.CurrentItemId;

				IEnumerable<BagSlot> itemSlots = InventoryManager.FilledSlots
					.Where(bs => bs.RawItemId == itemId && !Blacklist.Contains((uint)bs.Pointer.ToInt32(), BlacklistFlags.Loot))
					.ToArray();

				if (HqOnly)
				{
					itemSlots = itemSlots.Where(bs => bs.IsHighQuality);
				}

				if (NqOnly)
				{
					itemSlots = itemSlots.Where(bs => !bs.IsHighQuality);
				}

				var item = itemSlots.FirstOrDefault();

				if (item == null)
				{
					Logger.Warn("No items to turn in. Settings -> HqOnly: {0}, NqOnly: {1}, ItemId: {2}", HqOnly, NqOnly, itemId);
					isDone = true;
					return true;
				}

				StatusText = "Turning in items";

				var isHq = item.IsHighQuality;
				var itemName = item.EnglishName;
				var requestAttempts = 0;
				while (Request.IsOpen && requestAttempts++ < 5 && Behaviors.ShouldContinue && item.Item != null)
				{
					item.Handover();

					await Coroutine.Wait(500, () => Request.HandOverButtonClickable);

					if (Request.HandOverButtonClickable)
					{
						Request.HandOver();

						if (isHq)
						{
							await Coroutine.Wait(2000, () => !Request.IsOpen && SelectYesno.IsOpen);
						}
						else
						{
							await Coroutine.Wait(2000, () => !Request.IsOpen);
						}
					}
				}

				if (Request.IsOpen)
				{
					Logger.Warn("We can't turn in Name: {0}, Count: {1}, SlotId: 0x{2}", itemName, item.Count, item.Pointer.ToString("X8"));

					Blacklist.Add(
						(uint)item.Pointer.ToInt32(),
						BlacklistFlags.Loot,
						TimeSpan.FromMinutes(5),
						"Don't turn in this item for 5 minutes");

					return true;
				}

				if (SelectYesno.IsOpen)
				{
					SelectYesno.ClickYes();
					Logger.Info("Turned in HQ {0} on {1} ET", itemName, WorldManager.EorzaTime);
				}
				else
				{
					Logger.Info("Turned in {0} on {1} ET", itemName, WorldManager.EorzaTime);
				}

				await Coroutine.Sleep(250);

				return true;
			}

			if (JournalResult.IsOpen)
			{
				await Coroutine.Wait(1000, () => JournalResult.ButtonClickable);
				JournalResult.Complete();
				await Coroutine.Sleep(250);

				return true;
			}

			Logger.Info("Looks like no windows are open, lets clear our target and try again.");
			Me.ClearTarget();
			return true;
		}