Esempio n. 1
0
        internal static async Task <bool> UseHealthPotion()
        {
            if (ShinraEx.Settings.UseHealthPotion)
            {
                if (Core.Player.CurrentHealthPercent < 15)
                {
                    Logging.Write(Colors.Yellow, "[ShinraEx] Try to use Potion");
                    BagSlot item = null;
                    foreach (var potionId in Helpers.PotionIds.Health)
                    {
                        item = InventoryManager.FilledSlots.FirstOrDefault(s => potionId == s.RawItemId);
                        if (item != null || item.CanUse())
                        {
                            Logging.Write(Colors.Yellow, $@"[ShinraEx] Trying to use >>> {item.Name}");
                            break;
                        }
                    }


                    item.UseItem();
                    await Coroutine.Wait(1000, () => !item.CanUse());

                    Logging.Write(Colors.Yellow, $@"[ShinraEx] Using >>> {item.Name}");
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        ///     Use potions to recover health
        /// </summary>
        /// <param name="force"></param>
        /// <returns></returns>
        internal static async Task <bool> UsePots(bool force = false)
        {
            if (Core.Me.CurrentHealthPercent > 90)
            {
                return(false);
            }

            uint tenpcnt = Core.Me.MaxHealth;

            foreach (var pots in Constants.Pots.Select(i => new
            {
                pot = InventoryManager.FilledSlots.FirstOrDefault(r => r.RawItemId == i.Id),
                data = i,
                sort = i.Recovery / tenpcnt
            }).Where(i => i.pot != null)
                     .Where(i => i.data.Recovery <= Core.Me.MissingHealth())
                     .OrderByDescending(i => i.sort)
                     )
            {
                BagSlot pot = pots.pot;
                if (pot.CanUse())
                {
                    Logger.Info($"Attempting to recover: {pots.data.Recovery} hp");

                    if (await UseItem(pot))
                    {
                        return(true);
                    }
                }

                await Coroutine.Yield();
            }

            return(false);
        }
Esempio n. 3
0
        internal static async Task <bool> UseSustain()
        {
            if (!Settings.Instance.UseSustain)
            {
                return(false);
            }

            if (Core.Me.CurrentHealthPercent > 50)
            {
                return(false);
            }

            if (Core.Me.HasAura(Auras.Sustain))
            {
                return(false);
            }

            BagSlot i = InventoryManager.FilledSlots.FirstOrDefault(r => r.RawItemId == Items.SustainingPotion);

            if (i == null)
            {
                return(false);
            }

            return(i.CanUse() && await UseItem(i));
        }
        /// <summary>
        /// Tries to refresh the buff resulting from using an <see cref="Item"/>.
        /// </summary>
        /// <param name="item"><see cref="Item"/> to be used.</param>
        /// <returns><see langword="true"/> if the buff was refreshed.</returns>
        private bool TryRefreshItemBuff(Item item)
        {
            // TODO: Find Aura ID from Item.ItemAction -> ItemFood; ItemAction not inflated in RB
            uint auraId = 0;
            Aura aura   = Core.Player.GetAuraById(auraId);

            if (item == null || aura == null)
            {
                return(false);
            }

            if (aura.TimespanLeft > _minItemBuffDuration)
            {
                return(false);
            }

            BagSlot slot = InventoryManager.FilledSlots.FirstOrDefault(s => s.IsFilled && s.TrueItemId == item.Id);

            if (slot == null || !slot.CanUse())
            {
                return(false);
            }

            slot.UseItem();

            return(true);
        }
Esempio n. 5
0
        private async Task <bool> UseItem()
        {
            bool shouldUse      = false;
            bool alreadyPresent = false;

            if (Core.Player.HasAura(AuraId))
            {
                var auraInfo = Core.Player.GetAuraById(AuraId);
                if (auraInfo.TimespanLeft.TotalMinutes < MinDuration)
                {
                    shouldUse      = true;
                    alreadyPresent = true;
                }
            }
            else
            {
                shouldUse = true;
            }

            if (shouldUse)
            {
                if (CraftingLog.IsOpen || CraftingManager.IsCrafting)
                {
                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => CraftingLog.IsOpen);

                    await Coroutine.Sleep(1000);

                    CraftingLog.Close();
                    await Coroutine.Yield();

                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => !CraftingLog.IsOpen);

                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => !CraftingManager.AnimationLocked);
                }

                Log("Waiting until the item is usable.");
                await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => itemslot.CanUse(null));

                Log("Using {0}", itemData.CurrentLocaleName);
                itemslot.UseItem();
                await Coroutine.Sleep(3000);

                if (!alreadyPresent)
                {
                    Log("Waiting for the aura to appear");
                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => Core.Player.HasAura(AuraId));
                }
                else
                {
                    Log("Waiting until the duration is refreshed");
                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => Core.Player.GetAuraById(AuraId).TimespanLeft.TotalMinutes > MinDuration);
                }
            }

            _IsDone = true;

            return(true);
        }
