private async Task<bool> PurchaseItems()
		{
			if (Me.Location.Distance(locationData.ShopNpcLocation) > 4)
			{
				// too far away, should go back to MoveToNpc
				return true;
			}

			StatusText = "Purchasing items";

			var itemsToPurchase = ShopPurchases.Where(ShouldPurchaseItem).ToArray();
			var npc = GameObjectManager.GetObjectByNPCId(locationData.ShopNpcId);
			var shopType = ShopType.BlueGatherer;
			var shopExchangeCurrency = new ShopExchangeCurrency();
			foreach (var purchaseItem in itemsToPurchase)
			{
				var purchaseItemInfo = Data.ShopItemMap[purchaseItem.ShopItem];
				var purchaseItemData = purchaseItemInfo.ItemData;

				if (shopType != purchaseItemInfo.ShopType && shopExchangeCurrency.IsValid)
				{
					await shopExchangeCurrency.CloseInstanceGently();
				}

				shopType = purchaseItemInfo.ShopType;

				// target
				var ticks = 0;
				while (Core.Target == null && !shopExchangeCurrency.IsValid && ticks++ < 10 && Behaviors.ShouldContinue)
				{
					npc.Target();
					await Coroutine.Wait(1000, () => Core.Target != null);
				}

				// check for timeout
				if (ticks > 10)
				{
					Logger.Error("Timeout targeting npc.");
					isDone = true;
					return true;
				}

				// interact
				ticks = 0;
				while (!SelectIconString.IsOpen && !shopExchangeCurrency.IsValid && ticks++ < 10 && Behaviors.ShouldContinue)
				{
					npc.Interact();
					await Coroutine.Wait(1000, () => SelectIconString.IsOpen);
				}

				// check for timeout
				if (ticks > 10)
				{
					Logger.Error("Timeout interacting with npc.");
					isDone = true;
					return true;
				}

				if (Location == Locations.MorDhona
					&& (purchaseItemInfo.ShopType == ShopType.RedCrafter || purchaseItemInfo.ShopType == ShopType.RedGatherer))
				{
					Logger.Warn("Unable to purchase item {0} in MorDhona, set location to Idyllshire.", purchaseItemData.EnglishName);
					continue;
				}

				ticks = 0;
				while (SelectIconString.IsOpen && ticks++ < 5 && Behaviors.ShouldContinue)
				{
					if (Location == Locations.MorDhona)
					{
						// Blue crafter = 0, Blue gather = 1
						SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType / 2);
					}
					else
					{
						SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType);
					}

					await shopExchangeCurrency.Refresh(5000);
				}

				if (ticks > 5 || !shopExchangeCurrency.IsValid)
				{
					Logger.Error("Timeout interacting with npc.");
					if (SelectIconString.IsOpen)
					{
						SelectIconString.ClickSlot(uint.MaxValue);
					}

					isDone = true;
					return true;
				}

				await Coroutine.Sleep(600);
				int scripsLeft;
				while (purchaseItemData.ItemCount() < purchaseItem.MaxCount
						&& (scripsLeft = Memory.Scrips.GetRemainingScripsByShopType(purchaseItemInfo.ShopType)) >= purchaseItemInfo.Cost
						&& Behaviors.ShouldContinue)
				{
					if (!await shopExchangeCurrency.PurchaseItem(purchaseItemInfo.Index, 20))
					{
						Logger.Error("Timeout during purchase of {0}", purchaseItemData.EnglishName);
						await shopExchangeCurrency.CloseInstance();
						isDone = true;
						return true;
					}

					// wait until scrips changed
					var left = scripsLeft;
					await
						Coroutine.Wait(
							5000,
							() => (scripsLeft = Memory.Scrips.GetRemainingScripsByShopType(purchaseItemInfo.ShopType)) != left);

					Logger.Info(
						"Purchased item {0} for {1} {2} scrips at {3} ET; Remaining Scrips: {4}",
						purchaseItemData.EnglishName,
						purchaseItemInfo.Cost,
						purchaseItemInfo.ShopType,
						WorldManager.EorzaTime,
						scripsLeft);

					await Coroutine.Yield();
				}

				await Coroutine.Sleep(1000);
			}

			Logger.Info("Purchases complete.");
			SelectYesno.ClickNo();
			if (SelectIconString.IsOpen)
			{
				SelectIconString.ClickSlot(uint.MaxValue);
			}

			await shopExchangeCurrency.CloseInstance();
			isDone = true;
			return true;
		}
