Ejemplo n.º 1
0
        public static async Task <bool> RecipeBotRunner()
        {
            if (!ZetaDia.IsInTown)
            {
                return(false);
            }

            // For Smith plans, move to blacksmith
            // Use Item if not already known
            if (HasSmithPlans && Forge != null && UIElements.SalvageWindow.IsVisible)
            {
                ZetaDia.Me.Inventory.UseItem(BackPackSmithPlans.FirstOrDefault().DynamicId);
                return(true);
            }
            // Open Blacksmith window
            if (HasSmithPlans && Forge != null && !UIElements.SalvageWindow.IsVisible)
            {
                if (Forge.Distance > 10f)
                {
                    var moveResult = await CommonCoroutines.MoveAndStop(Forge.Position, 10f, "Forge Location");

                    if (moveResult == MoveResult.ReachedDestination)
                    {
                        return(false);
                    }
                }
                else
                {
                    Forge.Interact();
                    return(true);
                }
            }

            // Upgrade Blacksmith to max.. not sure if we can do that?
            // If already known: Move to Vendor
            // Sell Item

            // For Jeweler plans
            // Move to Jeweler
            // Open Window
            // Upgrade Jeweler to max
            // Use Item if not already known
            // If already Known: move to vendor
            // Sell Item

            if (await MoveToAndOpenStash())
            {
                return(true);
            }

            // Couldn't move to stash, something derpd?
            if (Stash == null)
            {
                return(false);
            }

            // Transfer Plans to backpack until pack full
            while (UIElements.StashWindow.IsVisible && TrinityItemManager.FindValidBackpackLocation(false) != TrinityItemManager.NoFreeSlot)
            {
                ZetaDia.Me.Inventory.QuickWithdraw(FirstStashPlan);
            }


            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     TownRunCheckOverlord - determine if we should do a town-run or not
        /// </summary>
        /// <param name="ret"></param>
        /// <returns></returns>
        internal static bool TownRunCanRun(object ret)
        {
            try
            {
                using (new PerformanceLogger("TownRunOverlord"))
                {
                    if (ZetaDia.Me == null || !ZetaDia.Me.IsValid)
                    {
                        return(false);
                    }

                    Trinity.WantToTownRun = false;

                    if (Trinity.Player.IsDead)
                    {
                        return(false);
                    }

                    // Check if we should be forcing a town-run
                    if (Trinity.ForceVendorRunASAP || BrainBehavior.IsVendoring)
                    {
                        if (!LastTownRunCheckResult)
                        {
                            if (BrainBehavior.IsVendoring)
                            {
                                Logger.Log("Looks like we are being asked to force a town-run by a profile/plugin/new DB feature, now doing so.");
                            }
                        }
                        SetPreTownRunPosition();
                        Trinity.WantToTownRun = true;
                    }

                    // Time safety switch for more advanced town-run checking to prevent CPU spam
                    if (DateTime.UtcNow.Subtract(LastCheckBackpackDurability).TotalSeconds > 6)
                    {
                        LastCheckBackpackDurability = DateTime.UtcNow;

                        // Check for no space in backpack
                        if (!Trinity.Player.ParticipatingInTieredLootRun)
                        {
                            Vector2 validLocation = TrinityItemManager.FindValidBackpackLocation(true);
                            if (validLocation.X < 0 || validLocation.Y < 0)
                            {
                                Logger.Log("No more space to pickup a 2-slot item, now running town-run routine. (TownRun)");
                                if (!LastTownRunCheckResult)
                                {
                                    LastTownRunCheckResult = true;
                                }
                                Trinity.WantToTownRun = true;

                                Trinity.ForceVendorRunASAP = true;
                                // Record the first position when we run out of bag space, so we can return later
                                SetPreTownRunPosition();
                            }
                        }
                        if (ZetaDia.Me.IsValid)
                        {
                            List <ACDItem> equippedItems = ZetaDia.Me.Inventory.Equipped.Where(i => i.DurabilityMax > 0 && i.DurabilityCurrent != i.DurabilityMax).ToList();
                            if (equippedItems.Any())
                            {
                                double min       = equippedItems.Average(i => i.DurabilityPercent);
                                var    dbsetting = CharacterSettings.Instance.RepairWhenDurabilityBelow;

                                float threshold   = Trinity.Player.IsInTown ? Math.Min(0.50f, dbsetting) : dbsetting;
                                bool  needsRepair = min <= threshold;

                                if (needsRepair)
                                {
                                    Logger.Log("Items may need repair, now running town-run routine.");

                                    Trinity.WantToTownRun      = true;
                                    Trinity.ForceVendorRunASAP = true;
                                    SetPreTownRunPosition();
                                }
                            }
                        }
                    }

                    if (ErrorDialog.IsVisible)
                    {
                        Trinity.WantToTownRun = false;
                    }

                    LastTownRunCheckResult = Trinity.WantToTownRun;

                    // Clear blacklists to triple check any potential targets
                    if (Trinity.WantToTownRun)
                    {
                        Trinity.Blacklist1Second   = new HashSet <int>();
                        Trinity.Blacklist3Seconds  = new HashSet <int>();
                        Trinity.Blacklist15Seconds = new HashSet <int>();
                        Trinity.Blacklist60Seconds = new HashSet <int>();
                        Trinity.Blacklist90Seconds = new HashSet <int>();
                    }

                    // Fix for A1 new game with bags full
                    if (Trinity.Player.LevelAreaId == 19947 && ZetaDia.CurrentQuest.QuestSNO == 87700)
                    {
                        Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Can't townrun with the current quest!");
                        Trinity.WantToTownRun = false;
                    }

                    if (Trinity.WantToTownRun && !(BrainBehavior.IsVendoring || Trinity.Player.IsInTown))
                    {
                        string cantUseTPreason;
                        if (!ZetaDia.Me.CanUseTownPortal(out cantUseTPreason) && !ZetaDia.IsInTown)
                        {
                            Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "It appears we need to town run but can't: {0}", cantUseTPreason);
                            Trinity.WantToTownRun = false;
                        }
                    }


                    if (Trinity.WantToTownRun && DataDictionary.BossLevelAreaIDs.Contains(Trinity.Player.LevelAreaId))
                    {
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "Unable to Town Portal - Boss Area!");
                        return(false);
                    }
                    if (Trinity.WantToTownRun && ZetaDia.IsInTown && DeathHandler.EquipmentNeedsEmergencyRepair())
                    {
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "EquipmentNeedsEmergencyRepair!");
                        return(true);
                    }
                    if (Trinity.WantToTownRun && Trinity.CurrentTarget != null)
                    {
                        TownRunCheckTimer.Restart();
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "Restarting TownRunCheckTimer, we have a target!");
                        return(false);
                    }

                    if (Trinity.WantToTownRun && DataDictionary.NeverTownPortalLevelAreaIds.Contains(Trinity.Player.LevelAreaId))
                    {
                        Logger.Log(TrinityLogLevel.Debug, LogCategory.GlobalHandler, "Unable to Town Portal in this area!");
                        return(false);
                    }
                    if (Trinity.WantToTownRun && (TownRunTimerFinished() || BrainBehavior.IsVendoring))
                    {
                        //Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Town run timer finished {0} or in town {1} or is vendoring {2} (TownRun)",
                        //    TownRunTimerFinished(), Trinity.Player.IsInTown, BrainBehavior.IsVendoring);
                        Trinity.WantToTownRun = false;
                        return(true);
                    }
                    if (Trinity.WantToTownRun && !TownRunCheckTimer.IsRunning)
                    {
                        Logger.Log(TrinityLogLevel.Verbose, LogCategory.UserInformation, "Starting town run timer");
                        TownRunCheckTimer.Start();
                        _loggedAnythingThisStash = false;
                        _loggedJunkThisStash     = false;
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Error Getting TownRun {0}", ex.Message);
                return(false);
            }
        }