Пример #1
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;
		}
Пример #2
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.RedGatherer50;
            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 RB_CN
                if ((Location == Locations.MorDhona) &&
                    (purchaseItemInfo.ShopType == ShopType.YellowCrafterItems || purchaseItemInfo.ShopType == ShopType.YellowGathererItems))
                {
                    Logger.Warn(Localization.Localization.ExTurnInCollectable_FailedPurchaseMorDhona, purchaseItemData.EnglishName);
                    continue;
                }

                ticks = 0;
                while (SelectIconString.IsOpen && ticks++ < 5 && Behaviors.ShouldContinue)
                {
                    if ((Location == Locations.MorDhona) && (purchaseItemInfo.ShopType == ShopType.RedGatherer50 || purchaseItemInfo.ShopType == ShopType.RedGatherer58))
                    {
                        SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType - 5);
                    }
                    else
                    {
                        SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType);
                    }

                    await shopExchangeCurrency.Refresh(5000);
                }
#else
                if ((Location == Locations.MorDhona) &&
                    (purchaseItemInfo.ShopType == ShopType.YellowCrafterItems || purchaseItemInfo.ShopType == ShopType.YellowGathererItems))
                {
                    Logger.Warn(Localization.Localization.ExTurnInCollectable_FailedPurchaseMorDhona, purchaseItemData.EnglishName);
                    continue;
                }

                ticks = 0;
                while (SelectIconString.IsOpen && ticks++ < 5 && Behaviors.ShouldContinue)
                {
                    if ((Location == Locations.MorDhona) && (purchaseItemInfo.ShopType == ShopType.RedGatherer50 || purchaseItemInfo.ShopType == ShopType.RedGatherer58))
                    {
                        SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType - 5);
                    }
                    else
                    {
                        SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopType);
                    }

                    await shopExchangeCurrency.Refresh(5000);
                }
#endif

                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)
                {
                    var qtyLeftToBuy = purchaseItem.MaxCount - (int)purchaseItemData.ItemCount();
                    var qtyBuyable   = scripsLeft / purchaseItemInfo.Cost;
                    var qtyToBuy     = Math.Min(99, Math.Min(qtyLeftToBuy, qtyBuyable));

                    if (!await shopExchangeCurrency.PurchaseItem(purchaseItemInfo.Index, (uint)qtyToBuy, 20))
                    {
                        Logger.Error(Localization.Localization.ExTurnInCollectable_PurchaseTimeout, purchaseItemData.EnglishName);
                        await shopExchangeCurrency.CloseInstance();

                        isDone = true;
                        return(true);
                    }

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

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

                    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);
        }
Пример #3
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.Yellow50;
            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 (purchaseItemInfo.Index == (int)ShopItem.OnHighOrchestrionRoll && Location != Locations.RhalgrsReach ||
                    purchaseItemInfo.Index >= (int)ShopItem.MoonbeamSilk && purchaseItemInfo.Index <= (int)ShopItem.RaziqcoatHq && Location != Locations.RhalgrsReach ||
                    purchaseItemInfo.Index == (int)ShopItem.GardenGravel && Location != Locations.RhalgrsReach ||
                    purchaseItemInfo.Index == (int)ShopItem.SongsofSaltandSufferingOrchestrionRoll && Location != Locations.RhalgrsReach)
                {
                    Logger.Warn(Localization.Localization.ExTurnInCollectable_FailedPurchaseGorRhalgrsReach, purchaseItemData.EnglishName);
                    continue;
                }

                ticks = 0;
                while (SelectIconString.IsOpen && ticks++ < 5 && Behaviors.ShouldContinue)
                {
                    SelectIconString.ClickSlot((uint)purchaseItemInfo.ShopJob);
                    await Coroutine.Wait(1000, () => SelectString.IsOpen);

                    SelectString.ClickSlot((purchaseItemInfo.ShopJob == ShopJob.Gatherer && purchaseItemInfo.ShopType > ShopType.Yellow61) ? (uint)purchaseItemInfo.ShopType - 1 : (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.ShopJob, purchaseItemInfo.ShopType)
                                                                                ) >= purchaseItemInfo.Cost &&
                       Behaviors.ShouldContinue)
                {
                    var qtyLeftToBuy = purchaseItem.MaxCount - (int)purchaseItemData.ItemCount();
                    var qtyBuyable   = scripsLeft / purchaseItemInfo.Cost;
                    var qtyToBuy     = Math.Min(99, Math.Min(qtyLeftToBuy, qtyBuyable));

                    var indexPurchaseItem = (Location != Locations.Idyllshire && Location != Locations.RhalgrsReach && purchaseItemInfo.ShopJob == ShopJob.Crafter && purchaseItemInfo.ShopType == ShopType.Yellow58 &&
                                             purchaseItemInfo.Index >= (int)ShopItem.MoonbeamSilk - 200)
                            ? purchaseItemInfo.Index - 12
                            : purchaseItemInfo.Index;

                    if (!await shopExchangeCurrency.PurchaseItem(indexPurchaseItem, (uint)qtyToBuy, 20))
                    {
                        Logger.Error(Localization.Localization.ExTurnInCollectable_PurchaseTimeout, purchaseItemData.EnglishName);
                        await shopExchangeCurrency.CloseInstance();

                        isDone = true;
                        return(true);
                    }

                    var left = scripsLeft;
                    await
                    Coroutine.Wait(
                        5000,
                        () => (scripsLeft = Memory.Scrips.GetRemainingScripsByShopType(purchaseItemInfo.ShopJob, purchaseItemInfo.ShopType)) != left);

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

                    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);
        }