Example #2
0
        private async Task <bool> ResolveItem()
        {
            if (item != null)
            {
                return(false);
            }

            var slots =
                InventoryManager.FilledInventoryAndArmory.Where(
                    i => !Blacklist.Contains((uint)i.Pointer.ToInt32(), BlacklistFlags.Loot)).ToArray();

            if (Collectables == null)
            {
                item = slots.FirstOrDefault(i => i.Collectability > 0);
            }
            else
            {
                foreach (var collectable in Collectables)
                {
                    var bagslots = slots.Where(i =>
                                               i.Collectability >= collectable.Value && i.Collectability <= collectable.MaxValueForTurnIn).ToArray();

                    if (collectable.Id > 0)
                    {
                        item =
                            bagslots.FirstOrDefault(i => i.RawItemId == collectable.Id);
                    }

                    item = item ??
                           bagslots.FirstOrDefault(
                        i => string.Equals(collectable.LocalName, i.Name, StringComparison.InvariantCultureIgnoreCase)) ??
                           bagslots.FirstOrDefault(
                        i => string.Equals(collectable.Name, i.EnglishName, StringComparison.InvariantCultureIgnoreCase));

                    if (item != null)
                    {
                        break;
                    }
                }
            }

            if (item != null && item.Item != null)
            {
                Logger.Verbose(Localization.Localization.ExTurnInCollectable_AttemptingTurnin, item.EnglishName, item.Pointer.ToString("X8"));
                return(false);
            }

            if ((turnedItemsIn || ForcePurchase) && !await HandleSkipPurchase())
            {
                return(false);
            }

            if (SelectYesno.IsOpen)
            {
                SelectYesno.ClickNo();
            }

            if (Request.IsOpen)
            {
                Request.Cancel();
            }

            var masterpieceSupply = new MasterPieceSupply();

            if (masterpieceSupply.IsValid)
            {
                await masterpieceSupply.CloseInstanceGently();
            }

            var shopExchangeCurrency = new ShopExchangeCurrency();

            if (shopExchangeCurrency.IsValid)
            {
                await shopExchangeCurrency.CloseInstanceGently();
            }

            if (SelectIconString.IsOpen)
            {
                SelectIconString.ClickSlot(uint.MaxValue);
            }

            return(isDone = true);
        }
		private async Task<bool> ResolveItem()
		{
			if (item != null)
			{
				return false;
			}

			var slots =
				InventoryManager.FilledInventoryAndArmory.Where(
					i => !Blacklist.Contains((uint)i.Pointer.ToInt32(), BlacklistFlags.Loot)).ToArray();

			if (Collectables == null)
			{
				item = slots.FirstOrDefault(i => i.Collectability > 0);
			}
			else
			{
				foreach (var collectable in Collectables)
				{
					item =
						slots.FirstOrDefault(
							i =>
							i.Collectability >= collectable.Value && i.Collectability <= collectable.MaxValueForTurnIn
							&& string.Equals(collectable.Name, i.EnglishName, StringComparison.InvariantCultureIgnoreCase));

					if (item != null)
					{
						break;
					}
				}
			}

			if (item != null && item.Item != null)
			{
				Logger.Verbose("Attempting to turn in item {0} -> 0x{1}", item.EnglishName, item.Pointer.ToString("X8"));
				return false;
			}

			if ((turnedItemsIn || ForcePurchase) && !await HandleSkipPurchase())
			{
				return false;
			}

			if (SelectYesno.IsOpen)
			{
				SelectYesno.ClickNo();
			}

			if (Request.IsOpen)
			{
				Request.Cancel();
			}

			var masterpieceSupply = new MasterPieceSupply();
			if (masterpieceSupply.IsValid)
			{
				await masterpieceSupply.CloseInstanceGently();
			}
			
			var shopExchangeCurrency = new ShopExchangeCurrency();
			if (shopExchangeCurrency.IsValid)
			{
				await shopExchangeCurrency.CloseInstanceGently();
			}

			if (SelectIconString.IsOpen)
			{
				SelectIconString.ClickSlot(uint.MaxValue);
			}

			return isDone = true;
		}