Esempio n. 6
0
        internal static async Task <bool> UseItemById(int id)
        {
            BagSlot pot = InventoryManager.FilledSlots.FirstOrDefault(r => r.RawItemId == id);

            if (pot != null && pot.CanUse() && await UseItem(pot))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        private async Task <bool> UseCordial(CordialType cordialType, int maxTimeoutSeconds = 5)
        {
            if (!(CordialSpellData.Cooldown.TotalSeconds < maxTimeoutSeconds))
            {
                return(false);
            }

            BagSlot cordial = InventoryManager.FilledSlots.FirstOrDefault(slot => slot.RawItemId == (uint)cordialType);

            if (cordial != null)
            {
                StatusText = Localization.ExFish_UseCordialWhenAvailable;

                Logger.Info(
                    Localization.ExFish_UseCordial,
                    (int)CordialSpellData.Cooldown.TotalSeconds,
                    ExProfileBehavior.Me.CurrentGP);

                if (!await Coroutine.Wait(
                        TimeSpan.FromSeconds(maxTimeoutSeconds),
                        () =>
                {
                    if (!ExProfileBehavior.Me.IsMounted || !(CordialSpellData.Cooldown.TotalSeconds < 2))
                    {
                        return(cordial.CanUse(ExProfileBehavior.Me));
                    }

                    ActionManager.Dismount();
                    return(false);
                }))
                {
                    return(false);
                }

                await Coroutine.Sleep(500);

                Logger.Info("Using " + cordialType);
                cordial.UseItem(ExProfileBehavior.Me);
                await Coroutine.Sleep(1500);

                return(true);
            }
            Logger.Warn(Localization.ExFish_NoCordial + cordialType);

            return(false);
        }
Esempio n. 8
0
        private async Task <bool> Eatfood()
        {
            uint auraId = 0;

            bool waitForAura    = false;
            bool shouldEat      = false;
            bool alreadyPresent = false;

            if (expectedAura != null)
            {
                auraId      = expectedAura.Id;
                waitForAura = true;
                if (Core.Me.HasAura(auraId))
                {
                    var auraInfo = Core.Player.GetAuraById(auraId);
                    if (auraInfo.TimespanLeft.TotalMinutes < MinDuration)
                    {
                        shouldEat      = true;
                        alreadyPresent = true;
                    }
                }
                else
                {
                    shouldEat = true;
                }
            }
            else
            {
                shouldEat = true;
            }

            BagSlot itemslot = null;

            if (shouldEat)
            {
                itemslot = findItem();
                if (itemslot == null)
                {
                    shouldEat = false; // silent exit
                    Log(System.Windows.Media.Color.FromRgb(0xCC, 0, 0), string.Format("We don't have any {0}{1} {2} in our inventory. Can't eat anymore."
                                                                                      , (HqOnly ? "[HQ] " : "")
                                                                                      , itemData.CurrentLocaleName, itemData.Id));
                }
            }

            if (shouldEat)
            {
                if (CraftingLog.IsOpen || CraftingManager.IsCrafting)
                {
                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => CraftingLog.IsOpen);

                    await Coroutine.Sleep(1000);

                    CraftingLog.Close();
                    await Coroutine.Yield();

                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => !CraftingLog.IsOpen);

                    await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => !CraftingManager.AnimationLocked);
                }

                Log("Waiting until the item is usable.");
                await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => itemslot.CanUse(null));

                Log("Eating {0}", itemData.CurrentLocaleName);
                itemslot.UseItem();
                await Coroutine.Sleep(5000);

                if (waitForAura)
                {
                    if (!alreadyPresent)
                    {
                        Log("Waiting for the aura to appear");
                        await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => Core.Player.HasAura(auraId));
                    }
                    else
                    {
                        Log("Waiting until the duration is refreshed");
                        await Coroutine.Wait(Timeout.InfiniteTimeSpan, () => Core.Player.GetAuraById(auraId).TimespanLeft.TotalMinutes > MinDuration);
                    }
                }
            }

            _IsDone = true;


            return(true);
        }
Esempio n. 9
0
        internal static bool CanUseItem(int itemid)
        {
            BagSlot pot = InventoryManager.FilledSlots.FirstOrDefault(r => r.RawItemId == itemid);

            return(pot != null && pot.CanUse());
        }
Esempio n. 10
0
        /// <summary>
        ///     can we use a potion
        /// </summary>
        /// <returns></returns>
        internal static bool CanUsePot()
        {
            BagSlot pot = InventoryManager.FilledSlots.FirstOrDefault(r => PotIDs.Contains(r.RawItemId));

            return(pot != null && pot.CanUse());
        }