Example #4
0
        private async Task <bool> PurchaseItems()
        {
            if (ExProfileBehavior.Me.Location.Distance(shopExchangeCurrencyNpc.Location) > 4)
            {
                // too far away, should go back to MoveToNpc
                return(true);
            }

            StatusText = Localization.Localization.ExTurnInCollectable_Purchase;

            var itemsToPurchase      = ShopPurchases.Where(ShouldPurchaseItem).ToArray();
            var npc                  = GameObjectManager.GetObjectByNPCId(shopExchangeCurrencyNpc.NpcId);
            var shopType             = ShopType.BlueGatherer;
            var shopExchangeCurrency = new ShopExchangeCurrency();

            foreach (var purchaseItem in itemsToPurchase)
            {
                var purchaseItemInfo = Data.ShopItemMap[purchaseItem.ShopItem];
                var purchaseItemData = purchaseItemInfo.ItemData;

                if (shopType != purchaseItemInfo.ShopType && shopExchangeCurrency.IsValid)
                {
                    await shopExchangeCurrency.CloseInstanceGently();
                }

                shopType = purchaseItemInfo.ShopType;

                // target
                var ticks = 0;
                while (Core.Target == null && !shopExchangeCurrency.IsValid && ticks++ < 10 && Behaviors.ShouldContinue)
                {
                    npc.Target();
                    await Coroutine.Wait(1000, () => Core.Target != null);
                }

                // check for timeout
                if (ticks > 10)
                {
                    Logger.Error(Localization.Localization.ExTurnInCollectable_TargetingTimeout);
                    isDone = true;
                    return(true);
                }

                // interact
                ticks = 0;
                while (!SelectIconString.IsOpen && !shopExchangeCurrency.IsValid && ticks++ < 10 && Behaviors.ShouldContinue)
                {
                    npc.Interact();
                    await Coroutine.Wait(1000, () => SelectIconString.IsOpen);
                }

                // check for timeout
                if (ticks > 10)
                {
                    Logger.Error(Localization.Localization.ExTurnInCollectable_InteractingTimeout);
                    isDone = true;
                    return(true);
                }

                if (Location == Locations.MorDhona &&
                    (purchaseItemInfo.ShopType == ShopType.RedCrafter || purchaseItemInfo.ShopType == ShopType.RedGatherer))
                {
                    Logger.Warn(Localization.Localization.ExTurnInCollectable_FailedPurchaseMorDhona, purchaseItemData.EnglishName);
                    continue;
                }

                ticks = 0;
                while (SelectIconString.IsOpen && ticks++ < 5 && Behaviors.ShouldContinue)
                {
                    if (Location == Locations.MorDhona)
                    {
                        // Blue crafter = 0, Blue gather = 1
                        SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType / 2);
                    }
                    else
                    {
                        SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType);
                    }

                    await shopExchangeCurrency.Refresh(5000);
                }

                if (ticks > 5 || !shopExchangeCurrency.IsValid)
                {
                    Logger.Error(Localization.Localization.ExTurnInCollectable_InteractingTimeout);
                    if (SelectIconString.IsOpen)
                    {
                        SelectIconString.ClickSlot(uint.MaxValue);
                    }

                    isDone = true;
                    return(true);
                }

                await Coroutine.Sleep(600);

                int scripsLeft;
                while (purchaseItemData.ItemCount() < purchaseItem.MaxCount
                       &&
                       (scripsLeft = Memory.Scrips.GetRemainingScripsByShopType(purchaseItemInfo.ShopType)) >= purchaseItemInfo.Cost &&
                       Behaviors.ShouldContinue)
                {
                    if (!await shopExchangeCurrency.PurchaseItem(purchaseItemInfo.Index, 20))
                    {
                        Logger.Error(Localization.Localization.ExTurnInCollectable_PurchaseTimeout, purchaseItemData.EnglishName);
                        await shopExchangeCurrency.CloseInstance();

                        isDone = true;
                        return(true);
                    }

                    // wait until scrips changed
                    var left = scripsLeft;
                    await
                    Coroutine.Wait(
                        5000,
                        () => (scripsLeft = Memory.Scrips.GetRemainingScripsByShopType(purchaseItemInfo.ShopType)) != left);

                    Logger.Info(
                        Localization.Localization.ExTurnInCollectable_Purchased,
                        purchaseItemData.EnglishName,
                        purchaseItemInfo.Cost,
                        purchaseItemInfo.ShopType,
                        WorldManager.EorzaTime,
                        scripsLeft);

                    await Coroutine.Yield();
                }

                await Coroutine.Sleep(1000);
            }

            Logger.Info(Localization.Localization.ExTurnInCollectable_PurchaseComplete);
            SelectYesno.ClickNo();
            if (SelectIconString.IsOpen)
            {
                SelectIconString.ClickSlot(uint.MaxValue);
            }

            await shopExchangeCurrency.CloseInstance();

            isDone = true;
            return(true);
        }